{"record":{"id":"03e0123919d7e691","repo":"Lightning-AI/pytorch-lightning","slug":"tensorrt-with-ir-mode-ts-only-supports-output-fo","errorCode":null,"errorMessage":"TensorRT with IR mode 'ts' only supports output format 'torchscript'. The current output format is {output_format}.","messagePattern":"TensorRT with IR mode 'ts' only supports output format 'torchscript'\\. The current output format is (.+?)\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/lightning/pytorch/core/module.py","lineNumber":1692,"sourceCode":"\n        input_sample = copy.deepcopy((input_sample,) if isinstance(input_sample, torch.Tensor) else input_sample)\n        input_sample = self._on_before_batch_transfer(input_sample)\n        input_sample = self._apply_batch_transfer_handler(input_sample)\n\n        with _jit_is_scripting() if ir == \"ts\" else nullcontext():\n            trt_obj = torch_tensorrt.compile(\n                module=self.eval(),\n                ir=ir,\n                inputs=input_sample,\n                **compile_kwargs,\n            )\n        self.train(mode)\n        self.to(device)\n\n        if file_path is not None:\n            if ir == \"ts\":\n                if output_format != \"torchscript\":\n                    raise ValueError(\n                        \"TensorRT with IR mode 'ts' only supports output format 'torchscript'.\"\n                        f\" The current output format is {output_format}.\"\n                    )\n                assert isinstance(trt_obj, (torch.jit.ScriptModule, torch.jit.ScriptFunction)), (\n                    f\"Expected TensorRT object to be a ScriptModule, but got {type(trt_obj)}.\"\n                )\n                # Because of https://github.com/pytorch/TensorRT/issues/3775,\n                # we'll need to take special care for the ScriptModule\n                torch.jit.save(trt_obj, file_path)\n            else:\n                torch_tensorrt.save(\n                    trt_obj,\n                    file_path,\n                    inputs=input_sample,\n                    output_format=output_format,\n                    retrace=retrace,\n                )\n        return trt_obj","sourceCodeStart":1674,"sourceCodeEnd":1710,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/pytorch/core/module.py#L1674-L1710","documentation":"When to_tensorrt uses ir='ts' (TorchScript IR), the only savable artifact is a TorchScript file, so output_format must be 'torchscript'. Requesting another output_format (e.g. 'engine' or 'onnx') with ir='ts' raises ValueError at save time.","triggerScenarios":"Calling model.to_tensorrt(path, ir=\"ts\", output_format=\"engine\") or any format other than \"torchscript\" while ir=\"ts\" and file_path is set.","commonSituations":"Mixing parameters copied from an ir='dlgraph' example while keeping the default ir='ts', or assuming any ir/format combination is valid.","solutions":["Use ir=\"ts\" with output_format=\"torchscript\" (the default)","Or switch ir to a mode that supports your desired output format (e.g. ir=\"dlgraph\" for engine/onnx export)"],"exampleFix":"# before\nmodel.to_tensorrt(\"model.ep\", ir=\"ts\", output_format=\"engine\")\n# after\nmodel.to_tensorrt(\"model.ts\", ir=\"ts\", output_format=\"torchscript\")","handlingStrategy":"type-guard","validationCode":"if ir == \"ts\":\n    assert output_format == \"torchscript\"\nmodel.to_tensorrt(path, ir=ir, output_format=output_format)","typeGuard":"def valid_trt_combo(ir: str, fmt: str) -> bool:\n    return ir != \"ts\" or fmt == \"torchscript\"","tryCatchPattern":null,"preventionTips":["Keep ir/output_format pairs in a validated config table","Default output_format when ir='ts'"],"tags":["tensorrt","invalid-combination","torchscript","lightning"],"backgroundTag":"invalid-enum-value","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}