{"record":{"id":"703f481b99a0c130","repo":"sgl-project/sglang","slug":"invalid-select-mode-select-mode-choose-topk","errorCode":null,"errorMessage":"Invalid select_mode: {select_mode}. Choose 'topk' or 'threshold'.","messagePattern":"Invalid select_mode: (.+?)\\. Choose 'topk' or 'threshold'\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/csrc/attn/vmoba_attn/vmoba/vmoba.py","lineNumber":772,"sourceCode":"            )\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)[\n        -1\n    ]  # [(h s k)]\n    moba_q_sh_indices = (moba_q_indices % seqlen) * num_head + (\n        moba_q_indices // seqlen","sourceCodeStart":754,"sourceCodeEnd":790,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/csrc/attn/vmoba_attn/vmoba/vmoba.py#L754-L790","documentation":"moba_attn_varlen only supports two gate selection modes: 'topk' and 'threshold'. Any other select_mode string falls through to the final else and raises ValueError.","triggerScenarios":"Calling moba_attn_varlen(..., select_mode=<not 'topk' or 'threshold'>), e.g. 'top_k', 'Threshold', 'score'.","commonSituations":"Typo or casing mistake in the mode string; configs from a different library version that renamed modes; defaulting select_mode from an unset config variable (None).","solutions":["Set select_mode to exactly 'topk' or 'threshold' (case-sensitive)","If the value comes from a config, validate/normalize it before the call and ensure it is not None"],"exampleFix":"# before\nmoba_attn_varlen(..., select_mode=\"top_k\")\n# after\nmoba_attn_varlen(..., select_mode=\"topk\")","handlingStrategy":"validation","validationCode":"VALID_SELECT_MODES = {\"topk\", \"threshold\"}\nif select_mode not in VALID_SELECT_MODES:\n    raise ValueError(f\"select_mode must be one of {VALID_SELECT_MODES}, got {select_mode!r}\")","typeGuard":"def is_valid_select_mode(m: str) -> bool:\n    return m in {\"topk\", \"threshold\"}","tryCatchPattern":"try:\n    moba_attn_varlen(..., select_mode=select_mode)\nexcept ValueError as e:\n    if \"Invalid select_mode\" in str(e):\n        select_mode = \"topk\"\n    else:\n        raise","preventionTips":["Validate select_mode at config parse time with an allowlist","Default the field so it is never None","Add a smoke test that each documented mode string runs"],"tags":["validation","value-error","moba","attention","select-mode"],"backgroundTag":"invalid-enum-argument","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}