{"record":{"id":"b07f9e202e6d5fc1","repo":"sgl-project/sglang","slug":"transformer-transformer-class-name-has-n","errorCode":null,"errorMessage":"Transformer {transformer.__class__.__name__} has no attribute {spec.blocks_attr!r} for cache-dit blocks.","messagePattern":"Transformer (.+?) has no attribute (.+?) for cache-dit blocks\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/cache/cache_dit_integration.py","lineNumber":381,"sourceCode":"    \"MiniMaxH3DiTModel\": CustomBlockAdapterSpec(\n        blocks_attr=\"blocks\",\n        forward_pattern=ForwardPattern.Pattern_3,\n    ),\n}\n\n\ndef _build_custom_block_adapter(\n    transformer: torch.nn.Module,\n    has_separate_cfg: bool = False,\n) -> Optional[BlockAdapter]:\n    \"\"\"Build a manual BlockAdapter for a model absent from cache-dit's registry,\n    or None if the class is unknown.\"\"\"\n    spec = _CUSTOM_BLOCK_ADAPTER_SPECS.get(transformer.__class__.__name__)\n    if spec is None:\n        return None\n    blocks = getattr(transformer, spec.blocks_attr, None)\n    if blocks is None:\n        raise ValueError(\n            f\"Transformer {transformer.__class__.__name__} has no attribute \"\n            f\"{spec.blocks_attr!r} for cache-dit blocks.\"\n        )\n    return BlockAdapter(\n        transformer=transformer,\n        blocks=blocks,\n        forward_pattern=spec.forward_pattern,\n        has_separate_cfg=has_separate_cfg,\n    )\n\n\ndef enable_cache_on_transformer(\n    transformer: torch.nn.Module,\n    config: CacheDitConfig,\n    model_name: str = \"transformer\",\n    sp_group: Optional[torch.distributed.ProcessGroup] = None,\n    tp_group: Optional[torch.distributed.ProcessGroup] = None,\n    has_separate_cfg: bool = False,","sourceCodeStart":363,"sourceCodeEnd":399,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/cache/cache_dit_integration.py#L363-L399","documentation":"For transformers not pre-registered with cache-dit, _build_custom_block_adapter looks up a per-class spec in _CUSTOM_BLOCK_ADAPTER_SPECS by class name and reads the blocks via getattr(transformer, spec.blocks_attr, None). If that attribute is None, the class shape doesn't match the spec and adapter construction aborts with this ValueError (raised through enable_cache_on_transformer).","triggerScenarios":"Enabling cache-dit on a transformer whose class name has a spec in _CUSTOM_BLOCK_ADAPTER_SPECS but whose instance lacks the expected blocks_attr — e.g. the blocks attribute was renamed in a newer model revision, or a wrapper module hides it.","commonSituations":"Model code updates renaming transformer.blocks; loading a custom/sharded checkpoint that reuses a known class name with different internals; passing a partially-initialized transformer before attributes are assigned.","solutions":["Inspect vars(transformer) to find the actual blocks attribute name and use a transformer whose layout matches the spec.","Update the _CUSTOM_BLOCK_ADAPTER_SPECS entry for that class to the correct blocks_attr.","Pre-register the transformer with cache-dit so the standard path is used and the custom adapter is not needed."],"exampleFix":"// before\n# spec expects transformer.blocks but model defines transformer.transformer_blocks\nenable_cache_on_transformer(model, config)\n// after\n# update spec's blocks_attr (or model revision) so getattr finds blocks\nenable_cache_on_transformer(model, config)","handlingStrategy":"validation","validationCode":"spec = _CUSTOM_BLOCK_ADAPTER_SPECS.get(type(transformer).__name__)\nif spec is not None and getattr(transformer, spec.blocks_attr, None) is None:\n    raise RuntimeError(f\"{type(transformer).__name__} missing {spec.blocks_attr}; update spec\")\nenable_cache_on_transformer(transformer, config)","typeGuard":"def transformer_supports_adapter(transformer) -> bool:\n    spec = _CUSTOM_BLOCK_ADAPTER_SPECS.get(type(transformer).__name__)\n    return spec is None or getattr(transformer, spec.blocks_attr, None) is not None","tryCatchPattern":"try:\n    enable_cache_on_transformer(transformer, config)\nexcept ValueError as e:\n    if \"for cache-dit blocks\" in str(e):\n        config = replace(config, enabled=False)  # serve without cache-dit\n    raise","preventionTips":["Pin model code versions compatible with adapter specs.","Smoke-check the blocks attribute before enabling cache-dit on custom models.","Update _CUSTOM_BLOCK_ADAPTER_SPECS when model internals change."],"tags":["cache-dit","block-adapter","model-internals","integration"],"backgroundTag":"missing-model-attribute","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}