sgl-project/sglang · error · ValueError
Cosmos3TokenizationStage requires a tokenizer; expected the
Error message
Cosmos3TokenizationStage requires a tokenizer; expected the Qwen2 tokenizer loaded from the checkpoint's text_tokenizer/ subfolder.
What it means
Cosmos3TokenizationStage needs the Qwen2 text tokenizer (loaded from the checkpoint's text_tokenizer/ subfolder) to build input ids with the chat template. Constructing the stage with tokenizer=None means the checkpoint layout is wrong or the loader skipped the text tokenizer, so __init__ fails fast.
Source
Thrown at python/sglang/multimodal_gen/runtime/pipelines_core/stages/model_specific_stages/cosmos3.py:275
cond_indexes = getattr(batch.sampling_params, "condition_frame_indexes", None)
if not cond_indexes:
return [0, 1]
return sorted(set(int(i) for i in cond_indexes))
class Cosmos3TokenizationStage(PipelineStage):
"""Tokenization stage for Cosmos3.
Applies the Qwen2 chat template, appends a duration suffix, and writes
``text_ids`` / ``text_mask`` into ``batch.extra`` for the denoising stage.
"""
parallelism_type = StageParallelismType.REPLICATED
def __init__(self, tokenizer):
super().__init__()
if tokenizer is None:
raise ValueError(
"Cosmos3TokenizationStage requires a tokenizer; expected the "
"Qwen2 tokenizer loaded from the checkpoint's text_tokenizer/ "
"subfolder."
)
self.tokenizer = tokenizer
def verify_input(self, batch: Req, server_args: ServerArgs) -> VerificationResult:
result = VerificationResult()
result.add_check("prompt", batch.prompt, V.string_or_list_strings)
return result
def _tokenize_prompt(
self,
text: str | list[str],
max_sequence_length: int,
device: torch.device,
use_system_prompt: bool = False,
system_prompt: str | None = None,View on GitHub (pinned to 0132848349)
Solutions
- Verify the checkpoint contains text_tokenizer/ with Qwen2 tokenizer files (tokenizer.json/tokenizer_config.json) and re-download/copy it if missing
- Fix the loader call so it actually loads the text tokenizer from that subfolder and pass the result to the stage
- If converting your own checkpoint, include the Qwen2 tokenizer files under text_tokenizer/
Example fix
# before stage = Cosmos3TokenizationStage(tokenizer=load_model(path).text_tokenizer_or_none) # after tok = AutoTokenizer.from_pretrained(os.path.join(ckpt, "text_tokenizer")) assert tok is not None and tok.pad_token_id is not None stage = Cosmos3TokenizationStage(tokenizer=tok)
Defensive patterns
Strategy: type-guard
Validate before calling
import os
from transformers import AutoTokenizer
sub = os.path.join(ckpt_dir, "text_tokenizer")
assert os.path.isdir(sub) and os.listdir(sub), f"missing {sub}" Type guard
def usable_tokenizer(tok) -> bool:
return tok is not None and getattr(tok, "pad_token_id", None) is not None Prevention
- Validate checkpoint layout (text_tokenizer/ present) before constructing stages
When it happens
Trigger: Instantiating Cosmos3TokenizationStage(tokenizer=None) — typically because the checkpoint directory lacks text_tokenizer/, files failed to download, or the loader returned None for the text tokenizer.
Common situations: Incomplete checkpoint download/transfer missing the text_tokenizer subfolder; using a Cosmos3 checkpoint converted without the Qwen2 text encoder files; loader version change that renamed or stopped auto-loading the subfolder.
Related errors
- Unexpected return type from apply_chat_template: {type(resul
- Action normalization stats not found at {stats_path}.
- scale_shift_table must have shape [9, D]
- Cosmos3 action input accepts one image field; use a list or
- Cosmos3 observation image arrays must use uint8 dtype
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/d200bb8899e5bdd8.
Report an issue: GitHub.