sgl-project/sglang · error · AttributeError
lm_head is not available in encoder-only mode
Error message
lm_head is not available in encoder-only mode
What it means
The lm_head property raises AttributeError when the Kimi-K3 model is in encoder-only mode, because there is no language model and therefore no output head. Code that reads lm_head for logits-related metadata, tied-weight detection, or sampling setup will fail on an encoder-only instance.
Source
Thrown at python/sglang/srt/models/kimi_k3.py:3319
def precompile_kernels_after_loading(self) -> None:
if self.config.language_only:
return
if self.vision_tower.precompile_fused_rope():
logger.info("Precompiled dynamic-token fused K3 vision RoPE kernel")
if self.vision_tower.precompile_attention_backend():
logger.info("Precompiled Kimi-K3 vision FA4 kernel")
def get_input_embeddings(self):
if self.language_model is None:
raise AttributeError(
"get_input_embeddings() is not available in encoder-only mode"
)
return self.language_model.model.embed_tokens
@property
def lm_head(self):
if self.language_model is None:
raise AttributeError("lm_head is not available in encoder-only mode")
return self.language_model.lm_head
def set_dspark_layers_to_capture(self, layer_ids: list[int]) -> None:
if self.language_model is None:
raise AttributeError(
"DSPARK layer capture is not available in encoder-only mode"
)
self.language_model.set_dspark_layers_to_capture(layer_ids)
def preprocess_mm_for_encoder(
self,
mm_data,
modality,
config,
*,
image_processor=None,
use_gpu_preprocessing=False,
):View on GitHub (pinned to 0132848349)
Solutions
- Guard access with model.language_model is not None before reading lm_head
- Mark encoder-only instances and branch generic logit/weight logic away from them
- Confirm the deployment actually intended encoder-only mode
Example fix
// before head = model.lm_head // after head = model.lm_head if model.language_model is not None else None
Defensive patterns
Strategy: type-guard
Validate before calling
assert model.language_model is not None, "encoder-only instance has no lm_head"
Type guard
def has_lm_head(m) -> bool:
return getattr(m, "language_model", None) is not None Try / catch
try:
head = model.lm_head
except AttributeError:
head = None Prevention
- Gate tied-weight/logit logic on presence of a language model
- Test generic harness paths against an encoder-only build
When it happens
Trigger: Accessing model.lm_head on an encoder-only Kimi-K3 build (language_model is None), e.g. during weight loading, tied-weight checks, or logit setup in generic paths.
Common situations: EPD encoder deployment where only the vision tower is loaded; shared utilities assuming every model exposes lm_head.
Related errors
- get_input_embeddings() is not available in encoder-only mode
- DSPARK layer capture is not available in encoder-only mode
- module {__name__!r} has no attribute {name!r}
- attn_res: nvb must be in [1, {_MAX_BANK_ROWS}], got {nvb}
- Unsupported text encoder output: expected `hidden_states`.
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/9fbd9707e8c5561c.
Report an issue: GitHub.