{"record":{"id":"2881a7e42821e840","repo":"vllm-project/vllm","slug":"init-received-a-positional-argument-of-type-arg","errorCode":null,"errorMessage":"{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.","messagePattern":"(.+?) received a positional argument of type (.+?), but no parameter of that type was found in the method signature\\. Please either annotate (.+?) or pass it as a keyword argument\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"vllm/compilation/decorators.py","lineNumber":374,"sourceCode":"        vllm_config: VllmConfig | None = None,\n        prefix: str = \"\",\n        **kwargs: Any,\n    ) -> None:\n        if vllm_config is None:\n            vllm_config = get_current_vllm_config()\n\n        # NOTE: to support multimodal models (such as encoder),\n        # we may not have vllm_config so we may need to patch it\n        sig = inspect.signature(old_init)\n        # Check that any positional arguments match the old_init method signature\n        annotations = [p.annotation for p in sig.parameters.values()]\n        for arg, annotation in zip(args, annotations):\n            if annotation is inspect._empty:\n                continue\n            if not isinstance(arg, annotation):\n                init = f\"'{type(self).__name__}.__init__'\"\n                arg_type = f\"'{type(arg).__name__}'\"\n                raise TypeError(\n                    f\"{init} received a positional argument of type {arg_type}, \"\n                    \"but no parameter of that type was found in the method signature. \"\n                    f\"Please either annotate {init} or pass it as a keyword argument.\"\n                )\n        if \"vllm_config\" in sig.parameters:\n            kwargs[\"vllm_config\"] = vllm_config\n        if \"prefix\" in sig.parameters:\n            kwargs[\"prefix\"] = prefix\n        old_init(self, *args, **kwargs)\n\n        self.vllm_config = vllm_config\n        self.compilation_config = self.vllm_config.compilation_config\n        enable_compile = enable_if is None or enable_if(vllm_config)\n        # for CompilationMode.STOCK_TORCH_COMPILE , the upper level model runner\n        # will handle the compilation, so we don't need to do anything here.\n        self.do_not_compile = (\n            self.compilation_config.mode\n            in [CompilationMode.NONE, CompilationMode.STOCK_TORCH_COMPILE]","sourceCodeStart":356,"sourceCodeEnd":392,"githubUrl":"https://github.com/vllm-project/vllm/blob/c794754062d49a8fdb63ab3c5215b488b865030c/vllm/compilation/decorators.py#L356-L392","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before\nmodule = MyDecoderLayer(vllm_config, \"model.layers.0\")  # TypeError if annotations mismatch\n# after\nmodule = MyDecoderLayer(vllm_config=vllm_config, prefix=\"model.layers.0\")","handlingStrategy":"type-guard","validationCode":"import inspect\n\ndef bind_positional_safely(cls, args: tuple) -> None:\n    params = list(inspect.signature(cls.__init__).parameters.values())[1:]\n    for arg, p in zip(args, params):\n        if p.annotation is not inspect._empty and not isinstance(arg, p.annotation):\n            raise TypeError(f'{arg!r} does not match annotation {p.annotation}; pass by keyword')","typeGuard":null,"tryCatchPattern":"try:\n    layer = MyLayer(cfg, 'model.layers.0')\nexcept TypeError as e:\n    if 'pass it as a keyword argument' in str(e):\n        layer = MyLayer(vllm_config=cfg, prefix='model.layers.0')\n    else:\n        raise","preventionTips":["Construct vLLM modules with keyword arguments","Fully annotate __init__ of decorated classes","Lock argument order with tests"],"tags":["torch-compile","decorators","type-checking","vllm"],"backgroundTag":null,"analyzedSha":"c794754062d49a8fdb63ab3c5215b488b865030c","analyzedAt":"2026-08-14T21:17:39.825Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}