jingyaogong/minimind · error · ValueError
不支持的引擎类型: {engine_type}
Error message
不支持的引擎类型: {engine_type} What it means
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.
Source
Thrown at trainer/rollout_engine.py:224
# ===== 工厂函数 =====
def create_rollout_engine(
engine_type: str = "torch",
policy_model: torch.nn.Module = None,
tokenizer = None,
device: str = "cuda",
autocast_ctx = None,
sglang_base_url: str = None,
sglang_model_path: str = None,
sglang_shared_path: str = None,
) -> RolloutEngine:
if engine_type == "torch":
return TorchRolloutEngine(policy_model, tokenizer, device, autocast_ctx)
elif engine_type == "sglang":
return SGLangRolloutEngine(sglang_base_url, sglang_model_path, sglang_shared_path)
else:
raise ValueError(f"不支持的引擎类型: {engine_type}")
View on GitHub (pinned to 393e387e9a)
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.
Example fix
# before
engine = create_rollout_engine(engine_type=config.get('engine'), ...)
# after
engine_type = (config.get('engine') or 'torch').strip().lower()
if engine_type not in ('torch', 'sglang'):
raise ValueError(f"engine must be 'torch' or 'sglang', got {engine_type!r}")
engine = create_rollout_engine(engine_type=engine_type, ...) Defensive patterns
Strategy: validation
Validate before calling
SUPPORTED_ENGINES = ('torch', 'sglang')
engine_type = (engine_type or 'torch').strip().lower()
if engine_type not in SUPPORTED_ENGINES:
raise ValueError(
f"engine_type must be one of {SUPPORTED_ENGINES}, got {engine_type!r}"
)
engine = create_rollout_engine(engine_type=engine_type, ...) Type guard
def is_supported_engine(value: str) -> bool:
"""Type guard for create_rollout_engine's engine_type argument."""
return isinstance(value, str) and value.strip().lower() in ('torch', 'sglang') Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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').
AI-assisted analysis of jingyaogong/minimind@393e387e9a (2026-08-15).
Data as JSON: /api/errors/001d6611640f25f6.
Report an issue: GitHub.