{"record":{"id":"cdba0f13ee43d5a0","repo":"Comfy-Org/ComfyUI","slug":"minimax-music3-prompt-has-prompt-tokens-tokens","errorCode":null,"errorMessage":"MiniMax Music3 prompt has {prompt_tokens} tokens; maximum is {MAX_PROMPT_TOKENS}","messagePattern":"MiniMax Music3 prompt has (.+?) tokens; maximum is (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy/ldm/minimax_music/ar.py","lineNumber":237,"sourceCode":"    def _sample_c0(self, hidden, cfg_scale, top_k, generator, vocab_mask):\n        if self.model.pruned_lm_head:\n            guided = self._guided_c0(self.model.lm_head_pruned(hidden).float(), cfg_scale, top_k)\n            code = sample_topk(guided, top_k, generator)\n            stop_token = 0\n            offset = 1\n        else:\n            logits = self.model.lm_head(hidden).float()\n            stop_token = SPECIAL_TOKEN_IDS[\"<|audio_end|>\"]\n            logits = logits.masked_fill(vocab_mask, -float(\"inf\"))\n            guided = self._guided_c0(logits, cfg_scale, top_k).masked_fill(vocab_mask, -float(\"inf\"))\n            code = sample_topk(guided, top_k, generator)\n            offset = AUDIO_CODE_OFFSET\n        return torch.where(code == stop_token, 0, code - offset), code, stop_token\n\n    def generate(self, input_ids, seed, max_audio_frames, device, cfg_scale=CFG_SCALE, top_k=CFG_TOP_K):\n        prompt_tokens = int(input_ids.shape[1])\n        if prompt_tokens > MAX_PROMPT_TOKENS:\n            raise ValueError(f\"MiniMax Music3 prompt has {prompt_tokens} tokens; maximum is {MAX_PROMPT_TOKENS}\")\n\n        input_ids = input_ids.to(device)\n        if comfy.model_management.should_use_bf16(device):\n            execution_dtype = torch.bfloat16\n        else:\n            execution_dtype = torch.float32\n        unconditioned = input_ids.clone()\n        unconditioned[:, 1:-2] = SPECIAL_TOKEN_IDS[\"<|audio_cfg|>\"]\n        text_ids = torch.cat((input_ids, unconditioned), dim=0)\n        if self.model.pruned_embedding:\n            text_embeds = self.model.embed_tokens_prefill(text_ids, out_dtype=execution_dtype)\n        else:\n            text_embeds = self.model.embed_tokens(text_ids, out_dtype=execution_dtype)\n        decode_limit = min(int(max_audio_frames), MAX_AUDIO_FRAMES)\n        past = self.model.init_kv_cache(2, prompt_tokens + decode_limit + 1, device, execution_dtype)\n        output = self.model(None, embeds=text_embeds, past_key_values=past, dtype=execution_dtype)\n        last_hidden = output[0][:, -1]\n        past = output[2]","sourceCodeStart":219,"sourceCodeEnd":255,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy/ldm/minimax_music/ar.py#L219-L255","documentation":"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.","triggerScenarios":"Calling generate(input_ids, ...) where input_ids.shape[1] > 5000 — typically a long caption plus extensive normalized lyrics.","commonSituations":"Very long lyrics (multiple verses in the prompt template), verbose captions, or a prompt-building bug that concatenates the prompt template multiple times.","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)"],"exampleFix":"# before\ninput_ids = tokenizer(build_prompt(caption, full_lyrics), add_special_tokens=False)\nout = generate(input_ids, ...)\n# after\ninput_ids = tokenizer(build_prompt(caption, full_lyrics), add_special_tokens=False)\nassert input_ids.shape[1] <= MAX_PROMPT_TOKENS, input_ids.shape[1]\nout = generate(input_ids[:, -MAX_PROMPT_TOKENS:], ...)","handlingStrategy":"validation","validationCode":"from comfy.ldm.minimax_music.ar import MAX_PROMPT_TOKENS\nprompt_tokens = input_ids.shape[1]\nif prompt_tokens > MAX_PROMPT_TOKENS:\n    input_ids = input_ids[:, -MAX_PROMPT_TOKENS:]  # or truncate lyrics and re-tokenize","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Token-count check after building the prompt, before generate()","Truncate lyrics first — they dominate prompt length"],"tags":["minimax","music","tokenizer","prompt-length","llm"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}