{"record":{"id":"6f5cd4e9a2ed7f9a","repo":"sgl-project/sglang","slug":"unknown-token-type-token-type-only-support-tex","errorCode":null,"errorMessage":"Unknown token_type {token_type}, only support \"text\" or \"image\".","messagePattern":"Unknown token_type (.+?), only support \"text\" or \"image\"\\.","errorType":"validation","errorClass":"KeyError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/configs/pipeline_configs/longcat_image.py","lineNumber":110,"sourceCode":"    num_token=None,\n    height=None,\n    width=None,\n):\n    if token_type == \"text\":\n        assert num_token\n        pos_ids = torch.zeros(num_token, 3)\n        pos_ids[..., 0] = modality_id\n        pos_ids[..., 1] = torch.arange(num_token) + start[0]\n        pos_ids[..., 2] = torch.arange(num_token) + start[1]\n    elif token_type == \"image\":\n        assert height and width\n        pos_ids = torch.zeros(height, width, 3)\n        pos_ids[..., 0] = modality_id\n        pos_ids[..., 1] = pos_ids[..., 1] + torch.arange(height)[:, None] + start[0]\n        pos_ids[..., 2] = pos_ids[..., 2] + torch.arange(width)[None, :] + start[1]\n        pos_ids = pos_ids.reshape(height * width, 3)\n    else:\n        raise KeyError(\n            f'Unknown token_type {token_type}, only support \"text\" or \"image\".'\n        )\n    return pos_ids\n\n\ndef _tokenize_prompt_for_encode(prompt, tokenizer):\n    \"\"\"Quote-aware tokenization mirroring diffusers LongCatImagePipeline._encode_prompt.\n\n    Quoted substrings are tokenized character-by-character; unquoted substrings\n    are tokenized whole. Truncated/padded to TOKENIZER_MAX_LENGTH. Returns the\n    padded (input_ids, attention_mask) for the prompt body (without prefix/suffix).\n    \"\"\"\n    if isinstance(prompt, str):\n        prompt = [prompt]\n\n    batch_all_tokens = []\n    for each_prompt in prompt:\n        all_tokens = []","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/configs/pipeline_configs/longcat_image.py#L92-L128","documentation":"Longcat image pipeline's _prepare_pos_ids builds (modality, row, col) position ids and only accepts token_type of \"text\" or \"image\". Any other value raises this KeyError.","triggerScenarios":"Calling the internal ID-preparation path (maybe_prepare_latent_ids, prepare_pos_cond_kwargs, prepare_neg_cond_kwargs, or _edit_img_ids) with a token_type other than \"text\"/\"image\" — e.g. \"video\", \"Text\", \"img\", or None.","commonSituations":"Extending the pipeline to new modalities and passing a new token type; typos or case mismatches (\"Image\" vs \"image\"); copying code from another pipeline that uses different token_type names.","solutions":["Use exactly \"text\" or \"image\" (lowercase) as token_type","Check for typos/case: \"Image\", \"TEXT\", \"img\" are all invalid","If you need a new modality, extend _prepare_pos_ids's branch handling rather than passing an unknown token_type"],"exampleFix":"# before\npos_ids = cfg._prepare_pos_ids(token_type=\"img\", ...)\n\n# after\npos_ids = cfg._prepare_pos_ids(token_type=\"image\", ...)","handlingStrategy":"validation","validationCode":"assert token_type in (\"text\", \"image\"), f\"bad token_type: {token_type!r}\"","typeGuard":"def is_supported_token_type(t: str) -> bool:\n    return t in (\"text\", \"image\")","tryCatchPattern":"except KeyError as e:\n    if \"Unknown token_type\" in str(e):\n        token_type = token_type.lower()\n        # remap aliases then retry or fail fast with context","preventionTips":["Centralize token_type constants instead of inline strings","Lowercase/normalize inputs at the API boundary"],"tags":["sglang","longcat-image","token-type","position-ids","invalid-argument"],"backgroundTag":"unsupported-enum-value","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}