vllm-project/vllm · error · ValueError
Argument {k} not found in the forward method of {cls}
Error message
Argument {k} not found in the forward method of {cls} What it means
After dynamic dimensions are resolved (inferred or user-supplied), the decorator validates that every key of dynamic_arg_dims is an actual parameter of the decorated class's forward method. A key that does not appear in inspect.signature(cls.forward).parameters is a configuration mistake and raises ValueError naming the bad argument.
Source
Thrown at vllm/compilation/decorators.py:235
IntermediateTensors | None,
]:
inferred_dynamic_arg_dims[k] = 0
logger.debug(
("Inferred dynamic dimensions for forward method of %s: %s"),
cls,
list(inferred_dynamic_arg_dims.keys()),
)
if len(inferred_dynamic_arg_dims) == 0:
raise ValueError(
"No dynamic dimensions found in the forward method of "
f"{cls}. Please provide dynamic_arg_dims explicitly."
)
for k in inferred_dynamic_arg_dims:
if k not in sig.parameters:
raise ValueError(
f"Argument {k} not found in the forward method of {cls}"
)
return _support_torch_compile(
cls,
inferred_dynamic_arg_dims,
mark_unbacked_dims,
enable_if,
is_encoder,
)
if cls is not None:
# use `support_torch_compile` as a decorator without arguments
assert isinstance(cls, type)
return cls_decorator_helper(cls)
return cls_decorator_helper
View on GitHub (pinned to c794754062)
Solutions
- Align the dynamic_arg_dims keys with the exact parameter names in forward.
- If the argument is forwarded via **kwargs, hoist it into an explicit named parameter.
- Re-check after refactors that rename forward arguments.
Example fix
# before
@support_torch_compile(dynamic_arg_dims={"input_ids": 0})
class L(nn.Module):
def forward(self, hidden_states): ...
# after
@support_torch_compile(dynamic_arg_dims={"hidden_states": 0})
class L(nn.Module):
def forward(self, hidden_states): ... Defensive patterns
Strategy: validation
Validate before calling
import inspect
def validate_dynamic_arg_dims(cls, dims: dict) -> list[str]:
params = set(inspect.signature(cls.forward).parameters)
return [k for k in dims if k not in params] # must be empty
assert not validate_dynamic_arg_dims(MyLayer, {'hidden_states': 0}) Prevention
- Keep dynamic_arg_dims keys in sync with forward parameter names
- Add a test asserting decorator keys match the signature
- Avoid **kwargs-only forwards for compiled modules
When it happens
Trigger: Passing dynamic_arg_dims={'input_ids': 0} to @support_torch_compile when forward has no parameter named input_ids (e.g. it is called hidden_states or embedded in **kwargs).
Common situations: Renaming forward parameters without updating dynamic_arg_dims; copying a decorator config from another model with a different signature; parameter swallowed by **kwargs so it never appears in the signature.
Related errors
- No dynamic dimensions found in the forward method of {cls}.
- decorated class should have a forward method.
- {init} received a positional argument of type {arg_type}, bu
- shape_id='{shape_id}' requires PyTorch >= 2.11.0
- Unsupported dynamic dimensions {dims} for argument {k} with
AI-assisted analysis of vllm-project/vllm@c794754062 (2026-08-14).
Data as JSON: /api/errors/8511885505257aaa.
Report an issue: GitHub.