{"record":{"id":"c5c8e84846a9797d","repo":"sgl-project/sglang","slug":"subclasses-of-basedit-must-define-attr-instanc","errorCode":null,"errorMessage":"Subclasses of BaseDiT must define '{attr}' instance variable","messagePattern":"Subclasses of BaseDiT must define '(.+?)' instance variable","errorType":"validation","errorClass":"AttributeError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/models/dits/base.py","lineNumber":97,"sourceCode":"            )\n\n    @abstractmethod\n    def forward(\n        self,\n        hidden_states: torch.Tensor,\n        encoder_hidden_states: torch.Tensor | list[torch.Tensor],\n        timestep: torch.LongTensor,\n        encoder_hidden_states_image: torch.Tensor | list[torch.Tensor] | None = None,\n        guidance=None,\n        **kwargs,\n    ) -> torch.Tensor:\n        pass\n\n    def __post_init__(self) -> None:\n        required_attrs = [\"hidden_size\", \"num_attention_heads\", \"num_channels_latents\"]\n        for attr in required_attrs:\n            if not hasattr(self, attr):\n                raise AttributeError(\n                    f\"Subclasses of BaseDiT must define '{attr}' instance variable\"\n                )\n\n    def post_load_weights(self) -> None:\n        \"\"\"Run model-specific post-load weight fixups after all parameters are materialized.\"\"\"\n        return None\n\n    def prepare_lora_adapter(\n        self, adapter: dict[str, torch.Tensor]\n    ) -> dict[str, torch.Tensor]:\n        \"\"\"Apply model-specific LoRA transforms after names are normalized.\"\"\"\n        return adapter\n\n    @property\n    def supported_attention_backends(self) -> set[AttentionBackendEnum]:\n        return self._supported_attention_backends\n\n    @property","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/models/dits/base.py#L79-L115","documentation":"BaseDiT.__post_init__ verifies that the model instance exposes hidden_size, num_attention_heads, and num_channels_latents. These are expected to be set during __init__/setup of the subclass (often from config.arch_config); if absent, the model is incompletely configured and the AttributeError is raised.","triggerScenarios":"A BaseDiT subclass completes construction without assigning self.hidden_size, self.num_attention_heads, or self.num_channels_latents — e.g. a custom model whose __init__ skips copying these fields from its config.","commonSituations":"Porting a new architecture where the config field names differ (e.g. dim vs hidden_size), so the subclass never assigns the expected attribute names; refactors that move attribute assignment out of __init__.","solutions":["In the subclass __init__, assign the three attributes from the model config, e.g. self.hidden_size = config.arch_config.hidden_size","If config field names differ, map them explicitly (self.hidden_size = cfg.dim)","Run the model's unit test after adding to catch the failure early"],"exampleFix":"# before\nclass MyDiT(BaseDiT):\n    def __init__(self, config, hf_config, **kw):\n        super().__init__(config, hf_config, **kw)\n        self.dim = 1024\n# after\nclass MyDiT(BaseDiT):\n    def __init__(self, config, hf_config, **kw):\n        super().__init__(config, hf_config, **kw)\n        self.hidden_size = 1024\n        self.num_attention_heads = 16\n        self.num_channels_latents = 16","handlingStrategy":"validation","validationCode":"REQUIRED_INSTANCE = [\"hidden_size\", \"num_attention_heads\", \"num_channels_latents\"]\nassert all(hasattr(model, a) for a in REQUIRED_INSTANCE)","typeGuard":"def is_configured_dit(model) -> bool:\n    return all(hasattr(model, a) for a in (\"hidden_size\", \"num_attention_heads\", \"num_channels_latents\"))","tryCatchPattern":null,"preventionTips":["Always copy config fields onto self in __init__ rather than relying on lazy access","Cover new models with an instantiation smoke test"],"tags":["sglang","dit","post-init","attribute-validation"],"backgroundTag":"missing-required-attribute","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}