{"record":{"id":"001d6611640f25f6","repo":"jingyaogong/minimind","slug":"engine-type","errorCode":null,"errorMessage":"不支持的引擎类型: {engine_type}","messagePattern":"不支持的引擎类型: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"trainer/rollout_engine.py","lineNumber":224,"sourceCode":"\n\n# ===== 工厂函数 =====\ndef create_rollout_engine(\n    engine_type: str = \"torch\",\n    policy_model: torch.nn.Module = None,\n    tokenizer = None,\n    device: str = \"cuda\",\n    autocast_ctx = None,\n    sglang_base_url: str = None,\n    sglang_model_path: str = None,\n    sglang_shared_path: str = None,\n) -> RolloutEngine:\n    if engine_type == \"torch\":\n        return TorchRolloutEngine(policy_model, tokenizer, device, autocast_ctx)\n    elif engine_type == \"sglang\":\n        return SGLangRolloutEngine(sglang_base_url, sglang_model_path, sglang_shared_path)\n    else:\n        raise ValueError(f\"不支持的引擎类型: {engine_type}\")\n","sourceCodeStart":206,"sourceCodeEnd":225,"githubUrl":"https://github.com/jingyaogong/minimind/blob/393e387e9ad99f0f04c296e4c5e7353f4444629f/trainer/rollout_engine.py#L206-L225","documentation":"ValueError raised by the create_rollout_engine factory (trainer/rollout_engine.py) when engine_type is neither the literal 'torch' nor 'sglang'. It is deliberate input validation at the API boundary: only two backends exist, TorchRolloutEngine(policy_model, tokenizer, device, autocast_ctx) and SGLangRolloutEngine(sglang_base_url, sglang_model_path, sglang_shared_path). The f-string message interpolates the offending value, so the error text is whatever string was passed.","triggerScenarios":"Calling create_rollout_engine(engine_type=...) with any value outside {'torch','sglang'}: typos like 'Torch'/'torch '/'vllm', a config default that was never updated (e.g. engine_type: vllm in a YAML), or passing None because a CLI/config key was misspelled and the loader fell back to None. Note the check is case- and whitespace-sensitive with no normalization.","commonSituations":"Renaming or extending the trainer config with a new backend string (e.g. after adding a vLLM engine that is not merged); copying a config from an older/newer revision where the accepted names differ; reading engine_type from argparse with a wrong default; case mismatch from JSON/YAML ('SGLang' vs 'sglang').","solutions":["Set engine_type to exactly 'torch' (in-process rollout with your policy model) or 'sglang' (external SGLang server rollout) — lowercase, no whitespace.","If you intended 'sglang', also supply sglang_base_url, sglang_model_path, sglang_shared_path; if 'torch', supply policy_model, tokenizer, device, autocast_ctx.","Normalize the value where it enters: engine_type = engine_type.strip().lower() before the factory call.","If you believe a third backend should exist, check the repo version — you may be on a branch that only implements two engines."],"exampleFix":"# before\nengine = create_rollout_engine(engine_type=config.get('engine'), ...)\n\n# after\nengine_type = (config.get('engine') or 'torch').strip().lower()\nif engine_type not in ('torch', 'sglang'):\n    raise ValueError(f\"engine must be 'torch' or 'sglang', got {engine_type!r}\")\nengine = create_rollout_engine(engine_type=engine_type, ...)","handlingStrategy":"validation","validationCode":"SUPPORTED_ENGINES = ('torch', 'sglang')\n\nengine_type = (engine_type or 'torch').strip().lower()\nif engine_type not in SUPPORTED_ENGINES:\n    raise ValueError(\n        f\"engine_type must be one of {SUPPORTED_ENGINES}, got {engine_type!r}\"\n    )\nengine = create_rollout_engine(engine_type=engine_type, ...)","typeGuard":"def is_supported_engine(value: str) -> bool:\n    \"\"\"Type guard for create_rollout_engine's engine_type argument.\"\"\"\n    return isinstance(value, str) and value.strip().lower() in ('torch', 'sglang')","tryCatchPattern":null,"preventionTips":["Normalize engine_type (strip + lower) at the config/CLI boundary, not at the factory call site.","Define the accepted values once (e.g. argparse choices=['torch','sglang']) so invalid input fails at parse time with a clear message.","Add a startup assert listing valid engines so config drift from other branches fails fast."],"tags":["validation","factory","configuration","rollout-engine"],"backgroundTag":null,"analyzedSha":"393e387e9ad99f0f04c296e4c5e7353f4444629f","analyzedAt":"2026-08-15T03:55:47.817Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}