{"record":{"id":"7babe050cd7898c6","repo":"keras-team/keras","slug":"to-export-to-litert-with-the-pytorch-backend-you","errorCode":null,"errorMessage":"To export to LiteRT with the PyTorch backend, you must install the `litert-torch` package. Install via: pip install litert-torch","messagePattern":"To export to LiteRT with the PyTorch backend, you must install the `litert-torch` package\\. Install via: pip install litert-torch","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"keras/src/export/litert.py","lineNumber":208,"sourceCode":"\n\ndef export_litert_via_torch(\n    model, filepath, input_signature=None, verbose=None, **kwargs\n):\n    \"\"\"Export Keras model to LiteRT via PyTorch backend.\"\"\"\n    from keras.src.backend.torch.core import device_scope\n    from keras.src.backend.torch.core import get_device\n\n    device = get_device()\n\n    # litert_torch internally imports JAX and unconditionally enables\n    # jax_enable_x64, which breaks dtype-sensitive tests elsewhere.\n    # We preserve the original setting and restore it after conversion.\n    with _preserve_jax_x64_state():\n        try:\n            import litert_torch\n        except ImportError:\n            raise ImportError(\n                \"To export to LiteRT with the PyTorch backend, \"\n                \"you must install the `litert-torch` package. \"\n                \"Install via: pip install litert-torch\"\n            )\n\n        if device != \"cpu\":\n            for v in model.variables:\n                v.value.data = v.value.data.to(\"cpu\")\n\n        try:\n            with device_scope(\"cpu\"):\n                if input_signature is None:\n                    input_signature = get_input_signature(model)\n\n                sample_inputs = tree.map_structure(\n                    lambda x: convert_spec_to_tensor(x, replace_none_number=1),\n                    input_signature,\n                )","sourceCodeStart":190,"sourceCodeEnd":226,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/export/litert.py#L190-L226","documentation":"Error \"To export to LiteRT with the PyTorch backend, you must install the `litert-torch` package. Install via: pip install litert-torch\" thrown in keras-team/keras.","triggerScenarios":"Thrown at keras/src/export/litert.py:208 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}