{"record":{"id":"7df99e3e3525cf78","repo":"sgl-project/sglang","slug":"f-the-class-type-quant-method-name-must-imp","errorCode":null,"errorMessage":"f\"The class {type(quant_method).__name__} must implement the 'embedding' method, see UnquantizedEmbeddingMethod.\"","messagePattern":"f\"The class (.+?) must implement the 'embedding' method, see UnquantizedEmbeddingMethod\\.\"","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/layers/vocab_parallel_embedding.py","lineNumber":273,"sourceCode":"            self.tp_size,\n        )\n        self.embedding_dim = embedding_dim\n\n        quant_method = None\n        if quant_config is not None:\n            quant_method = quant_config.get_quant_method(self, prefix=prefix)\n        if quant_method is None:\n            quant_method = UnquantizedEmbeddingMethod()\n\n        # If we are making an embedding layer, then our quantization linear\n        # method must implement the embedding operation. If we are another\n        # layer type like ParallelLMHead, this is not important.\n        is_embedding_layer = type(self.__class__) is VocabParallelEmbedding\n        quant_method_implements_embedding = method_has_implemented_embedding(\n            type(quant_method)\n        )\n        if is_embedding_layer and not quant_method_implements_embedding:\n            raise NotImplementedError(\n                f\"The class {type(quant_method).__name__} must implement \"\n                \"the 'embedding' method, see UnquantizedEmbeddingMethod.\"\n            )\n\n        self.quant_method: QuantizeMethodBase = quant_method\n\n        if params_dtype is None:\n            params_dtype = torch.get_default_dtype()\n        # Divide the weight matrix along the vocaburaly dimension.\n        self.num_added_embeddings = self.num_embeddings - self.org_vocab_size\n        self.num_embeddings_per_partition = divide(\n            self.num_embeddings_padded, self.tp_size\n        )\n        assert (\n            self.shard_indices.num_elements_padded == self.num_embeddings_per_partition\n        )\n        self.num_org_embeddings_per_partition = (\n            self.shard_indices.org_vocab_end_index","sourceCodeStart":255,"sourceCodeEnd":291,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/layers/vocab_parallel_embedding.py#L255-L291","documentation":"When constructing a VocabParallelEmbedding, sglang verifies the provided quant_method class implements the 'embedding' forward method (as UnquantizedEmbeddingMethod does). If the quantization method class lacks an embedding() implementation, this NotImplementedError is raised, since embedding layers cannot use the generic linear-only quant method.","triggerScenarios":"Passing a QuantizeMethodBase subclass that only implements apply() (a linear-only quantizer) as quant_method to VocabParallelEmbedding; wiring a new/custom quant method into an embedding layer without adding an embedding() method.","commonSituations":"Adding a new quantization format to sglang and reusing an existing linear quant method for embeddings; subclassing a quant method and overriding only apply(); version mismatches where an older quant class lacks embedding support.","solutions":["Implement an embedding() method on the quant method class, mirroring UnquantizedEmbeddingMethod","If the quant method is for linear layers only, use UnquantizedEmbeddingMethod for the embedding layer instead","When subclassing, ensure method_has_implemented_embedding can see the override — define embedding() directly, not via __getattr__"],"exampleFix":"# before\nclass MyQuantMethod(QuantizeMethodBase):\n    def apply(self, layer, x, bias): ...\n# after\nclass MyQuantMethod(QuantizeMethodBase):\n    def apply(self, layer, x, bias): ...\n    def embedding(self, layer, x): return F.embedding(x, layer.weight)","handlingStrategy":"type-guard","validationCode":"from sglang.multimodal_gen.runtime.layers.vocab_parallel_embedding import method_has_implemented_embedding\n\nassert method_has_implemented_embedding(type(quant_method)), \"quant method lacks embedding()\"","typeGuard":"def supports_embedding(qm) -> bool:\n    return callable(getattr(qm, \"embedding\", None))","tryCatchPattern":null,"preventionTips":["When adding a quant method, implement both apply() and embedding() up front","Run the existing method_has_implemented_embedding check in unit tests for new quantizers"],"tags":["quantization","embedding","not-implemented","constructor"],"backgroundTag":"missing-interface-implementation","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}