sgl-project/sglang · error · Exception
Given arguments mismatch the SGL function signature
Error message
Given arguments mismatch the SGL function signature
What it means
Raised by run_batch in sglang's frontend IR when the number of per-program argument dicts that pass signature validation does not equal num_programs. Each program in the batch must receive a compatible number of positional/keyword arguments for the SGL function (between len(arg_names)-len(arg_defaults) and len(arg_names)), so any single mismatched entry drops the count and triggers this exception.
Source
Thrown at python/sglang/lang/ir.py:273
stop_regex = []
assert isinstance(batch_kwargs, (list, tuple))
if len(batch_kwargs) == 0:
return []
if not isinstance(batch_kwargs[0], dict):
num_programs = len(batch_kwargs)
# change the list of argument values to dict of arg_name -> arg_value
batch_kwargs = [
{self.arg_names[i]: v for i, v in enumerate(arg_values)}
for arg_values in batch_kwargs
if isinstance(arg_values, (list, tuple))
and len(self.arg_names) - len(self.arg_defaults)
<= len(arg_values)
<= len(self.arg_names)
]
# Ensure to raise an exception if the number of arguments mismatch
if len(batch_kwargs) != num_programs:
raise Exception("Given arguments mismatch the SGL function signature")
default_sampling_para = SglSamplingParams(
max_new_tokens=max_new_tokens,
n=n,
stop=stop,
stop_token_ids=stop_token_ids,
stop_regex=stop_regex,
temperature=temperature,
top_p=top_p,
top_k=top_k,
min_p=min_p,
frequency_penalty=frequency_penalty,
presence_penalty=presence_penalty,
ignore_eos=ignore_eos,
return_logprob=return_logprob,
logprob_start_len=logprob_start_len,
top_logprobs_num=top_logprobs_num,
return_text_in_logprobs=return_text_in_logprobs,View on GitHub (pinned to 0132848349)
Solutions
- Check the SGL function signature (arg_names and arg_defaults) and make every dict in batch_kwargs supply all required arguments
- Log len(batch_kwargs) vs num_programs and each dict's keys to find the offending entry
- If some programs intentionally have fewer args, give the missing parameters defaults in the function definition
Example fix
# before
programs = [{"x": 1}, {"x": 2, "y": 3}] # second dict has extra arg
run_batch(programs)
# after
programs = [{"x": 1, "y": 0}, {"x": 2, "y": 3}]
run_batch(programs) Defensive patterns
Strategy: validation
Validate before calling
required = set(fn.arg_names) - set(fn.arg_defaults)
for i, kw in enumerate(batch_kwargs):
missing = required - set(kw)
extra = set(kw) - set(fn.arg_names)
assert not missing and not extra, (i, missing, extra)
run_batch(batch_kwargs) Prevention
- Keep a single source of truth for the function signature and generate batch dicts from it
- Add a preflight assert on len(batch_kwargs) == num_programs in tests
When it happens
Trigger: Calling sgl.run_batch (or run_batch on a traced SGL function) with a list of argument dicts where at least one dict has too few arguments (fewer than arg_names minus defaults) or more arguments than the function signature declares; batch size of valid kwargs then != num_programs.
Common situations: Passing heterogeneous batches where some entries miss required parameters, forgetting that parameters with defaults are optional but others are not, or refactoring an SGL function signature without updating all batch argument dicts.
Related errors
- The input_ids {seq} contains values greater than the vocab s
- borrow_torch_tensors requires MPS tensors, got {devices}
- Unknown serve backend {name!r}. Available values: {available
- Multiple distributions register serve backend {name!r}: {pro
- Failed to load serve backend {name!r} from {self._entry_poin
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/a9a1112dc25144c9.
Report an issue: GitHub.