[RFC] Run a `.pte` from Python without PyTorch: drop the PyTorch requirement and load CUDA on demand
Mantenedores costumam responder em até 1 dia
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 5/5
- Tempo estimado
- Mais de uma semana
- Facilidade para iniciantes
- 25/100
- Tipo de issue
- Funcionalidade
- Clareza
- Claramente especificada
- Status de atividade
- Ativa
- Domínio
- build-system
Direção de pesquisa
This RFC proposes splitting the existing Python wheels, but it does not identify implementation files or tests. Start by reading the package build configuration and the no-PyTorch CI job from #22971, then map which wheel currently owns each runtime file. Done means the runtime installs and runs a .pte without PyTorch across the listed build variants, passes pip check, and upgrades cleanly with pip and uv.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
Summary
Running an exported .pte from Python does not need PyTorch. The 1.6.0 runtime already proves it: installed without PyTorch, it loads a program and runs it on NumPy arrays or any buffer. What stops people is packaging. The executorch package requires torch==2.15.0, and on Linux its Python extension always loads the CUDA backend.
An earlier version of this RFC proposed a second package, executorch-runtime. After discussion, this version proposes 2 smaller changes to the existing executorch package instead:
- Drop the PyTorch requirement, and check the PyTorch version when the exporter is imported.
- On Linux, stop linking the CUDA backend into the Python extension, and load it when a CUDA program needs it.
No new package name, no files moving between packages, and the same wheels and indexes as today. A separate runtime package stays possible later, if users still need to drop the remaining export packages.
The problem
Export needs PyTorch. Running a model does not. Many Python users only run models: robot learning frameworks that deploy a trained policy, ROS 2 Python nodes, CI jobs that check an exported file, and small containers or Jetson images.
What they face with 1.6.0:
- A PyTorch pin they cannot accept. Every 1.6.0 wheel requires
torch==2.15.0. MuJoCo Playground requirestorch<2.14, so pip cannot installexecutorchnext to it. LeRobot allowstorch<2.16, so adding ExecuTorch would move its users to exactly 2.15. PyTorch itself is a 484 to 539 MB download on Linux, before its CUDA libraries. - CUDA on every Linux import. The PyPI wheel for Linux is the CUDA 13.2 build. Its Python extension links the CUDA backend, the AOTInductor shim library (about 35 MB) and
libcudart.so.13. So every import loads them, also on a board with no NVIDIA GPU and also for an XNNPACK program. - A workaround that only works by hand. This runs today:
pip install --no-deps "executorch==1.6.0+cpu" --index-url https://download.pytorch.org/whl/cpu
pip install numpy
A library cannot put --no-deps in its requirements, so no project can depend on ExecuTorch this way.
What the 1.6.0 wheels contain
Measured on the Python 3.12 wheels from PyPI and download.pytorch.org:
| Part | Size | Links PyTorch? | Notes |
|---|---|---|---|
| Core, kernels, XNNPACK, Python extension | about 16 MB | no | everything a CPU program needs |
| OpenVINO, QNN, Core ML adapters | under 0.5 MB each | no | load the vendor runtime only when a program uses it |
| VGF (Arm Vulkan ML) | inside the Python extension | no | Linux only |
| MLX | about 6 MB | no | macOS only |
| CUDA backend and shim | about 36 MB | no | Linux and Windows CUDA builds; linked into the Python extension on Linux only |
| LLM runner, training bindings, export-time operator libraries | small | yes | link libtorch |
So the runtime and every backend run without PyTorch. Only the LLM runner and the training bindings need it.
Proposal
1. Drop the PyTorch requirement, check the version on import
executorch stops listing torch in its requirements. The main branch already does this, and so does torchao. A user who only runs models never installs PyTorch.
Export still needs a matching PyTorch, and releases without a requirement have failed late before: 1.5.x installed fine next to PyTorch 2.12 and then failed at run time with tensor does not have a device (#23311). With 1.6.0 and PyTorch 2.8, import executorch.exir fails on a missing private function. To turn that into a clear early error, each release records the PyTorch range it was tested with, and executorch.exir checks it on import:
- PyTorch missing, or older than supported: stop with a message that says what to install, for example
ExecuTorch 1.7 exports with torch 2.16.x, found 2.8.0. Run: pip install "torch==2.16.*". - Newer than tested: warn and continue. 1.6.0 exported and ran a model with PyTorch 2.14 and with a 2.16 nightly.
- The runtime import (
executorch.runtime) never runs this check.
The LLM runner and the training bindings link libtorch, so importing them without PyTorch gives the same clear message instead of a loader error.
An optional extra, pip install executorch[export], installs the tested PyTorch range for users who want pip to pick it.
2. Load the CUDA backend on demand
The top-level CMakeLists.txt already leaves the CUDA backend out of the Python extension on Windows, "so the Python extension stays free of any CUDA dependency". This change does the same on Linux:
- The Python extension stops linking the CUDA backend, the shim library and
extension_cuda. The libraries still ship in the same wheel, and C++ apps link them through CMake as today. - The CUDA parts of the Python API (CUDA streams, results that stay on the GPU) move to a small separate extension module that links CUDA.
- The CUDA backend registers itself from a static initializer when its library loads, the way the TensorRT delegate wheel already works. It loads on
import executorch.backends.cuda, or automatically when a program namesCudaBackendand it is not registered yet. - The same loader lets Windows Python run CUDA programs, which it cannot do today.
A CPU program then maps no CUDA library and does not need libcudart. Torch-TensorRT keeps working, because extension_cuda still ships in the CUDA builds.
While touching registration: the backend registry has 16 fixed slots, and a failed or duplicate registration is dropped silently. Failures should be logged.
Related, owned by others
Not part of this RFC, but worth knowing:
- The TensorRT delegate wheel,
torch-tensorrt-executorch-runtime, liststorchdirectly, so its users still install PyTorch after change 1. Whether to drop it is up to Torch-TensorRT. - The QNN adapter ships only in the Linux x86_64 wheel. Whether to ship it for Linux aarch64 is up to the Qualcomm backend owners.
How people use it
Run a model, with no PyTorch:
pip install executorch
import numpy as np
from executorch.runtime import Runtime
method = Runtime.get().load_program("policy.pte").load_method("forward")
action = np.asarray(method.execute([np.zeros((1, 32), dtype=np.float32)])[0])
Depend on it from a library:
[project.optional-dependencies]
executorch = ["executorch"]
Export a model: pip install executorch[export], or pip install executorch next to the PyTorch you already have.
What stays as it is
Without PyTorch, pip install executorch still installs the other packages the exporter uses. On Linux aarch64 they take about 316 MB on disk: pandas (84 MB), SymPy (74 MB), NumPy (68 MB), TorchAO (13 MB), and smaller ones: hydra-core, omegaconf, flatbuffers, PyYAML, ruamel.yaml, tabulate, mpmath, requests, pytorch-tokenizers, py-cpuinfo, packaging and typing-extensions. On Linux x86_64 and macOS, coremltools and scikit-learn come too, and scikit-learn brings SciPy. NumPy is the only one of these a runtime user may want anyway. That is far less than PyTorch and its CUDA libraries, but it matters for small images. If users need to drop it too, a runtime-only package is the next step (see Alternatives). It has to handle a pip behavior we reproduced with pip 26.3: when a file moves from one package to another, pip install -U of the old package deletes it, and pip check stays green.
Plan
- Agree on the 3 changes.
- Remove
torchfrom the release requirements and add the version check, with tests for missing, older, and newer PyTorch. - Change the Linux CMake for the Python extension, add the CUDA loader and the separate CUDA module, and test: import on a machine without CUDA, a CPU program maps no CUDA library, a CUDA program loads it and runs, and the TensorRT delegate still loads.
- Add a docs page, "Run a model from Python without PyTorch".
What this promises, and what it does not
pip install executorchruns a.ptewith no PyTorch on the platforms the wheels cover today.- Export works with the PyTorch range the release names, and fails early with a clear message outside it.
- No stable binary interface across releases.
- It does not make inference faster, and it does not shrink the download for users who keep the export packages.
Alternatives considered
- A version range (
torch>=2.15,<2.16) instead of no requirement. pip would enforce it, but every runtime-only user would still install PyTorch, and MuJoCo Playground would still be blocked. - A separate
executorch-runtimepackage now (the earlier version of this RFC), with a CUDA add-on later. It removes the export packages too, but it moves files between packages, which pip handles badly on upgrade, and it doubles the release matrix. It stays the next step if the remaining export packages are a real problem. - One package per backend. Only CUDA is large and needs something most users do not have. The other adapters are under 1 MB and load their vendor runtime only when used, so separate packages would add release work for no gain.
- A separate import name, as the Native backend's
executorch-nativewheel does. A process that imports both packages would load the runtime twice, each with its own backend registry.
Open questions
- Should the version check fail or warn for a PyTorch newer than tested?
- Should the automatic CUDA load happen on demand only, or also when
executorch.runtimeis imported on a machine with a GPU? - Are the remaining export packages (pandas, SymPy, TorchAO and the rest, about 316 MB) acceptable for the robotics and container users, or should the runtime-only package follow soon after?
- Linguagem predominante
- Python
- Estrelas
- 5.2k
- Forks
- 1.3k
- Merge médio
- 1d 7h
- PRs com merge (30d)
- 644
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Tem um modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de pytorch/executorch
-
to_edge_transform_and_lower ignores some ops_to_not_decompose requests: multi-output ops, and non-core ops without a decompositionTalvez já em andamento @Eureka-Zhang assumiu há 7 dias. Abertamodule: exir
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 66/100
pytorch/executorch#25620 ·
Mantenedores costumam responder em até 1 dia
-
Qualcomm AI Engine Direct - fp16a8w quantization crashes on layer_normTalvez já em andamento @psiddh assumiu há 21 dias. Abertabug module: qnn partner: qualcomm
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 74/100
pytorch/executorch#24434 · 1 responsável ·
Mantenedores costumam responder em até 1 dia
-
enhancement triaged
Dificuldade 2/5 Meio dia Facilidade para iniciantes 68/100
pytorch/executorch#21640 ·
Mantenedores costumam responder em até 1 dia
-
quantize_per_channel and dequantize_per_tensor.tensor abort the process on a float32 scaleTalvez já em andamento @AxelNoun assumiu hoje. Aberta
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 35/100
pytorch/executorch#25873 ·
Mantenedores costumam responder em até 1 dia
-
XNNPACK INT4 linear returns incorrect per-channel outputs and fails groupwise FP16 on Apple M4 MaxTalvez já em andamento Um pull request vinculado a esta issue está aberto ou já foi mesclado. Abertabug module: quantization module: xnnpack
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 43/100
pytorch/executorch#25854 ·
Mantenedores costumam responder em até 1 dia
Todas as issues de pytorch/executorch
Issues semelhantes
-
Container fails to start when GitHub Releases is unavailable: uv run re-downloads the tvl wheelAberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
trezor/trezor-user-env#421 ·
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 84/100
-
Dificuldade 1/5 1-3 horas Facilidade para iniciantes 91/100
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
tangentcode/tangentswarm#167 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
Mantenedores costumam responder em até 1 dia