sgl-project/sglang · error · ValueError
Invalid backend: {value}. Must be one of: {', '.join([m.valu
Error message
Invalid backend: {value}. Must be one of: {', '.join([m.value for m in cls])} What it means
Raised by Backend.from_string when the string passed cannot be matched to a Backend enum member. The lookup is cls(value.lower()), so any string that is not exactly (case-insensitively) one of the enum's values fails. The message lists all valid values.
Source
Thrown at python/sglang/multimodal_gen/runtime/server_args/server_args.py:131
class Backend(str, Enum):
"""
Enumeration for different model backends.
- AUTO: Automatically select backend (prefer sglang native, fallback to diffusers)
- SGLANG: Use sglang's native optimized implementation
- DIFFUSERS: Use vanilla diffusers pipeline (supports all diffusers models)
"""
AUTO = "auto"
SGLANG = "sglang"
DIFFUSERS = "diffusers"
@classmethod
def from_string(cls, value: str) -> "Backend":
"""Convert string to Backend enum."""
try:
return cls(value.lower())
except ValueError:
raise ValueError(
f"Invalid backend: {value}. Must be one of: {', '.join([m.value for m in cls])}"
) from None
@classmethod
def choices(cls) -> list[str]:
"""Get all available choices as strings for argparse."""
return [backend.value for backend in cls]
WARMUP_MODES = ("off", "request", "server")
# Default prompt sequence-length buckets for breakable CUDA graph (BCG) padding.
# Prompt-conditioning is padded up to the smallest bucket that fits so prompts
# of different lengths share one captured graph.
DEFAULT_BCG_TEXT_BUCKETS = (64, 128, 256, 512, 1024)
BREAKABLE_CUDA_GRAPH_SUPPORTED_MODEL_IDS = frozenset(
{View on GitHub (pinned to 0132848349)
Solutions
- Fix the string to exactly match one of the values printed in the error message
- Check the enum definition next to from_string in server_args.py for the authoritative list of valid values
- If loading from config/env, strip whitespace and normalize case before calling from_string
Example fix
# before
Backend.from_string("flashinde ")
# after
Backend.from_string("flashinfer") Defensive patterns
Strategy: validation
Validate before calling
from sglang.multimodal_gen.runtime.server_args.server_args import Backend
valid = {m.value for m in Backend}
if value.lower() not in valid:
raise SystemExit(f"unsupported backend {value!r}; choose from {sorted(valid)}")
backend = Backend.from_string(value) Type guard
def is_valid_backend(value: str) -> bool:
return isinstance(value, str) and value.lower() in {m.value for m in Backend} Prevention
- Validate backend strings against Backend values before constructing ServerArgs
- Centralize backend name constants instead of scattering literals
When it happens
Trigger: Calling from_string('tensorrt') when no such enum member exists; passing a backend name with a typo, trailing whitespace, or a value not defined on the Backend enum. Callers include derive_pool_result_endpoint, Backend.__post_init__, and from_kwargs.
Common situations: CLI/config typos in --backend style flags, copying a backend name from another project (e.g. 'trt', 'nccl'), version changes where a backend value was renamed or removed.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- rollout_sde_type must be one of {_VALID_ROLLOUT_SDE_TYPES},
- Invalid attention backend '{backend}'. Available options are
- kv-canary: kv_canary must be one of none/log/raise, got {mod
- Unknown CacheAware Policy: {policy=}
- Unknown CacheAgnostic Policy: {policy=}
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/7ceb867291fa3acd.
Report an issue: GitHub.