{"record":{"id":"965fc2e53cf469bf","repo":"sgl-project/sglang","slug":"mode-must-be-one-of-valid-modes-got-mode","errorCode":null,"errorMessage":"Mode must be one of {valid_modes}, got {mode}","messagePattern":"Mode must be one of (.+?), got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/multimodal_gen/runtime/layers/attention/STA_configuration.py","lineNumber":54,"sourceCode":"        Mode-specific parameters:\n\n        For 'STA_searching':\n        - mask_candidates: list of str, optional, mask candidates to use\n        - mask_selected: list of int, optional, indices of selected masks\n\n        For 'STA_tuning':\n        - mask_search_files_path: str, required, path to mask search results\n        - mask_candidates: list of str, optional, mask candidates to use\n        - mask_selected: list of int, optional, indices of selected masks\n        - skip_time_steps: int, optional, number of time steps to use full attention (default 12)\n        - save_dir: str, optional, directory to save mask strategy (default \"mask_candidates\")\n\n        For 'STA_inference':\n        - load_path: str, optional, path to load mask strategy (default \"mask_candidates/mask_strategy.json\")\n    \"\"\"\n    valid_modes = [\"STA_searching\", \"STA_tuning\", \"STA_inference\", \"STA_tuning_cfg\"]\n    if mode not in valid_modes:\n        raise ValueError(f\"Mode must be one of {valid_modes}, got {mode}\")\n\n    if mode == \"STA_searching\":\n        # Get parameters with defaults\n        mask_candidates: list[str] | None = kwargs.get(\"mask_candidates\")\n        if mask_candidates is None:\n            raise ValueError(\"mask_candidates is required for STA_searching mode\")\n        mask_selected: list[int] = kwargs.get(\n            \"mask_selected\", list(range(len(mask_candidates)))\n        )\n\n        # Parse selected masks\n        selected_masks: list[list[int]] = []\n        for index in mask_selected:\n            mask = mask_candidates[index]\n            masks_list = [int(x) for x in mask.split(\",\")]\n            selected_masks.append(masks_list)\n\n        # Create 3D mask structure with fixed dimensions (t=50, l=60)","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/multimodal_gen/runtime/layers/attention/STA_configuration.py#L36-L72","documentation":"configure_sta configures Sparse-Triangle-Attention modes and only accepts four modes: STA_searching, STA_tuning, STA_inference, STA_tuning_cfg. Passing any other mode string raises immediately, before any kwargs are read.","triggerScenarios":"Calling configure_sta(mode, **kwargs) with a typo'd or unsupported mode, e.g. 'sta_searching' (lowercase), 'STA_search', or a newly added mode not in the valid_modes list at STA_configuration.py:54.","commonSituations":"Case/typo mismatches with the exact enum-like strings; code copied from docs of a different version; extending STA with a new mode without updating valid_modes.","solutions":["Use exactly one of: 'STA_searching', 'STA_tuning', 'STA_inference', 'STA_tuning_cfg' (case-sensitive).","If adding a new mode, append it to valid_modes and implement its branch.","Normalize/validate mode strings at the call site before invoking configure_sta."],"exampleFix":"# before\nparams = configure_sta('sta_searching', mask_candidates=[...])\n# after\nparams = configure_sta('STA_searching', mask_candidates=[...])","handlingStrategy":"validation","validationCode":"VALID_STA_MODES = {\"STA_searching\",\"STA_tuning\",\"STA_inference\",\"STA_tuning_cfg\"}\nassert mode in VALID_STA_MODES, f\"mode must be one of {VALID_STA_MODES}\"","typeGuard":"def is_valid_sta_mode(mode: str) -> bool:\n    return mode in {\"STA_searching\",\"STA_tuning\",\"STA_inference\",\"STA_tuning_cfg\"}","tryCatchPattern":null,"preventionTips":["Define mode names as module constants instead of inline strings.","Watch case: mode strings are case-sensitive."],"tags":["sta","attention","mode-validation","argument-validation"],"backgroundTag":"invalid-mode-string","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}