Comfy-Org/ComfyUI · error · ValueError
MiniMax Music3 prompt has {prompt_tokens} tokens; maximum is
Error message
MiniMax Music3 prompt has {prompt_tokens} tokens; maximum is {MAX_PROMPT_TOKENS} What it means
Raised by MiniMax Music3's generate() when the tokenized prompt (input_ids sequence length) exceeds MAX_PROMPT_TOKENS (5000). The autoregressive LM has a hard context limit, so an over-long prompt is rejected up front rather than failing mid-generation. The count includes caption tokens, lyrics tokens, and special markup tokens.
Source
Thrown at comfy/ldm/minimax_music/ar.py:237
def _sample_c0(self, hidden, cfg_scale, top_k, generator, vocab_mask):
if self.model.pruned_lm_head:
guided = self._guided_c0(self.model.lm_head_pruned(hidden).float(), cfg_scale, top_k)
code = sample_topk(guided, top_k, generator)
stop_token = 0
offset = 1
else:
logits = self.model.lm_head(hidden).float()
stop_token = SPECIAL_TOKEN_IDS["<|audio_end|>"]
logits = logits.masked_fill(vocab_mask, -float("inf"))
guided = self._guided_c0(logits, cfg_scale, top_k).masked_fill(vocab_mask, -float("inf"))
code = sample_topk(guided, top_k, generator)
offset = AUDIO_CODE_OFFSET
return torch.where(code == stop_token, 0, code - offset), code, stop_token
def generate(self, input_ids, seed, max_audio_frames, device, cfg_scale=CFG_SCALE, top_k=CFG_TOP_K):
prompt_tokens = int(input_ids.shape[1])
if prompt_tokens > MAX_PROMPT_TOKENS:
raise ValueError(f"MiniMax Music3 prompt has {prompt_tokens} tokens; maximum is {MAX_PROMPT_TOKENS}")
input_ids = input_ids.to(device)
if comfy.model_management.should_use_bf16(device):
execution_dtype = torch.bfloat16
else:
execution_dtype = torch.float32
unconditioned = input_ids.clone()
unconditioned[:, 1:-2] = SPECIAL_TOKEN_IDS["<|audio_cfg|>"]
text_ids = torch.cat((input_ids, unconditioned), dim=0)
if self.model.pruned_embedding:
text_embeds = self.model.embed_tokens_prefill(text_ids, out_dtype=execution_dtype)
else:
text_embeds = self.model.embed_tokens(text_ids, out_dtype=execution_dtype)
decode_limit = min(int(max_audio_frames), MAX_AUDIO_FRAMES)
past = self.model.init_kv_cache(2, prompt_tokens + decode_limit + 1, device, execution_dtype)
output = self.model(None, embeds=text_embeds, past_key_values=past, dtype=execution_dtype)
last_hidden = output[0][:, -1]
past = output[2]View on GitHub (pinned to 1c6d8d45b3)
Solutions
- Shorten the lyrics or caption so the full tokenized prompt is at most 5000 tokens
- Check prompt construction for accidental duplication of the caption/lyrics template
- If you build prompts programmatically, count tokens with the same tokenizer and truncate lyrics first (they dominate length)
Example fix
# before input_ids = tokenizer(build_prompt(caption, full_lyrics), add_special_tokens=False) out = generate(input_ids, ...) # after input_ids = tokenizer(build_prompt(caption, full_lyrics), add_special_tokens=False) assert input_ids.shape[1] <= MAX_PROMPT_TOKENS, input_ids.shape[1] out = generate(input_ids[:, -MAX_PROMPT_TOKENS:], ...)
Defensive patterns
Strategy: validation
Validate before calling
from comfy.ldm.minimax_music.ar import MAX_PROMPT_TOKENS
prompt_tokens = input_ids.shape[1]
if prompt_tokens > MAX_PROMPT_TOKENS:
input_ids = input_ids[:, -MAX_PROMPT_TOKENS:] # or truncate lyrics and re-tokenize Prevention
- Token-count check after building the prompt, before generate()
- Truncate lyrics first — they dominate prompt length
When it happens
Trigger: Calling generate(input_ids, ...) where input_ids.shape[1] > 5000 — typically a long caption plus extensive normalized lyrics.
Common situations: Very long lyrics (multiple verses in the prompt template), verbose captions, or a prompt-building bug that concatenates the prompt template multiple times.
Related errors
- MiniMax Music3 tokenizer mismatch for {token}: expected {exp
- MiniMax Music3 text encoder checkpoint is missing tokenizer_
- MiniMax Music3 tokenizer mismatch for {token}
- MiniMax Music3 generated zero audio frames
- Unknown patch method: {self.patch_method}
AI-assisted analysis of Comfy-Org/ComfyUI@1c6d8d45b3 (2026-08-14).
Data as JSON: /api/errors/cdba0f13ee43d5a0.
Report an issue: GitHub.