{"record":{"id":"101dff76a2dfe2e3","repo":"Lightning-AI/pytorch-lightning","slug":"tensorrt-only-supports-cuda-devices-the-current-d","errorCode":null,"errorMessage":"TensorRT only supports CUDA devices. The current device is {self.device}. Please set the `default_device` argument to a CUDA device.","messagePattern":"TensorRT only supports CUDA devices\\. The current device is (.+?)\\. Please set the `default_device` argument to a CUDA device\\.","errorType":"exception","errorClass":"MisconfigurationException","httpStatus":null,"severity":"error","filePath":"src/lightning/pytorch/core/module.py","lineNumber":1658,"sourceCode":"            input_sample = torch.randn(1, 64)\n            exported_program = model.to_tensorrt(\n                file_path=\"export.ep\",\n                inputs=input_sample,\n            )\n\n        \"\"\"\n        if not _TORCH_TRT_AVAILABLE:\n            raise ModuleNotFoundError(\n                f\"`{type(self).__name__}.to_tensorrt` requires `torch_tensorrt` to be installed. \"\n            )\n\n        mode = self.training\n        device = self.device\n        if self.device.type != \"cuda\":\n            default_device = torch.device(default_device) if isinstance(default_device, str) else default_device\n\n            if not torch.cuda.is_available() or default_device.type != \"cuda\":\n                raise MisconfigurationException(\n                    f\"TensorRT only supports CUDA devices. The current device is {self.device}.\"\n                    f\" Please set the `default_device` argument to a CUDA device.\"\n                )\n\n            self.to(default_device)\n\n        if input_sample is None:\n            if self.example_input_array is None:\n                raise ValueError(\n                    \"Could not export to TensorRT since neither `input_sample` nor\"\n                    \" `model.example_input_array` attribute is set.\"\n                )\n            input_sample = self.example_input_array\n\n        import torch_tensorrt\n\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)","sourceCodeStart":1640,"sourceCodeEnd":1676,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/pytorch/core/module.py#L1640-L1676","documentation":"TensorRT engines can only be built for CUDA devices. If the model currently sits on a non-CUDA device (e.g. cpu) and either CUDA is unavailable or the provided default_device is not a CUDA device, Lightning raises MisconfigurationException telling you to set `default_device` to a CUDA device.","triggerScenarios":"Calling model.to_tensorrt() with the model on CPU and default_device unset/\"cpu\", or on a machine without CUDA.","commonSituations":"Running the export script on a CPU-only dev box or CI node, or forgetting to move the model before export.","solutions":["Run on a GPU machine and pass default_device=\"cuda:0\" (or move the model to cuda first)","Verify torch.cuda.is_available() before attempting export","If no GPU is available, use to_onnx() instead and compile with TensorRT offline"],"exampleFix":"# before\nmodel.to_tensorrt(\"model.ep\", input_sample=x)  # model on cpu\n# after\nmodel.to_tensorrt(\"model.ep\", input_sample=x, default_device=\"cuda:0\")","handlingStrategy":"validation","validationCode":"import torch\nif not torch.cuda.is_available():\n    raise RuntimeError(\"TensorRT export requires CUDA\")\nmodel.to_tensorrt(path, input_sample=x, default_device=\"cuda:0\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Gate TRT export behind torch.cuda.is_available()","Keep a CPU-safe ONNX fallback branch in export scripts"],"tags":["tensorrt","cuda","device-mismatch","lightning"],"backgroundTag":"cuda-device-unavailable","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}