sgl-project/sglang · error · ValueError

Invalid simulate_acc_method: {simulate_acc_method}

Error message

Invalid simulate_acc_method: {simulate_acc_method}

What it means

sample_simulated_acc_len supports a fixed set of simulate_acc_method values (its if/elif chain). An unrecognized method string reaches the else branch and raises ValueError.

Source

Thrown at python/sglang/srt/speculative/spec_utils.py:392

    elif simulate_acc_method == "match-expected":
        # multinomial sampling does not match the expected length
        # we keep it for the sake of compatibility of existing tests
        # but it's better to use "match-expected" for the cases that need to
        # match the expected length, One caveat is that this will only sample
        # either round down or round up of the expected length
        simulate_acc_len = max(1.0, min(max_len, simulate_acc_len))
        lower = int(simulate_acc_len // 1)
        upper = lower + 1 if lower < max_len else lower
        if lower == upper:
            simulate_acc_len = lower
        else:
            weight_upper = simulate_acc_len - lower
            weight_lower = 1.0 - weight_upper
            probs = torch.tensor([weight_lower, weight_upper], device="cpu")
            sampled_index = torch.multinomial(probs, num_samples=1)
            simulate_acc_len = lower if sampled_index == 0 else upper
    else:
        raise ValueError(f"Invalid simulate_acc_method: {simulate_acc_method}")
    return int(simulate_acc_len)


def generate_simulated_accept_index(
    accept_index,
    predict,
    num_correct_drafts,
    candidates,
    target_predict,
    bs,
    spec_steps,
    simulate_acc_len: float = SIMULATE_ACC_LEN,
    simulate_acc_method: str = SIMULATE_ACC_METHOD,
    simulate_acc_token_mode: str = SIMULATE_ACC_TOKEN_MODE,
):
    use_real_draft_tokens = simulate_acc_token_mode == "real-draft-token"

    assert simulate_acc_len > 0.0

View on GitHub (pinned to 0132848349)

Solutions

  1. Check the if/elif chain in spec_utils.py:sample_simulated_acc_len for accepted method strings
  2. Fix the typo in the simulate_acc_method config
  3. If you need a new method, implement the branch and add it to validation

Example fix

# before
sample_simulated_acc_len(..., simulate_acc_method='unifrom')
# after
sample_simulated_acc_len(..., simulate_acc_method='uniform')
Defensive patterns

Strategy: validation

Validate before calling

valid_methods = {'fixed_prob', 'uniform', 'normal'}  # mirror the if/elif chain in spec_utils.py
assert simulate_acc_method in valid_methods, simulate_acc_method

Type guard

def is_valid_acc_method(m: str) -> bool:
    return m in {'fixed_prob', 'uniform', 'normal'}

Prevention

When it happens

Trigger: Passing simulate_acc_method other than the supported options (e.g. a typo like 'unifrom' instead of 'uniform', or a new method not implemented), via apply_dflash_simulated_acceptance or related simulated-acceptance APIs.

Common situations: Configuring DFlash simulated acceptance with a mistyped method name; version mismatch where a method was renamed/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


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