{"record":{"id":"1374a957e4656db2","repo":"keras-team/keras","slug":"failed-to-convert-pytorch-model-to-litert-common","errorCode":null,"errorMessage":"Failed to convert PyTorch model to LiteRT. Common causes: unsupported operations, dynamic shapes, or complex control flow. Original error: {e}","messagePattern":"Failed to convert PyTorch model to LiteRT\\. Common causes: unsupported operations, dynamic shapes, or complex control flow\\. Original error: (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"keras/src/export/litert.py","lineNumber":246,"sourceCode":"\n                # Although Keras models manage training mode via the\n                # `training` argument to `call()`, `litert_torch.convert`\n                # checks `module.training` and warns when it is `True`.\n                # Calling `eval()` silences that warning and ensures any\n                # PyTorch-native submodules are in inference mode.\n                model.eval()\n\n                litert_torch_kwargs = _prepare_litert_kwargs(\n                    kwargs, litert_torch\n                )\n\n                with _silence_output(verbose is False):\n                    try:\n                        edge_model = litert_torch.convert(\n                            model, sample_inputs, **litert_torch_kwargs\n                        )\n                    except Exception as e:\n                        raise RuntimeError(\n                            \"Failed to convert PyTorch model to LiteRT. \"\n                            \"Common causes: unsupported operations, \"\n                            \"dynamic shapes, or complex control flow. \"\n                            f\"Original error: {e}\"\n                        ) from e\n\n                    edge_model.export(filepath)\n        finally:\n            if device != \"cpu\":\n                for v in model.variables:\n                    v.value.data = v.value.data.to(device)\n\n    if verbose is not False:\n        io_utils.print_msg(f\"Saved artifact at '{filepath}'.\")\n\n    return filepath\n\n","sourceCodeStart":228,"sourceCodeEnd":264,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/export/litert.py#L228-L264","documentation":"Raised when the underlying litert_torch.convert() call raises while translating the Keras-wrapped PyTorch module into a LiteRT/FlatBuffer artifact. The original exception is chained as {e}, so this is a wrapper error: the real cause is the PyTorch-to-TFLite converter rejecting something in the model (unsupported ops, dynamic shapes, control flow).","triggerScenarios":"Thrown at keras/src/export/litert.py:246 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect the chained original error to identify the exact op or shape that failed conversion","Rebuild or refactor the model to avoid operations unsupported by the AI Edge Torch converter (e.g., exotic custom layers, data-dependent control flow)","Make input shapes static (fixed batch/sequence dimensions) before exporting","Replace dynamic control flow (loops/conditionals on tensor values) with tensor operations","Export to an intermediate format (e.g., ONNX or saved PyTorch state) and use a TFLite conversion path that supports the ops"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}