sgl-project/sglang · error · AttributeError
Subclasses of BaseDiT must define '{attr}' class variable
Error message
Subclasses of BaseDiT must define '{attr}' class variable What it means
BaseDiT uses __init_subclass__ to enforce that every DiT model implementation declares a set of required class-level attributes (e.g. param_names_mapping, _compile_conditions). Defining a subclass without these attributes raises AttributeError at class-definition time, i.e. at import of the module containing the subclass, not at instantiation.
Source
Thrown at python/sglang/multimodal_gen/runtime/models/dits/base.py:65
AttentionBackendEnum.VIDEO_SPARSE_ATTN,
AttentionBackendEnum.SPARSE_VIDEO_GEN_2_ATTN,
AttentionBackendEnum.VMOBA_ATTN,
AttentionBackendEnum.SAGE_ATTN_3,
AttentionBackendEnum.LASER_ATTN,
AttentionBackendEnum.BLOCK_SPARSE_ATTN,
AttentionBackendEnum.RAIN_FUSION_ATTN,
}
def __init_subclass__(cls) -> None:
required_class_attrs = [
"_fsdp_shard_conditions",
"param_names_mapping",
"_compile_conditions",
]
super().__init_subclass__()
for attr in required_class_attrs:
if not hasattr(cls, attr):
raise AttributeError(
f"Subclasses of BaseDiT must define '{attr}' class variable"
)
def __init__(self, config: DiTConfig, hf_config: dict[str, Any], **kwargs) -> None:
super().__init__()
# `config.arch_config` contains static model metadata. Runtime
# capabilities remain class attributes on the model implementation.
self.config: DiTArchConfig = config.arch_config
self.prefix = config.prefix
self.hf_config = hf_config
if not self.supported_attention_backends:
raise ValueError(
f"Subclass {self.__class__.__name__} must define _supported_attention_backends"
)
@abstractmethod
def forward(
self,View on GitHub (pinned to 0132848349)
Solutions
- Add the missing attribute(s) named in the message as class variables on your BaseDiT subclass, e.g. param_names_mapping = (...) and _compile_conditions = ...
- Copy the full attribute set from an existing model implementation (e.g. cosmos3video.py or another dits/ model) and adapt values
- Check base.py's required_class_attrs list to see the complete set of required names
Example fix
// before
class MyDiT(BaseDiT):
...
// after
class MyDiT(BaseDiT):
param_names_mapping = {...}
_compile_conditions = ...
... Defensive patterns
Strategy: validation
Validate before calling
from sglang.multimodal_gen.runtime.models.dits.base import BaseDiT
REQUIRED = ["param_names_mapping", "_compile_conditions"]
def check_dit_subclass(cls):
missing = [a for a in REQUIRED if not hasattr(cls, a)]
assert not missing, f"missing class attrs: {missing}"
return True Type guard
def is_valid_dit_subclass(cls) -> bool:
return isinstance(cls, type) and issubclass(cls, BaseDiT) and all(
hasattr(cls, a) for a in ("param_names_mapping", "_compile_conditions")
) Prevention
- Copy a known-good model file as the template when adding a new DiT
- Add a registration-time unit test that imports every model module so subclass contract errors surface in CI
When it happens
Trigger: Creating any class that inherits from BaseDiT without defining all names in required_class_attrs (e.g. missing param_names_mapping or _compile_conditions). The error fires the moment the subclass statement is executed (import time).
Common situations: Adding a new DiT model to sglang's multimodal_gen runtime and forgetting boilerplate class attributes; copying an older model implementation that predates a newly-added required attribute after a version upgrade.
Related errors
- Subclass {self.__class__.__name__} must define _supported_at
- Subclasses of BaseDiT must define '{attr}' instance variable
- Unknown serve backend {name!r}. Available values: {available
- Multiple distributions register serve backend {name!r}: {pro
- Failed to load serve backend {name!r} from {self._entry_poin
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/0e8e36cd6ba18bde.
Report an issue: GitHub.