Skip to content

The most powerful and modular diffusion model GUI, api and backend with a graph/nodes interface. The fastest local inference engine in the world.

Increase max song duration in Yue2 node. (#16292)

comfyanonymous7dac1d2512c2
diff --git a/comfy/text_encoders/yue2.py b/comfy/text_encoders/yue2.py
index 53531f859..2c01e3ee8 100644
--- a/comfy/text_encoders/yue2.py
+++ b/comfy/text_encoders/yue2.py
@@ -194,7 +194,7 @@ class YuE2TEModel(torch.nn.Module):
finally:
# Each phase has different KV buffers and may change the CFG batch size.
comfy.model_prefetch.cleanup_prefetch_queues()
- logging.warning("YuE2 %s reached its token budget; increase the limit for a complete result.", phase)
+ logging.warning("YuE2 %s reached its token budget before the end token.", phase)
return history, True
def _acoustic_conditioning(self, prefix, tokens, dtype):
@@ -242,12 +242,19 @@ class YuE2TEModel(torch.nn.Module):
abc_ids = []
prefix = prefix + abc_ids + [ABC_END, MUSIC_START]
negative = tokens["negative"] + ([MUSIC_START] if cot == "off" else [ABC_START] + abc_ids + [ABC_END, MUSIC_START])
+ context = self.config.max_position_embeddings
+ max_tokens = min(tokens["max_tokens"], context - max(len(prefix), len(negative)))
+ # One acoustic frame needs two positions plus three boundary tokens.
+ if max_tokens < 1 or len(prefix) + 5 > context:
+ raise ValueError("YuE2 prompt leaves no room for music; shorten the style, lyrics, or ABC.")
+ if max_tokens < tokens["max_tokens"]:
+ logging.info("YuE2 music budget reduced to %d tokens (%.2f seconds) to fit the prompt.", max_tokens, max_tokens / FRAMES_PER_SECOND)
semantic, semantic_truncated = self._generate(
- prefix, tokens["seed"], tokens["max_tokens"], "semantic", dtype,
+ prefix, tokens["seed"], max_tokens, "semantic", dtype,
negative=negative, cfg_scale=tokens["cfg_scale"], legacy_off=cot == "off",
temperature=tokens["temperature"], top_p=tokens["top_p"], top_k=tokens["top_k"],
repetition_penalty=tokens["repetition_penalty"], penalty_window=50,
- min_tokens=min(200, tokens["max_tokens"]),
+ min_tokens=min(200, max_tokens),
)
conditioning, chunks = self._acoustic_conditioning(prefix, semantic, dtype)
return conditioning, None, {
diff --git a/comfy_extras/nodes_yue2.py b/comfy_extras/nodes_yue2.py
index 2d9aa6616..b32ae7957 100644
--- a/comfy_extras/nodes_yue2.py
+++ b/comfy_extras/nodes_yue2.py
@@ -47,7 +47,7 @@ class YuE2GenerateMusic(io.ComfyNode):
io.String.Input("abc", default="", multiline=True, tooltip="Connect the ABC generator or supply an edited score. Leave empty to use off mode automatically."),
io.Int.Input("seed", default=0, min=0, max=0xffffffffffffffff, control_after_generate=True),
io.Combo.Input("mode", options=["full", "melody"], tooltip="full: generates melody and chords; melody: generates melody only, recommended for covers."),
- io.Float.Input("max_duration", default=360.0, min=0.04, max=360.0, step=0.04, tooltip="Maximum duration; generation can stop earlier. The release uses a 360-second budget."),
+ io.Float.Input("max_duration", default=360.0, min=0.04, max=900.0, step=0.04, tooltip="Maximum duration in seconds. Automatically reduced for long prompts; generation can stop earlier."),
io.Float.Input("temperature", default=1.0, min=0.0, max=5.0, step=0.05, advanced=True),
io.Float.Input("top_p", default=0.95, min=0.01, max=1.0, step=0.01, advanced=True),
io.Int.Input("top_k", default=100, min=1, max=32768, advanced=True),