{"record":{"id":"8914480d57db33ba","repo":"Lightning-AI/pytorch-lightning","slug":"the-method-parameter-only-supports-script-or","errorCode":null,"errorMessage":"The 'method' parameter only supports 'script' or 'trace', but value given was: {method}","messagePattern":"The 'method' parameter only supports 'script' or 'trace', but value given was: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/lightning/pytorch/core/module.py","lineNumber":1595,"sourceCode":"            if example_inputs is None:\n                if self.example_input_array is None:\n                    raise ValueError(\n                        \"Choosing method=`trace` requires either `example_inputs`\"\n                        \" or `model.example_input_array` to be defined.\"\n                    )\n                example_inputs = self.example_input_array\n\n            if kwargs.get(\"check_inputs\") is not None:\n                kwargs[\"check_inputs\"] = self._on_before_batch_transfer(kwargs[\"check_inputs\"])\n                kwargs[\"check_inputs\"] = self._apply_batch_transfer_handler(kwargs[\"check_inputs\"])\n\n            # automatically send example inputs to the right device and use trace\n            example_inputs = self._on_before_batch_transfer(example_inputs)\n            example_inputs = self._apply_batch_transfer_handler(example_inputs)\n            with _jit_is_scripting():\n                torchscript_module = torch.jit.trace(func=self.eval(), example_inputs=example_inputs, **kwargs)\n        else:\n            raise ValueError(f\"The 'method' parameter only supports 'script' or 'trace', but value given was: {method}\")\n\n        self.train(mode)\n\n        if file_path is not None:\n            fs = get_filesystem(file_path)\n            with fs.open(file_path, \"wb\") as f:\n                torch.jit.save(torchscript_module, f)\n\n        return torchscript_module\n\n    @torch.no_grad()\n    def to_tensorrt(\n        self,\n        file_path: Optional[Union[str, Path, BytesIO]] = None,\n        input_sample: Optional[Any] = None,\n        ir: Literal[\"default\", \"dynamo\", \"ts\"] = \"default\",\n        output_format: Literal[\"exported_program\", \"torchscript\"] = \"exported_program\",\n        retrace: bool = False,","sourceCodeStart":1577,"sourceCodeEnd":1613,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/pytorch/core/module.py#L1577-L1613","documentation":"to_torchscript accepts only method='script' or method='trace'. Any other string (typos, 'jit', 'Script', etc.) falls through the if/elif chain and raises ValueError naming the bad value.","triggerScenarios":"Calling model.to_torchscript(method=\"jit\") or any string other than 'script'/'trace'.","commonSituations":"Copy-paste from other tooling that uses different export method names, or passing a variable that defaulted to an unexpected string.","solutions":["Use method=\"script\" or method=\"trace\"","If the value comes from a config, validate/normalize it before calling to_torchscript"],"exampleFix":"# before\nmodel.to_torchscript(method=\"jit\")\n# after\nmodel.to_torchscript(method=\"trace\", example_inputs=x)","handlingStrategy":"type-guard","validationCode":"assert method in (\"script\", \"trace\"), f\"bad method {method}\"","typeGuard":"def is_valid_ts_method(m: str) -> bool:\n    return m in {\"script\", \"trace\"}","tryCatchPattern":null,"preventionTips":["Drive method from a validated config enum","Unit-test the export path with both methods"],"tags":["torchscript","invalid-argument","lightning"],"backgroundTag":"invalid-enum-value","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}