sgl-project/sglang · error · ValueError
{key}.{field} is required
Error message
{key}.{field} is required What it means
forward() reads fields from per-modality position/psp structures via _psp_field, which requires the field to exist (dict key or object attribute). The error message names both the modality key and the missing field, e.g. 'audio.psp_lengths is required'.
Source
Thrown at python/sglang/multimodal_gen/runtime/models/dits/minimax_h3.py:2121
@staticmethod
def _pos_ids(pos_info: Any, key: str) -> torch.Tensor:
if isinstance(pos_info, dict):
ids = pos_info.get("position_ids")
else:
ids = getattr(pos_info, "position_ids", None)
if ids is None:
raise ValueError(f"{key}.position_ids is required")
return ids.view(-1).to(torch.long)
@staticmethod
def _psp_field(psp: Any, key: str, field: str) -> Any:
if isinstance(psp, dict):
value = psp.get(field)
else:
value = getattr(psp, field, None)
if value is None:
raise ValueError(f"{key}.{field} is required")
return value
@staticmethod
def _psp_optional_field(psp: Any, field: str) -> Any:
if isinstance(psp, dict):
return psp.get(field)
return getattr(psp, field, None)
def refine_prompt_embeds(
self,
prompt_embeds: torch.Tensor,
refiner_cu_seqlens: torch.Tensor,
*,
device: torch.device,
) -> torch.Tensor:
"""Project and refine request-static text conditioning once."""
self.materialize_mps_non_layer_weights(
"condition_proj", "token_refiner.final_norm"View on GitHub (pinned to 0132848349)
Solutions
- Inspect the error's {key}.{field} and add that field with the correct tensor to the input structure
- Cross-check against the model's input dataclass / docs for the full required field list per modality
- Write a small pre-flight validator that walks required fields before calling forward
Example fix
# before
psp = {"video": {"psp_lengths": lens}} # missing companion field
# after
psp = {"video": {"psp_lengths": lens, REQUIRED_FIELD: vals}} # per error message Defensive patterns
Strategy: type-guard
Validate before calling
REQUIRED = ("field_a", "field_b") # per error message
for key, psp in psp_inputs.items():
for f in REQUIRED:
v = psp.get(f) if isinstance(psp, dict) else getattr(psp, f, None)
assert v is not None, f"{key}.{f}" Type guard
def psp_complete(psp: Any, fields: tuple) -> bool:
for f in fields:
v = psp.get(f) if isinstance(psp, dict) else getattr(psp, f, None)
if v is None:
return False
return True Prevention
- Mirror the model's input schema in typed dataclasses
- Log dropped/None fields during batch construction
When it happens
Trigger: Passing a psp dict like {"audio": {"psp_lengths": x}} where 'audio.field_name' is absent — e.g. missing 'psp_values', 'lengths', or similar required companion field.
Common situations: Hand-built multimodal batches missing companion fields; schema changes where a field was renamed or made required; partial serialization dropping None-valued keys.
Related errors
- Unsupported image type: {type(image)}
- When using multiple prompts with multiple input images, prov
- {key}.position_ids is required
- You have to specify input_ids
- Hunyuan3D requires 'image_path' input.
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/fc6f5f8cad540164.
Report an issue: GitHub.