{"record":{"id":"8511885505257aaa","repo":"vllm-project/vllm","slug":"argument-k-not-found-in-the-forward-method-of-c","errorCode":null,"errorMessage":"Argument {k} not found in the forward method of {cls}","messagePattern":"Argument (.+?) not found in the forward method of (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"vllm/compilation/decorators.py","lineNumber":235,"sourceCode":"                    IntermediateTensors | None,\n                ]:\n                    inferred_dynamic_arg_dims[k] = 0\n\n            logger.debug(\n                (\"Inferred dynamic dimensions for forward method of %s: %s\"),\n                cls,\n                list(inferred_dynamic_arg_dims.keys()),\n            )\n\n        if len(inferred_dynamic_arg_dims) == 0:\n            raise ValueError(\n                \"No dynamic dimensions found in the forward method of \"\n                f\"{cls}. Please provide dynamic_arg_dims explicitly.\"\n            )\n\n        for k in inferred_dynamic_arg_dims:\n            if k not in sig.parameters:\n                raise ValueError(\n                    f\"Argument {k} not found in the forward method of {cls}\"\n                )\n\n        return _support_torch_compile(\n            cls,\n            inferred_dynamic_arg_dims,\n            mark_unbacked_dims,\n            enable_if,\n            is_encoder,\n        )\n\n    if cls is not None:\n        # use `support_torch_compile` as a decorator without arguments\n        assert isinstance(cls, type)\n        return cls_decorator_helper(cls)\n\n    return cls_decorator_helper\n","sourceCodeStart":217,"sourceCodeEnd":253,"githubUrl":"https://github.com/vllm-project/vllm/blob/c794754062d49a8fdb63ab3c5215b488b865030c/vllm/compilation/decorators.py#L217-L253","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"# before\n@support_torch_compile(dynamic_arg_dims={\"input_ids\": 0})\nclass L(nn.Module):\n    def forward(self, hidden_states): ...\n# after\n@support_torch_compile(dynamic_arg_dims={\"hidden_states\": 0})\nclass L(nn.Module):\n    def forward(self, hidden_states): ...","handlingStrategy":"validation","validationCode":"import inspect\n\ndef validate_dynamic_arg_dims(cls, dims: dict) -> list[str]:\n    params = set(inspect.signature(cls.forward).parameters)\n    return [k for k in dims if k not in params]  # must be empty\nassert not validate_dynamic_arg_dims(MyLayer, {'hidden_states': 0})","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["torch-compile","decorators","dynamic-shapes","vllm"],"backgroundTag":null,"analyzedSha":"c794754062d49a8fdb63ab3c5215b488b865030c","analyzedAt":"2026-08-14T21:17:39.825Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}