Repository navigation
Commit 7d51b01
authored
Break the exir backend_api <-> program import cycle (#24802)
### Summary
**Stacked on #24799.** Until that lands this branch also contains its
commits; review only the last commit, 121f6d6.
`exir/backend/backend_api.py` imports
`executorch.exir.program._fake_program`, which runs
`exir/program/__init__.py` and so `_program.py`. `_program.py` imported
`MethodProgramsPartitionerSpec` and `to_backend` from the still
half-initialised `backend_api` at module scope:
```
ImportError: cannot import name 'MethodProgramsPartitionerSpec' from partially initialized module 'executorch.exir.backend.backend_api' (most likely due to a circular import)
```
Normally `exir/__init__.py` loads `program` first, so this only fails
when `backend_api` is the first `executorch.exir` import, for example
under lazy imports (Cinder lazy imports on Python 3.14) when a backend
imports `to_backend` directly. On main, that import order fails earlier
on the `capture` cycle fixed in #24799, which is why this is stacked.
`_program.py` uses those two names only in
`EdgeProgramManager.to_backend`, so the import moves into that method.
Nothing imports them through `_program`.
This PR was authored with AI assistance (Claude Code).
### Test plan
Added `executorch.exir.backend.backend_api` to
`exir/tests/test_import_order.py` (added in #24799). It fails with the
error above without the `_program.py` change and passes with it. The
other entry points in that test still pass.
`python -m unittest executorch.exir.program.test.test_program
executorch.exir.backend.test.test_backends_lifted
executorch.exir.backend.test.test_partitioner
executorch.backends.xnnpack.test.ops.test_add` gives the same results
with and without this commit, apart from the new import-order case. The
shared failures come from my local runtime build, which lacks
`BackendWithCompilerDemo` and some kernels such as
`aten::_embedding_bag.out`.1 parent bc5bd66 commit 7d51b01
2 files changed
Lines changed: 8 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | 26 | | |
31 | 27 | | |
32 | 28 | | |
| |||
1725 | 1721 | | |
1726 | 1722 | | |
1727 | 1723 | | |
| 1724 | + | |
| 1725 | + | |
| 1726 | + | |
| 1727 | + | |
| 1728 | + | |
| 1729 | + | |
| 1730 | + | |
1728 | 1731 | | |
1729 | 1732 | | |
1730 | 1733 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
| |||
0 commit comments