sgl-project/sglang · error · TypeError
rank_consensus() got unexpected keyword argument(s): {list(k
Error message
rank_consensus() got unexpected keyword argument(s): {list(kwargs)} What it means
The rank_consensus decorator factory accepts only positional usage — rank_consensus(func) — and no keyword arguments; any kwargs trigger this TypeError. Configuration is done via the decorator's own named parameters (same_params, same_results), not via call-time kwargs.
Source
Thrown at python/sglang/srt/utils/rank_consensus_checker.py:77
def foo():
return 1
* Assert for part of the results are same.
@rank_consensus(same_results = ["result.some_field"]
def foo():
return SomeObject()
@rank_consensus(same_results = ["result.field", "len(result.field2)"]
def foo():
return SomeObject()
* Assert the function is called by all ranks and all parameters and results are the same.
@rank_consensus(same_params = True, same_results = True)
def foo():
return 1
"""
if kwargs:
raise TypeError(
f"rank_consensus() got unexpected keyword argument(s): " f"{list(kwargs)}"
)
params_selector = _normalize_selector(same_params, "same_params")
results_selector = _normalize_selector(same_results, "same_results")
def decorator(func: Callable) -> Callable:
# This decorator function called at import time. So it should be zero runtime overhead
# when the consensus checker is disabled.
if not envs.SGLANG_ENABLE_RANK_CONSENSUS_CHECKER.get():
return func
# Unwrap static/class-method descriptors so we always operate on the
# raw function. We remember the descriptor type so we can re-wrap the
# result and the class-body descriptor protocol keeps working.
if isinstance(func, (classmethod, staticmethod)):
raw_func = func.__func__
descriptor_type = type(func)View on GitHub (pinned to 0132848349)
Solutions
- Use only the supported parameters: @rank_consensus(same_params=..., same_results=...)
- If decorating directly without options, write @rank_consensus (no parens)
- Check the decorator signature in rank_consensus_checker.py for supported knobs
Example fix
# before @rank_consensus(mode='strict') def check(): ... # after @rank_consensus(same_params=True, same_results=True) def check(): ...
Defensive patterns
Strategy: type-guard
Validate before calling
import inspect
allowed = set(inspect.signature(rank_consensus).parameters) - {'kwargs'}
assert set(kwargs) <= set() Type guard
null
Try / catch
try:
rank_consensus(fn, **opts)
except TypeError as e:
if 'unexpected keyword' in str(e):
rank_consensus(fn) # decorate without options Prevention
- Read the decorator signature before passing options
- Only use same_params/same_results as decorator-time named args
- Pin decorator usage patterns in a shared internal helper
When it happens
Trigger: Writing @rank_consensus(check=True) or calling rank_consensus(fn, foo=1) — i.e. passing unexpected keyword arguments to the decorator factory itself.
Common situations: Developers assuming the checker takes options at decoration time like other decorators, or copy-pasting from a different consensus helper's API.
Related errors
- {name} must be True / False / str / list[str], got {value!r}
- cannot mix lambda extractor with static kwargs
- must provide either a lambda or static kwargs
- NCCL only supports CUDA, ROCm and MUSA backends.
- Multi-node weight cache daemons (nnodes > 1) require --dist-
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/385b109bc10f7f48.
Report an issue: GitHub.