{"record":{"id":"68301644209197ad","repo":"sgl-project/sglang","slug":"unknown-mode-mode-r","errorCode":null,"errorMessage":"Unknown mode {mode!r}","messagePattern":"Unknown mode (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/debug_utils/dumper.py","lineNumber":814,"sourceCode":"        original_forward = module.forward\n\n        @functools.wraps(original_forward)\n        def _wrapped(*args, **kwargs):\n            pre_hook(module, args, kwargs)\n            output = original_forward(*args, **kwargs)\n            hook(module, args, output)\n            return output\n\n        module.forward = _wrapped\n\n        class _Handle:\n            def remove(self) -> None:\n                assert module.forward is _wrapped\n                module.forward = original_forward\n\n        return [_Handle()]\n    else:\n        raise ValueError(f\"Unknown mode {mode!r}\")\n\n\n# -------------------------------------- grafter ------------------------------------------\n\n\nclass _GraftRole(enum.Enum):\n    BASELINE = \"baseline\"\n    TARGET = \"target\"\n\n\nclass _GraftDirection(enum.Enum):\n    B2T = \"b2t\"  # name flows baseline -> target\n    T2B = \"t2b\"  # name flows target -> baseline\n\n\n@dataclass\nclass GraftTransformInput:\n    \"\"\"Single argument passed to a user-supplied transform function.","sourceCodeStart":796,"sourceCodeEnd":832,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/debug_utils/dumper.py#L796-L832","documentation":"_register_forward_hook_or_replace_fn supports a fixed set of modes (forward pre-hook, post-hook, or forward replacement) selected by the mode argument in the DumpConfig. An unrecognized mode string falls through the if/elif chain to this ValueError.","triggerScenarios":"Constructing the dumper with a config whose mode is misspelled or from a newer/older version (e.g. 'replace_fn' vs 'replace', 'pre_hook' vs 'pre-hook'); __init__ passes cfg.mode straight through, so bad values surface at construction.","commonSituations":"Typos in the mode string, version skew between the config schema and installed sglang, hand-built config dicts.","solutions":["Check the mode branch labels in _register_forward_hook_or_replace_fn and use one of the exact strings","Use the config dataclass default or a documented constant instead of a raw string","After upgrading sglang, re-check valid mode names — they may have been renamed"],"exampleFix":"# before\ncfg = HookConfig(mode=\"replce\")\n# after\ncfg = HookConfig(mode=\"replace\")  # use exact mode string from source","handlingStrategy":"validation","validationCode":"VALID_MODES = {\"pre\", \"post\", \"replace\"}  # mirror the source branches\nassert cfg.mode in VALID_MODES, f\"mode must be one of {VALID_MODES}\"","typeGuard":null,"tryCatchPattern":"try:\n    dumper = Dumper(cfg)\nexcept ValueError as e:\n    if \"Unknown mode\" in str(e):\n        print(\"valid modes:\", VALID_MODES); raise","preventionTips":["Define mode constants in one module instead of raw strings","Re-check valid modes after upgrading sglang"],"tags":["config","enum-value","debug-utils"],"backgroundTag":"invalid-enum-value","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}