{"record":{"id":"d9d35837eaf8775c","repo":"sgl-project/sglang","slug":"quanto-layers-collide-after-parameter-mapping-at","errorCode":null,"errorMessage":"Quanto layers collide after parameter mapping at {mapped_prefix!r}","messagePattern":"Quanto layers collide after parameter mapping at (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/layers/quantization/configs/quanto_int8_config.py","lineNumber":186,"sourceCode":"                raise ValueError(\n                    f\"Quanto layer {prefix!r} has incompatible scale \"\n                    f\"{scale_slice.get_dtype()} {scale_shape}\"\n                )\n            for scale_name in (names[\"input\"], names[\"output\"]):\n                scale = checkpoint.get_slice(scale_name)\n                if (\n                    scale.get_dtype() not in _FLOAT_DTYPES\n                    or tuple(scale.get_shape()) != ()\n                ):\n                    raise ValueError(\n                        f\"Quanto auxiliary scale {scale_name!r} must be a float scalar\"\n                    )\n\n            mapped_prefix = (\n                param_name_mapper(prefix) if param_name_mapper is not None else prefix\n            )\n            if mapped_prefix in mapped_prefixes:\n                raise ValueError(\n                    f\"Quanto layers collide after parameter mapping at {mapped_prefix!r}\"\n                )\n            mapped_prefixes.add(mapped_prefix)\n\n    return QuantoInt8Config(mapped_prefixes)\n\n\n__all__ = [\"QuantoInt8Config\", \"inspect_quanto_int8_checkpoint\"]\n","sourceCodeStart":168,"sourceCodeEnd":195,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/layers/quantization/configs/quanto_int8_config.py#L168-L195","documentation":"After applying the caller-supplied param_name_mapper to each quantization_map prefix, two different source prefixes map to the same target name. Since the returned QuantoInt8Config is keyed by mapped prefixes, collisions would silently merge distinct layers, so they are rejected.","triggerScenarios":"Calling inspect_quanto_int8_checkpoint(ckpt, param_name_mapper=fn) where fn is not injective on the checkpoint's quantized prefixes — e.g. a mapper that strips a distinguishing index or folds layer names together.","commonSituations":"Adapters renaming encoder layer names for a different model class (e.g. dropping block indices, mapping 'layers.0' and 'layers.10' both to 'layers.0' via faulty regex), or a shared mapper reused across architectures.","solutions":["Fix param_name_mapper to be injective: distinct Quanto prefixes must map to distinct names (usually keep the layer index)","Log {prefix -> mapped_prefix} pairs before loading and eyeball for duplicates","If two prefixes legitimately target one layer, the checkpoint layout is wrong — re-export instead of remapping"],"exampleFix":"# before\nmapper = lambda p: re.sub(r\"layers\\.\\d+\\.\", \"layers.\", p)  # collapses indices\n# after\nmapper = lambda p: p.replace(\"encoder.\", \"model.encoder.\")  # injective rename","handlingStrategy":"type-guard","validationCode":"mapped = [param_name_mapper(p) if param_name_mapper else p for p in quantization_map]\nif len(mapped) != len(set(mapped)):\n    raise SystemExit('param_name_mapper is not injective on quantized prefixes')","typeGuard":"def mapper_is_injective(mapper, prefixes) -> bool:\n    outs = [mapper(p) for p in prefixes]\n    return len(outs) == len(set(outs))","tryCatchPattern":"try:\n    cfg = inspect_quanto_int8_checkpoint(ckpt, mapper)\nexcept ValueError as e:\n    if 'collide after parameter mapping' in str(e):\n        raise SystemExit('Fix mapper to preserve layer indices (injective mapping)')\n    raise","preventionTips":["Name mappers should only add/rename fixed segments, never drop indices","Unit-test the mapper for injectivity against the actual checkpoint prefixes"],"tags":["quantization","quanto","name-mapping","collision"],"backgroundTag":"name-mapping-collision","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}