sgl-project/sglang · error · ValueError
Invalid {field_name}={value!r}.
Error message
Invalid {field_name}={value!r}. What it means
Raised by _parse_optional_int while parsing the DFLASH draft config: the field's value is not None and cannot be converted with int(). This is a config deserialization error — a required-numeric field was given a non-numeric value such as a bad string or a nested object.
Source
Thrown at python/sglang/srt/speculative/dflash_utils.py:519
sample_from_anchor = dflash_config.get(
"sample_from_anchor", _cfg_get(config, "sample_from_anchor", True)
)
return sample_from_anchor is False
def _parse_optional_int(
value: Any,
*,
field_name: str,
min_value: Optional[int] = None,
) -> Optional[int]:
if value is None:
return None
try:
parsed = int(value)
except Exception as e:
raise ValueError(f"Invalid {field_name}={value!r}.") from e
if min_value is not None and parsed < int(min_value):
comparator = "positive" if int(min_value) == 1 else f">= {int(min_value)}"
raise ValueError(f"{field_name} must be {comparator}, got {parsed}.")
return parsed
@dataclass(frozen=True)
class DFlashDraftConfig:
num_hidden_layers: Optional[int]
num_target_layers: Optional[int]
block_size: Optional[int]
conv_kernel_size: int
conv_group_size: int
selector_rank: int
selector_top_k: int
output_multiplier: float
final_logit_softcapping: Optional[float]
target_layer_ids: Optional[List[int]]View on GitHub (pinned to 0132848349)
Solutions
- Fix the offending field in the draft config to be an integer or null.
- Use the error's chained cause (raise ... from e) and the field_name in the message to identify which field failed, then correct just that entry.
- Validate the draft config JSON with a schema/lint before deploying.
Example fix
# before
{"speculative_num_draft_tokens": "eight"}
# after
{"speculative_num_draft_tokens": 8} Defensive patterns
Strategy: validation
Validate before calling
for k, v in draft_cfg.items():
if v is not None and not isinstance(v, (int, float)):
try:
int(v)
except (TypeError, ValueError):
raise ValueError(f'{k} must be int-convertible, got {v!r}') Type guard
def is_int_like(v) -> bool:
if v is None or isinstance(v, bool):
return v is None
try:
int(v)
return True
except (TypeError, ValueError):
return False Try / catch
try:
cfg = parse_dflash_draft_config(raw)
except ValueError as e:
raise ConfigError(f'draft config invalid: {e}') from e Prevention
- Validate the draft config JSON against a schema before deployment.
- Never hand-type numeric config values as strings.
When it happens
Trigger: parse_dflash_draft_config on a config where a field like speculative_num_draft_tokens is "eight", "", [8], or a dict; any int(field) call raising ValueError/TypeError.
Common situations: Hand-edited draft config JSON with quoted or malformed numbers; YAML/JSON passing a list where a scalar int is expected; env-var overrides injected as strings like "null" instead of null.
Related errors
- DFLASH config.layer_types must be a sequence of attention ty
- {option} must be a dict or a comma-separated component=value
- DFLASH speculative decoding only supports CUDA and NPU devic
- Currently DFLASH speculative decoding does not support dp at
- Currently DFLASH speculative decoding only supports pp_size
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/26d0ddb5a594bcf4.
Report an issue: GitHub.