pytorch / pytorch/executorch

[RFC] Canonicalize python file structure

Open
#8,699 11 comments 2 reactions 1 assignee View on GitHub

@larryliu0820 is already working on this.

Since Feb 25, 2025.

enhancement triaged
Dominant language
Python
Stars
5k
Forks
1.2k
Avg merge
2d 10h
Merged PRs (30d)
581

Description

πŸš€ The feature, motivation and pitch

Blocking #2871

Context

Currently the file structure looks like this:

executorch
β”œβ”€β”€ backends
...
β”œβ”€β”€ exir
β”œβ”€β”€ extension
...
β”œβ”€β”€ runtime
β”œβ”€β”€ setup.py
...
└── version.txt

Problem

  • Since we don't have an executorch/ directory, we can't add code into executorch root module, we will have to do things like import executorch.exir etc. In the future we want to do from executorch import <top level API>
  • We want to have a clean separation between python code and C++ code, for easier build system management.
    • E.g., we don't want to build python code in GH, so it will be easier to configure the internal repo to not map TARGETS files to GH.
  • Editable mode install couldn't find the top level module correctly and thus failed to install.
    • This is because when setuptools tries to map the module namespace to actual files, it will do the following mapping: 'executorch/backens.apple': ['<path to local executorch repo>/executorch/backends/apple']. setuptools couldn't define a root level executorch module as well because it only lookup folders under executorch/. See NAMESPACE section in this generated code, instead we want this code.

Proposal

Move all python code into executorch/ and use that as our root level module. Keep all native source files intact.

executorch
β”œβ”€β”€ backends
β”‚   β”œβ”€β”€ apple // no python code
β”‚   β”œβ”€β”€ arm
β”œβ”€β”€ executorch // only python code
β”‚   β”œβ”€β”€ backends
β”‚   β”œβ”€β”€ exir
β”‚   └── extension
...
└── version.txt

This way we can build a self-contained executorch module which works for editable mode.

Migrations

If we go down this route, we will have to migrate python targets to executorch/ and change internal usage. I don't expect this to affect pip users since they will just do the same from executorch.exir import X.

Alternatives

No response

Additional context

No response

RFC (Optional)

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up β€” it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.