Keep YuE2 jobs live on the bench and wire target length to semantic tokens.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+12
-5
@@ -97,8 +97,10 @@ def main():
|
||||
root = Path(cli.root).resolve()
|
||||
output = Path(cli.request).resolve().parent
|
||||
duration = int(request.get('duration', 60))
|
||||
if not 30 <= duration <= 150:
|
||||
raise ValueError('Duration must be 30–150 seconds.')
|
||||
if not 15 <= duration <= 150:
|
||||
raise ValueError('Target length must be 15–150 seconds.')
|
||||
# VAE downsampling_ratio 1920 @ 48 kHz → 25 semantic / latent frames per second.
|
||||
max_tokens = max(200, min(9000, duration * 25))
|
||||
lyrics = normalize_lyrics(request['lyrics'])
|
||||
style = ' '.join(str(request['tags']).split())
|
||||
seed = int(request['seed'])
|
||||
@@ -111,9 +113,11 @@ def main():
|
||||
import soundfile as sf
|
||||
attention_backend, pipeline_backend = resolve_attention_backend(torch)
|
||||
emit(stage='loading', progress=1, message='Loading YuE2', model=model, vae=vae,
|
||||
duration=duration, attention_backend=attention_backend, pipeline_backend=pipeline_backend,
|
||||
duration=duration, maxTokens=max_tokens, attention_backend=attention_backend,
|
||||
pipeline_backend=pipeline_backend,
|
||||
cudaAllocConf=os.environ.get('PYTORCH_CUDA_ALLOC_CONF'))
|
||||
from yue2 import YuE2Pipeline
|
||||
from yue2.protocol import Sampling
|
||||
if not torch.cuda.is_available():
|
||||
raise RuntimeError('YuE2 requires a CUDA GPU; CPU fallback is disabled.')
|
||||
patch_graph_attention(attention_backend)
|
||||
@@ -129,6 +133,8 @@ def main():
|
||||
)
|
||||
cot = 'full'
|
||||
pipe_kwargs = dict(style=style, lyrics=lyrics, cot=cot, seed=seed)
|
||||
# Cap semantic length from target seconds. Do not FFmpeg-trim after decode.
|
||||
semantic_sampling = Sampling(max_tokens=max_tokens, min_tokens=min(200, max_tokens))
|
||||
# YuE2Pipeline.__init__ always calls set_per_process_memory_fraction; skip it on this 16GB host.
|
||||
_set_fraction = torch.cuda.set_per_process_memory_fraction
|
||||
torch.cuda.set_per_process_memory_fraction = lambda *args, **kwargs: None
|
||||
@@ -153,8 +159,9 @@ def main():
|
||||
plan = pipe.plan(**pipe_kwargs)
|
||||
free_cuda(torch)
|
||||
memory_snapshot(torch, 'memory-after-plan')
|
||||
emit(stage='semantic', message='Generating semantic tokens', progress=25, cot=cot)
|
||||
semantic = pipe.generate_semantic(plan)
|
||||
emit(stage='semantic', message='Generating semantic tokens', progress=25, cot=cot,
|
||||
maxTokens=max_tokens, targetSeconds=duration)
|
||||
semantic = pipe.generate_semantic(plan, sampling=semantic_sampling)
|
||||
free_cuda(torch)
|
||||
memory_snapshot(torch, 'memory-after-semantic')
|
||||
emit(stage='synthesize', message='Synthesizing acoustic latents', progress=55, cot=cot)
|
||||
|
||||
Reference in New Issue
Block a user