Repository navigation
Commit 7cfcde7
authored
Stop importing exir when loading the runtime from Python (pytorch#23301)
Loading the runtime from Python imports the whole exporter.
`portable_lib.py` imports `executorch.exir._warnings` only to get
`ExperimentalWarning` for one warning. Importing any `executorch.exir`
submodule runs `executorch/exir/__init__.py`, which pulls in
`torch._dynamo`, Inductor, Triton and torchao. A process that only loads
and runs `.pte` files pays for all of that.
On a Jetson AGX Thor, in a fresh process after `import torch`, importing
the runtime that way adds about 1,900 modules, over 250 MB of resident
memory and about 3 seconds. Jetson boards share their memory between the
CPU and the GPU, so on a small one like the 8 GB Orin Nano those 250 MB
come out of the model's budget.
This change raises the same message as a `DeprecationWarning`.
`ExperimentalWarning` derives from `DeprecationWarning`, so Python's
default filters treat it the same way: hidden by default, shown with `-W
default` or under pytest. Only the class name in the printed warning
changes.
It also drops the now unused `//executorch/exir:_warnings` dependency
from the `portable_lib` target, and adds a runtime test that imports
`executorch.runtime` in a fresh interpreter and checks that neither
`executorch.exir` nor `torch._dynamo` got loaded.
Measured on the Thor with a model that runs one TensorRT engine through
ExecuTorch, three fresh processes each:
| | before | after |
| --- | --- | --- |
| time to import the runtime and load the program | 3.3 s | 0.24 s |
| resident memory added | 758 MB | 522 MB |
| per-call latency | unchanged | unchanged |
Test plan: the new test fails before this change and passes after it.
The runtime and pybindings tests pass. Checked that the warning still
prints under `-W default` and stays hidden with the default filters.1 parent e78c792 commit 7cfcde7
3 files changed
Lines changed: 16 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
71 | | - | |
72 | 71 | | |
73 | 72 | | |
74 | 73 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
22 | | - | |
| 21 | + | |
| 22 | + | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
| 25 | + | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| |||
107 | 107 | | |
108 | 108 | | |
109 | 109 | | |
110 | | - | |
111 | 110 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
| 9 | + | |
8 | 10 | | |
9 | 11 | | |
10 | 12 | | |
| |||
20 | 22 | | |
21 | 23 | | |
22 | 24 | | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
23 | 36 | | |
24 | 37 | | |
25 | 38 | | |
| |||
0 commit comments