{"id":9730,"library":"executorch","title":"ExecuTorch","description":"ExecuTorch is an on-device AI framework that extends PyTorch to mobile, embedded, and edge devices. It enables efficient inference by compiling PyTorch models into a compact, optimized format (.pte file) suitable for resource-constrained environments. The current version, 1.2.0, expands model and hardware support, including real-time speech and improved embedded targets. Releases are frequent, typically every 1-2 months, aligning with PyTorch releases.","status":"active","version":"1.2.0","language":"en","source_language":"en","source_url":"https://github.com/pytorch/executorch","tags":["pytorch","on-device-ai","edge-ai","embedded","machine-learning","inference","mobile-ai"],"install":[{"cmd":"pip install executorch","lang":"bash","label":"Base installation"},{"cmd":"pip install executorch[xnnpack] # Or [coreml], [qnn], etc.","lang":"bash","label":"Installation with specific backend delegates"}],"dependencies":[{"reason":"Core PyTorch library, ExecuTorch is built on top of it for model export.","package":"torch","optional":false},{"reason":"Required for certain model types, especially LLMs. Was explicitly added as a dependency in v1.0.1.","package":"pytorch-tokenizers","optional":false},{"reason":"Required for vision models.","package":"torchvision","optional":false},{"reason":"Required for audio models.","package":"torchaudio","optional":false},{"reason":"One of several optional backends for on-device inference.","package":"xnnpack","optional":true},{"reason":"Required for the CoreML backend on Apple devices. Updated in v1.0.1.","package":"coremltools","optional":true}],"imports":[{"note":"The `export_to_edge` function was part of an older API and is replaced by `torch.export` combined with `to_executorch`.","wrong":"from executorch.exporters.model_exporter.model_exporter import export_to_edge","symbol":"to_executorch","correct":"from torch._export.executorch import to_executorch"},{"note":"This is the standard PyTorch 2.0+ API for symbolic tracing, a prerequisite for ExecuTorch compilation.","symbol":"export","correct":"from torch.export import export"},{"note":"Example import for a common backend delegate. Other backends will have similar paths (e.g., `qualcomm`, `coreml`).","symbol":"XnnpackPartitioner","correct":"from executorch.backends.xnnpack.partition.xnnpack_partitioner import XnnpackPartitioner"}],"quickstart":{"code":"import torch\nimport torch.nn as nn\nfrom torch._export.executorch import to_executorch\nfrom torch.export import export\nfrom executorch.backends.xnnpack.partition.xnnpack_partitioner import XnnpackPartitioner\n\n# 1. Define a simple PyTorch model\nclass SimpleModel(nn.Module):\n    def __init__(self):\n        super().__init__()\n        self.linear = nn.Linear(10, 2)\n\n    def forward(self, x):\n        return self.linear(x)\n\nmodel = SimpleModel()\n\n# 2. Define example inputs (crucial for tracing and export)\nexample_inputs = (torch.randn(1, 10),)\n\n# 3. Export the model to an ExportedProgram using PyTorch's export API\nexported_program = export(model, example_inputs)\n\n# 4. Convert the ExportedProgram to an ExecuTorch program (.pte file)\n# This requires specifying a backend delegate. XNNPACK is a common choice.\n# Ensure `executorch[xnnpack]` or equivalent is installed.\nexecutorch_program = to_executorch(exported_program, [XnnpackPartitioner()])\n\n# 5. Save the ExecuTorch program to a file\nwith open(\"model.pte\", \"wb\") as f:\n    f.write(executorch_program.buffer)\n\nprint(\"Model successfully exported to model.pte\")","lang":"python","description":"This quickstart demonstrates how to define a simple PyTorch model, export it using `torch.export`, and then convert it into an ExecuTorch program (.pte file) using the `to_executorch` function with an XNNPACK delegate. The resulting .pte file can then be deployed to target devices."},"warnings":[{"fix":"Migrate to the new unified `export_llm` API for LLMs or the `torch.export` + `to_executorch` pattern for general models, referencing the latest documentation.","message":"The `export_llm` API was significantly changed/unified in v0.7.0. Older custom LLM export scripts will likely break. The general model export workflow also transitioned from older `executorch.exporters.model_exporter.model_exporter.export_to_edge` to `torch.export` followed by `torch._export.executorch.to_executorch`.","severity":"breaking","affected_versions":"<0.7.0"},{"fix":"Refer to the official ExecuTorch documentation for your specific target platform (Android, iOS, Cortex-M, etc.) for detailed build instructions for the native runtime.","message":"ExecuTorch involves two main components: the Python model preparation/exporter and the C++/native runtime for target devices. While `pip install executorch` handles the Python part, building the C++ runtime and SDK for specific embedded/mobile targets is a separate, often complex, and platform-specific process, requiring CMake and toolchain setup.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure you have installed ExecuTorch with the correct backend extras (e.g., `pip install executorch[xnnpack]`) and provide instantiated delegate builders to `to_executorch`, e.g., `to_executorch(exported_program, [YourDelegate()])`.","message":"The `to_executorch` function requires a list of delegate builders (e.g., `[XnnpackPartitioner()]`) for model partitioning and optimization. If a backend delegate is not provided or not correctly configured/installed, the export process may fail or result in a program that does not utilize the target hardware effectively.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure your Python environment is within the supported range (e.g., `python 3.10`, `3.11`, `3.12`). Use `pyenv` or `conda` to manage Python versions if needed.","message":"ExecuTorch explicitly supports Python versions `>=3.10` and `<3.14`. Using unsupported Python versions may lead to installation issues, build failures, or runtime errors due to underlying dependencies like PyTorch itself.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Install ExecuTorch with the required backend extra: `pip install executorch[xnnpack]` (replace `xnnpack` with the desired backend like `coreml`, `qualcomm`, etc.).","cause":"The specific backend delegate (e.g., XNNPACK) was not installed or built as part of your ExecuTorch installation.","error":"ModuleNotFoundError: No module named 'executorch.backends.xnnpack'"},{"fix":"Carefully review your model's `forward` signature and ensure `example_inputs` exactly mimic the data your model expects (e.g., `torch.randn(1, 10)` for a model expecting `(1, 10)` inputs).","cause":"The `example_inputs` provided to `torch.export` do not match the expected input types, shapes, or number of arguments for the model's `forward` method.","error":"RuntimeError: Input type mismatch. Expected (Tensor(shape=[1, 10], dtype=torch.float32)) got (Tensor(shape=[1, 5], dtype=torch.float32))"},{"fix":"First, pass the `ExportedProgram` to `to_executorch` to get the ExecuTorch program, then access `.buffer` on that object: `executorch_program = to_executorch(exported_program, ...); executorch_program.buffer`.","cause":"You are trying to access `.buffer` directly on the `ExportedProgram` returned by `torch.export`. The `.pte` binary data is contained in the object returned by `to_executorch`.","error":"AttributeError: 'ExportedProgram' object has no attribute 'buffer'"},{"fix":"When passing the partitioner to `to_executorch`, instantiate it: `to_executorch(exported_program, [XnnpackPartitioner()])`.","cause":"The `to_executorch` function expects a list of *instantiated* delegate objects or callables that return delegates, not the class type itself without parentheses.","error":"TypeError: 'XnnpackPartitioner' object is not callable"}]}