sgl-project/sglang · error · ValueError

{field_name} must be {comparator}, got {parsed}.

Error message

{field_name} must be {comparator}, got {parsed}.

What it means

Raised by _parse_optional_int when a numeric field parses successfully but violates its minimum, e.g. a count field set to 0 or negative when min_value=1. The message names the field, the required bound ("positive" or ">= N"), and the parsed value, so it pinpoints the bad entry in the DFLASH draft config.

Source

Thrown at python/sglang/srt/speculative/dflash_utils.py:522

    )
    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]]
    mask_token: str
    mask_token_id: Optional[int]

View on GitHub (pinned to 0132848349)

Solutions

  1. Raise the field's value to at least the stated minimum (usually >= 1), or set it to null to use the default.
  2. Check the DFlash draft config spec/docs for that field's allowed range.
  3. If you intended to disable a feature, remove the field or set null rather than 0.

Example fix

# before
{"speculative_eagle_topk": 0}
# after
{"speculative_eagle_topk": 1}
Defensive patterns

Strategy: validation

Validate before calling

FIELD_MIN = {'speculative_num_draft_tokens': 1, 'speculative_eagle_topk': 1}
for k, lo in FIELD_MIN.items():
    v = draft_cfg.get(k)
    if v is not None and int(v) < lo:
        raise ValueError(f'{k} must be >= {lo}, got {v}')

Type guard

def within_min(v, lo: int) -> bool:
    return v is None or (isinstance(v, int) and v >= lo)

Prevention

When it happens

Trigger: parse_dflash_draft_config with a field like topk/k compile to 0 when min_value >= 1, or a threshold set below its floor; parsed < int(min_value) triggers the raise.

Common situations: Draft config JSON sets a count to 0 thinking it disables the feature (use null instead); negative values from env overrides; copying a draft config from a different DFlash version with different minimums.

Related errors


AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28). Data as JSON: /api/errors/9bd81fa5e4557584. Report an issue: GitHub.