sgl-project/sglang · error · ValueError

Invalid filter_apply_order: {filter_apply_order}

Error message

Invalid filter_apply_order: {filter_apply_order}

What it means

top_k_top_p_sampling_from_probs dispatches on a filter_apply_order string that must be exactly 'top_k_first' or 'joint'. Any other value (typo, wrong case, None) falls through both branches and raises.

Source

Thrown at python/sglang/kernels/aot/python/sgl_kernel/musa.py:314

            renorm_probs,
            top_p,
            indices,
            deterministic,
            generator=generator,
            check_nan=check_nan,
        )
    if filter_apply_order == "joint":
        if check_nan and torch.any(torch.isnan(probs)):
            raise ValueError("Input probs contains NaN.")
        return _top_k_top_p_sampling_from_probs_internal(
            probs,
            indices,
            *_to_tensor_scalar_tuple(top_k),
            *_to_tensor_scalar_tuple(top_p),
            deterministic,
            generator,
        )
    raise ValueError(f"Invalid filter_apply_order: {filter_apply_order}")


def _min_p_sampling_from_probs_internal(
    probs: torch.Tensor,
    indices: Optional[torch.Tensor],
    maybe_min_p_arr: Optional[torch.Tensor],
    min_p_val: float,
    deterministic: bool,
    generator: Optional[torch.Generator],
) -> torch.Tensor:
    device = probs.device
    probs = probs.float()
    maybe_min_p_arr = maybe_min_p_arr.float() if maybe_min_p_arr is not None else None
    samples = torch.empty(probs.size(0), dtype=torch.int32, device=device)
    torch.ops.sgl_kernel.min_p_sampling_from_probs.default(
        probs,
        samples,
        indices,

View on GitHub (pinned to 0132848349)

Solutions

  1. Use exactly 'top_k_first' or 'joint'
  2. If constructing dynamically, validate/normalize against {'top_k_first','joint'} before the call
  3. Pin the sgl-kernel version and check its docstring for the accepted values

Example fix

# before
sampled = top_k_top_p_sampling_from_probs(p, k, pp, filter_apply_order='topk_first')
# after
sampled = top_k_top_p_sampling_from_probs(p, k, pp, filter_apply_order='top_k_first')
Defensive patterns

Strategy: validation

Validate before calling

if filter_apply_order not in ('top_k_first','joint'): raise ValueError(f'bad order {filter_apply_order!r}')

Type guard

def is_valid_order(s): return s in ('top_k_first','joint')

Prevention

When it happens

Trigger: Passing filter_apply_order='topk_first', 'top-k-first', 'both', 'sequential', None, or any string other than the two supported literals.

Common situations: Copy-pasted configs from other sampling APIs, renamed arguments after a version change, or dynamic construction of the order string.

Related errors


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