{"record":{"id":"a49d6de803f2c9a0","repo":"sgl-project/sglang","slug":"invalid-threshold-type-threshold-type-choose","errorCode":null,"errorMessage":"Invalid threshold_type: {threshold_type}. Choose 'query_head', 'block', or 'overall'.","messagePattern":"Invalid threshold_type: (.+?)\\. Choose 'query_head', 'block', or 'overall'\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/csrc/attn/vmoba_attn/vmoba/vmoba.py","lineNumber":768,"sourceCode":"        valid_gate_mask = gate != -float(\"inf\")  # (num_chunk, num_head, seqlen)\n        if threshold_type == \"query_head\":\n            gate_mask = _select_threshold_query_head(\n                gate, valid_gate_mask, gate_self_chunk_mask, simsum_threshold\n            )\n        elif threshold_type == \"block\":\n            gate_mask = _select_threshold_block(\n                gate, valid_gate_mask, gate_self_chunk_mask, simsum_threshold\n            )\n        elif threshold_type == \"overall\":\n            gate_mask = _select_threshold_overall(\n                gate, valid_gate_mask, gate_self_chunk_mask, simsum_threshold\n            )\n        elif threshold_type == \"head_global\":\n            gate_mask = _select_threshold_head_global(\n                gate, valid_gate_mask, gate_self_chunk_mask, simsum_threshold\n            )\n        else:\n            raise ValueError(\n                f\"Invalid threshold_type: {threshold_type}. Choose 'query_head', 'block', or 'overall'.\"\n            )\n    else:\n        raise ValueError(\n            f\"Invalid select_mode: {select_mode}. Choose 'topk' or 'threshold'.\"\n        )\n\n    # eliminate self_chunk in MoBA branch\n    gate_mask = gate_mask & ~gate_self_chunk_mask\n    # if gate_mask is all false, perform flash_attn instead\n    if gate_mask.sum() == 0:\n        return flash_attn_varlen_func(\n            q, k, v, cu_seqlens, cu_seqlens, max_seqlen, max_seqlen, causal=False\n        )\n\n    # Determine which query positions are selected.\n    # nonzero_indices has shape [N, 3] where each row is [chunk_index, head_index, seq_index].\n    moba_q_indices = gate_mask.reshape(gate_mask.shape[0], -1).nonzero(as_tuple=True)[","sourceCodeStart":750,"sourceCodeEnd":786,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/csrc/attn/vmoba_attn/vmoba/vmoba.py#L750-L786","documentation":"Inside the select_mode == 'threshold' branch, moba_attn_varlen dispatches on threshold_type to a specific thresholding helper (_select_threshold_*). Values other than the supported set (including 'query_head'/'block'/'overall' style names not valid here, e.g. anything not handled above 'head_global') raise ValueError.","triggerScenarios":"Calling moba_attn_varlen(..., select_mode='threshold', threshold_type=<unhandled value>) — any string not matched by the if/elif chain ending at 'head_global'.","commonSituations":"Passing a topk-style value such as 'overall' or 'block' when select_mode='threshold' if those aren't handled in the chain; typo'd config keys; configs migrated between modes.","solutions":["Use a threshold_type handled by the threshold branch (e.g. 'head_global' or the other _select_threshold_* names defined in the file)","If you intended top-k selection, use select_mode='topk' with 'query_head'/'block'/'overall'","Print/grep the valid threshold_type literals near vmoba.py:740-770 to confirm supported names for your version"],"exampleFix":"# before\nmoba_attn_varlen(..., select_mode=\"threshold\", threshold_type=\"query_head\")\n# after\nmoba_attn_varlen(..., select_mode=\"threshold\", threshold_type=\"head_global\")","handlingStrategy":"validation","validationCode":"# confirm against the literals handled in vmoba.py's threshold branch\nVALID_THRESHOLD_TYPES = {\"head_global\"}  # extend per your vmoba.py version\nif select_mode == \"threshold\":\n    assert threshold_type in VALID_THRESHOLD_TYPES, threshold_type","typeGuard":"def is_valid_threshold_type(t: str) -> bool:\n    return t in {\"head_global\"}  # keep in sync with _select_threshold_* dispatch","tryCatchPattern":"try:\n    moba_attn_varlen(..., select_mode=\"threshold\", threshold_type=threshold_type)\nexcept ValueError as e:\n    if \"Invalid threshold_type\" in str(e):\n        threshold_type = \"head_global\"\n    else:\n        raise","preventionTips":["Grep vmoba.py for `_select_threshold_` helpers to enumerate valid names each version","Fail fast on unknown config strings during model init","Keep mode/threshold_type pairs together in a single config dataclass"],"tags":["validation","value-error","moba","attention","config"],"backgroundTag":"invalid-enum-argument","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}