sgl-project/sglang · error · ValueError
Subclass {self.__class__.__name__} must define _supported_at
Error message
Subclass {self.__class__.__name__} must define _supported_attention_backends What it means
Raised by the text encoder base __init__ when the subclass's supported_attention_backends (from _supported_attention_backends) is empty. Every text encoder must declare which attention backends it supports; omitting it is an implementation error caught at construction.
Source
Thrown at python/sglang/multimodal_gen/runtime/models/encoders/base.py:226
]
_fsdp_shard_conditions: list = field(default_factory=lambda: [])
# Methods that drive a forward pass without going through __call__. FSDP2
# only unshards around the wrapped module's own forward, so anything the
# shard conditions left in the root group stays sharded unless the entry
# point is registered; loaders read this and register each name.
_fsdp_forward_methods: tuple[str, ...] = ()
_stacked_params_mapping: list[tuple[str, str, str]] = field(default_factory=list)
_supported_attention_backends: set[AttentionBackendEnum] = (
TextEncoderConfig()._supported_attention_backends
)
def __init__(self, config: TextEncoderConfig) -> None:
super().__init__()
self.config = config
self._fsdp_shard_conditions = config.arch_config._fsdp_shard_conditions
self._stacked_params_mapping = config.arch_config.stacked_params_mapping
if not self.supported_attention_backends:
raise ValueError(
f"Subclass {self.__class__.__name__} must define _supported_attention_backends"
)
@abstractmethod
def forward(
self,
input_ids: torch.Tensor | None,
position_ids: torch.Tensor | None = None,
attention_mask: torch.Tensor | None = None,
inputs_embeds: torch.Tensor | None = None,
output_hidden_states: bool | None = None,
**kwargs,
) -> BaseEncoderOutput:
pass
@property
def supported_attention_backends(self) -> set[AttentionBackendEnum]:
return self._supported_attention_backendsView on GitHub (pinned to 0132848349)
Solutions
- Define _supported_attention_backends = ['flashattention', 'fa3', ...] (non-empty) on your subclass
- Copy the declaration pattern from an existing encoder subclass
Example fix
# before
class MyEncoder(BaseTextEncoder):
_supported_attention_backends: list[str] = []
# after
class MyEncoder(BaseTextEncoder):
_supported_attention_backends = ["flashattention", "triton_attn"] Defensive patterns
Strategy: validation
Validate before calling
assert getattr(MyEncoder, "supported_attention_backends", None), "declare _supported_attention_backends"
Type guard
def declares_backends(cls) -> bool:
return bool(getattr(cls, "_supported_attention_backends", None)) Prevention
- When adding a new encoder, copy the backend declaration from an existing subclass first
When it happens
Trigger: Subclassing the base text encoder without defining _supported_attention_backends (or defining it as an empty list) and instantiating the subclass.
Common situations: Adding a new text encoder model class and forgetting the backend declaration required by the base class contract.
Related errors
- flashinfer_sparse_mla supports only GLM DSA with FP8 KV cach
- GLM DSA with FP8 KV cache on NVIDIA SM120/SM121 supports onl
- MiniMax-H3 ring parallelism requires the FlashAttention back
- AITer backend does not have a metadata builder.
- AITer backend requires num_heads ({num_heads}) to be a multi
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/bc4f7d84be0d6c10.
Report an issue: GitHub.