{"record":{"id":"1fa5da28886c7974","repo":"sgl-project/sglang","slug":"language-model-does-not-support-set-embed-and-head","errorCode":null,"errorMessage":"language_model does not support set_embed_and_head().","messagePattern":"language_model does not support set_embed_and_head\\(\\)\\.","errorType":"exception","errorClass":"AttributeError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/models/kimi_k25.py","lineNumber":979,"sourceCode":"        return self.language_model.lm_head\n\n    def get_embed_and_head(self) -> Tuple[torch.Tensor, torch.Tensor]:\n        \"\"\"Get embedding and LM head weights for speculative decoding.\"\"\"\n        if self.language_model is None or not hasattr(\n            self.language_model, \"get_embed_and_head\"\n        ):\n            raise AttributeError(\n                \"language_model does not support get_embed_and_head().\"\n            )\n\n        return self.language_model.get_embed_and_head()\n\n    def set_embed_and_head(self, embed: torch.Tensor, head: torch.Tensor) -> None:\n        \"\"\"Set embedding and LM head weights for speculative decoding.\"\"\"\n        if self.language_model is None or not hasattr(\n            self.language_model, \"set_embed_and_head\"\n        ):\n            raise AttributeError(\n                \"language_model does not support set_embed_and_head().\"\n            )\n\n        self.language_model.set_embed_and_head(embed, head)\n\n\nEntryClass = [KimiK25ForConditionalGeneration]\n","sourceCodeStart":961,"sourceCodeEnd":987,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/models/kimi_k25.py#L961-L987","documentation":"KimiK25ForCausalLM.set_embed_and_head() restores embedding and LM-head weights on the wrapped language_model, the counterpart to get_embed_and_head used by speculative decoding (e.g. temporarily tying/untying weights). It raises AttributeError when the delegate method is absent or language_model is None, so the weight-swap protocol cannot proceed.","triggerScenarios":"The speculative worker calls set_embed_and_head(embed, head) after get_embed_and_head on a wrapper whose language_model is None or whose class lacks set_embed_and_head — same conditions as error 5420 but on the write path.","commonSituations":"Same as get_embed_and_head: enabling EAGLE/MTP speculative decoding against a Kimi K2.5 variant without the spec-decode hooks; inconsistent model implementations that define one of get/set but not both.","solutions":["Ensure both get_embed_and_head and set_embed_and_head exist on the inner language_model class (implement them in pairs).","Confirm language_model initialization succeeded before starting spec decoding.","Disable speculative decoding if the inner model only partially implements the weight-access protocol."],"exampleFix":"// before\nmodel.set_embed_and_head(embed, head)  # AttributeError\n\n// after\nlm = model.language_model\nif lm is not None and hasattr(lm, \"set_embed_and_head\"):\n    lm.set_embed_and_head(embed, head)","handlingStrategy":"type-guard","validationCode":"lm = model.language_model\nassert lm is not None and hasattr(lm, \"set_embed_and_head\"), \"spec weight set unsupported\"","typeGuard":"def supports_embed_head_rw(model) -> bool:\n    lm = getattr(model, \"language_model\", None)\n    return lm is not None and all(hasattr(lm, m) for m in (\"get_embed_and_head\", \"set_embed_and_head\"))","tryCatchPattern":null,"preventionTips":["Implement get/set embed-head hooks in pairs on language model classes.","Validate the wrapper protocol once at startup instead of mid-serving."],"tags":["speculative-decoding","kimi","attribute-error","model-loading"],"backgroundTag":"unsupported-model-architecture","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}