{"record":{"id":"432ccfb28802654a","repo":"unslothai/unsloth","slug":"no-bicodec-semantic-tokens-found-in-generated-outp","errorCode":null,"errorMessage":"No bicodec_semantic tokens found in generated output","messagePattern":"No bicodec_semantic tokens found in generated output","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"studio/backend/core/inference/audio_codecs.py","lineNumber":209,"sourceCode":"        return _numpy_to_wav_bytes(waveform, 24000), 24000\n\n    def decode_bicodec(self, generated_text: str, device: str) -> Tuple[bytes, int]:\n        \"\"\"Decode BiCodec tokens (Spark-TTS) from generated text.\n\n        Extracts bicodec_semantic_N and bicodec_global_N tokens via regex.\n        Returns (wav_bytes, sample_rate).\n        \"\"\"\n        semantic_matches = re.findall(r\"<\\|bicodec_semantic_(\\d+)\\|>\", generated_text)\n        global_matches = re.findall(r\"<\\|bicodec_global_(\\d+)\\|>\", generated_text)\n\n        logger.info(\n            f\"BiCodec decode: {len(global_matches)} global tokens, {len(semantic_matches)} semantic tokens\"\n        )\n        if len(global_matches) < 10:\n            logger.info(f\"BiCodec generated text (first 500 chars): {generated_text[:500]}\")\n\n        if not semantic_matches:\n            raise ValueError(\"No bicodec_semantic tokens found in generated output\")\n\n        semantic_ids = torch.tensor([int(t) for t in semantic_matches]).long().unsqueeze(0)\n\n        # Speaker encoder expects exactly 32 global tokens (token_num=32);\n        # pad with zeros or truncate.\n        GLOBAL_TOKEN_NUM = 32\n        if global_matches:\n            raw = [int(t) for t in global_matches]\n        else:\n            raw = []\n        if len(raw) < GLOBAL_TOKEN_NUM:\n            raw = raw + [0] * (GLOBAL_TOKEN_NUM - len(raw))\n        raw = raw[:GLOBAL_TOKEN_NUM]\n        global_ids = torch.tensor(raw).long().unsqueeze(0)  # (1, 32)\n\n        self._bicodec_tokenizer.device = device\n        self._bicodec_tokenizer.model.to(device)\n","sourceCodeStart":191,"sourceCodeEnd":227,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/core/inference/audio_codecs.py#L191-L227","documentation":"Raised during BiCodec (e.g. MeiGate/E2-style TTS) decode when the regex for <|bicodec_semantic_N|> tokens finds zero matches in the generated text. The LLM was supposed to emit semantic tokens as inline special-token text but produced none — the generation ended early, used the wrong template, or the tokenizer does not mark these ids as special so they never render in the text.","triggerScenarios":"Generation stopped before emitting any semantic tokens (EOS-first); chat template missing the TTS prompt structure so the model answers in plain prose; tokenizer's added-special-token set lacks the bicodec tokens so decode() renders them as raw text or nothing; wrong model loaded for the requested decode path.","commonSituations":"Using a GGUF/quantized variant whose special tokens are not registered; prompt/prefill not ending with the audio-generation start marker; sampling params causing immediate EOS; version drift between tokenizer config and model card.","solutions":["Inspect the logged 'BiCodec generated text (first 500 chars)' to see what the model actually produced — prose instead of tokens means a prompt/template problem","Ensure the model's tokenizer_config registers the bicodec_semantic/bicodec_global tokens as special tokens","Adjust sampling (temperature, min_p, repetition penalty) and retry — early-EOS is often stochastic","Confirm the loaded checkpoint is the audio-capable variant and the generation prompt includes the required prefix"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"import re\ndef has_bicodec_output(text: str) -> bool:\n    return bool(re.search(r\"<\\|bicodec_semantic_\\d+\\|>\", text))","typeGuard":null,"tryCatchPattern":"try:\n    wav, sr = codec.decode_bicodec(generated_text, device)\nexcept ValueError as e:\n    if \"bicodec_semantic\" in str(e):\n        log_first_500(generated_text)  # inspect what the model emitted\n        regenerate()","preventionTips":["Confirm bicodec tokens are registered as special tokens in tokenizer_config","Use the model card's exact TTS prompt structure","Watch the logged token counts (global vs semantic) to catch template drift early"],"tags":["tts","audio","bicodec","tokenizer","decode"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}