vllm-project/vllm · error · TypeError
{init} received a positional argument of type {arg_type}, bu
Error message
{init} received a positional argument of type {arg_type}, but no parameter of that type was found in the method signature. Please either annotate {init} or pass it as a keyword argument. What it means
The decorator patches the module's __init__ to inject vllm_config/prefix. As a safety check it walks the positional *args against the old __init__'s parameter annotations: if an argument's runtime type does not match the annotated type of the parameter in the same position, it raises TypeError suggesting you annotate __init__ or pass the argument by keyword. This guards against silently binding vllm_config/prefix into the wrong slots.
Source
Thrown at vllm/compilation/decorators.py:374
vllm_config: VllmConfig | None = None,
prefix: str = "",
**kwargs: Any,
) -> None:
if vllm_config is None:
vllm_config = get_current_vllm_config()
# NOTE: to support multimodal models (such as encoder),
# we may not have vllm_config so we may need to patch it
sig = inspect.signature(old_init)
# Check that any positional arguments match the old_init method signature
annotations = [p.annotation for p in sig.parameters.values()]
for arg, annotation in zip(args, annotations):
if annotation is inspect._empty:
continue
if not isinstance(arg, annotation):
init = f"'{type(self).__name__}.__init__'"
arg_type = f"'{type(arg).__name__}'"
raise TypeError(
f"{init} received a positional argument of type {arg_type}, "
"but no parameter of that type was found in the method signature. "
f"Please either annotate {init} or pass it as a keyword argument."
)
if "vllm_config" in sig.parameters:
kwargs["vllm_config"] = vllm_config
if "prefix" in sig.parameters:
kwargs["prefix"] = prefix
old_init(self, *args, **kwargs)
self.vllm_config = vllm_config
self.compilation_config = self.vllm_config.compilation_config
enable_compile = enable_if is None or enable_if(vllm_config)
# for CompilationMode.STOCK_TORCH_COMPILE , the upper level model runner
# will handle the compilation, so we don't need to do anything here.
self.do_not_compile = (
self.compilation_config.mode
in [CompilationMode.NONE, CompilationMode.STOCK_TORCH_COMPILE]View on GitHub (pinned to c794754062)
Solutions
- Pass arguments as keyword arguments when constructing the module: MyModule(config=..., prefix=...).
- Add accurate type annotations to every parameter of the decorated class's __init__.
- Verify the positional order at the call site matches the annotated signature exactly.
Example fix
# before module = MyDecoderLayer(vllm_config, "model.layers.0") # TypeError if annotations mismatch # after module = MyDecoderLayer(vllm_config=vllm_config, prefix="model.layers.0")
Defensive patterns
Strategy: type-guard
Validate before calling
import inspect
def bind_positional_safely(cls, args: tuple) -> None:
params = list(inspect.signature(cls.__init__).parameters.values())[1:]
for arg, p in zip(args, params):
if p.annotation is not inspect._empty and not isinstance(arg, p.annotation):
raise TypeError(f'{arg!r} does not match annotation {p.annotation}; pass by keyword') Try / catch
try:
layer = MyLayer(cfg, 'model.layers.0')
except TypeError as e:
if 'pass it as a keyword argument' in str(e):
layer = MyLayer(vllm_config=cfg, prefix='model.layers.0')
else:
raise Prevention
- Construct vLLM modules with keyword arguments
- Fully annotate __init__ of decorated classes
- Lock argument order with tests
When it happens
Trigger: Instantiating a @support_torch_compile-decorated model with positional arguments whose order or type does not match annotated parameters — e.g. MyModule(config, 'prefix') where the second parameter is annotated torch.Tensor but receives a str.
Common situations: Custom model __init__ signatures reordered during refactoring while call sites kept the old positional order; __init__ parameters partially annotated; encoder/multimodal models whose vllm_config is optional so callers pass fewer positional args.
Related errors
- decorated class should have a forward method.
- No dynamic dimensions found in the forward method of {cls}.
- Argument {k} not found in the forward method of {cls}
- vLLM failed to compile the model. The most likely reason for
- shape_id='{shape_id}' requires PyTorch >= 2.11.0
AI-assisted analysis of vllm-project/vllm@c794754062 (2026-08-14).
Data as JSON: /api/errors/2881a7e42821e840.
Report an issue: GitHub.