sgl-project/sglang · error · ValueError
must provide either a lambda or static kwargs
Error message
must provide either a lambda or static kwargs
What it means
The dumper.ctx decorator requires exactly one context source: a lambda extractor or static keyword arguments. If neither is supplied, the wrapper would have no context to register, so the decorator fails fast at decoration time rather than silently doing nothing.
Source
Thrown at python/sglang/srt/debug_utils/dumper.py:377
def ctx(
self,
_extractor: Optional[Callable[..., dict]] = None,
**static_ctx: Any,
) -> Callable:
"""Decorator that sets context before calling the wrapped function and clears it after.
Two forms:
@dumper.ctx(lambda self: dict(layer_id=self.layer_id))
def forward(self, x): ...
@dumper.ctx(phase="decode")
def decode_step(self, x): ...
"""
if _extractor is not None and static_ctx:
raise ValueError("cannot mix lambda extractor with static kwargs")
if _extractor is None and not static_ctx:
raise ValueError("must provide either a lambda or static kwargs")
def decorator(fn: Callable) -> Callable:
@functools.wraps(fn)
def wrapper(*args: Any, **kwargs: Any) -> Any:
ctx_dict: dict = _extractor(args[0]) if _extractor else static_ctx
self.set_ctx(**ctx_dict)
try:
return fn(*args, **kwargs)
finally:
self.set_ctx(**{k: None for k in ctx_dict})
return wrapper
return decorator
def apply_source_patches(self) -> None:
"""Apply source patches from DUMPER_SOURCE_PATCHER_CONFIG if set.
View on GitHub (pinned to 0132848349)
Solutions
- Pass a lambda extractor: @dumper.ctx(lambda self: {...})
- Or pass at least one static kwarg: @dumper.ctx(phase='decode')
Example fix
# before @dumper.ctx def step(self, x): ... # after @dumper.ctx(phase="decode") def step(self, x): ...
Defensive patterns
Strategy: validation
Validate before calling
assert extractor is not None or bool(static_kwargs), "ctx needs a lambda or static kwargs"
Prevention
- Lint for bare @dumper.ctx with no arguments
- Keep decorator usage examples next to the decorated class
When it happens
Trigger: @dumper.ctx() with no arguments decorating a method; calling dumper.ctx with no positional callable and no kwargs.
Common situations: Decorating a method intending to use a default context, or forgetting to pass the extractor lambda during a refactor.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- MiniMax-H3 NVFP4 metadata requires checkpoint files
- cannot mix lambda extractor with static kwargs
- rank_consensus() got unexpected keyword argument(s): {list(k
- Missing previous frame for delta payload
- Usage: sglang serve --model-path <model-name-or-path> [addit
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/c76a4334c0b2e504.
Report an issue: GitHub.