Skip to content

Expose executorch.__version__#20271

Closed
shoumikhin wants to merge 3 commits into
pytorch:mainfrom
shoumikhin:expose-executorch-version
Closed

Expose executorch.__version__#20271
shoumikhin wants to merge 3 commits into
pytorch:mainfrom
shoumikhin:expose-executorch-version

Conversation

@shoumikhin

Copy link
Copy Markdown
Contributor

Summary

import executorch; executorch.__version__ currently raises AttributeError, even though torch.__version__, numpy.__version__, etc. all work. The version data already exists: setup.py generates executorch/version.py (with __version__ and git_version) from version.txt at build time, mirroring torch/version.py. But executorch has no top-level __init__.py to re-export it, so the generated module is never surfaced on the package. (executorch.version.__version__ works today; the conventional executorch.__version__ does not.)

This adds src/executorch/__init__.py that re-exports the generated version, with a graceful fallback so import executorch never fails in an unbuilt source tree:

  • built wheel / editable install -> uses the generated executorch/version.py (exact build version + git hash);
  • otherwise -> falls back to installed distribution metadata via importlib.metadata;
  • otherwise -> 0.0.0+unknown (never raises).

version.txt stays the single source of truth; no version string is hardcoded, and setup.py is unchanged (it already generates version.py in this directory).

Note for reviewers

This promotes executorch from an implicit (PEP 420) namespace package to a regular package. For the single-wheel layout this is the conventional setup and matches torch/numpy, but please confirm no consumer relies on namespace-package merging of executorch.* across multiple roots.

Test plan

import executorch
print(executorch.__version__)   # e.g. 1.4.0a0+<githash>
print(executorch.git_version)

Re-export the build-generated version from the package root.
Copilot AI review requested due to automatic review settings June 15, 2026 00:13
@pytorch-bot

pytorch-bot Bot commented Jun 15, 2026

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/20271

Note: Links to docs will display an error until the docs builds have been completed.

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

❌ 11 New Failures, 1 Cancelled Job, 13 Pending, 1 Unclassified Failure

As of commit 22a82d0 with merge base 0378fc4 (image):

NEW FAILURES - The following jobs have failed:

UNCLASSIFIED FAILURE - DrCI could not classify the following job because the workflow did not run on the merge base. The failure may be pre-existing on trunk or introduced by this PR:

  • Test WebGPU Backend (gh) (this job did not run on the merge base, so DrCI cannot tell whether the failure is pre-existing)

CANCELLED JOB - The following job was cancelled. Please retry:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jun 15, 2026
@github-actions

Copy link
Copy Markdown

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a top-level executorch Python package initializer to expose conventional version attributes (executorch.__version__, executorch.git_version) while keeping imports resilient in unbuilt source-tree scenarios.

Changes:

  • Introduces src/executorch/__init__.py to re-export __version__ and git_version from the generated executorch/version.py.
  • Implements a fallback to importlib.metadata (and finally 0.0.0+unknown) so import executorch does not fail when version.py isn’t present.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/executorch/__init__.py Outdated
Comment thread src/executorch/__init__.py Outdated
Addresses review: only fall back when version.py is absent; a present-but-broken version.py now surfaces.
@shoumikhin

Copy link
Copy Markdown
Contributor Author

Thanks for the review — addressed both:

  • Import resilience: switched to a relative import and narrowed the catch to ModuleNotFoundError, so the fallback only triggers when version.py is genuinely absent (unbuilt source tree). A present-but-broken version.py now surfaces its error instead of being silently swallowed.
  • Smoke test: added test/test_version.py asserting import executorch succeeds and exposes __version__ (non-empty str) and git_version, covering both the built and unbuilt-source paths.

@shoumikhin

Copy link
Copy Markdown
Contributor Author

Closing this — CI shows the approach is incompatible with ExecuTorch's packaging model.

Adding a top-level src/executorch/__init__.py converts executorch from a PEP 420 implicit namespace package into a regular package, which stops Python from merging executorch.* across multiple roots. Components that are built/installed into a separate location and rely on that namespace merging then fail to import. The QNN and LoRA jobs break with:

import executorch.backends.qualcomm.python.PyQnnManagerAdaptor as PyQnnManager
ModuleNotFoundError: No module named 'executorch.backends.qualcomm.python'

This is the namespace-package risk noted in the PR description, now confirmed by CI (11 jobs, deterministic). Since executorch must remain a namespace package, there's no way to add a package __init__.py (which is required to set __version__) without this regression.

The underlying gap is real — the build already generates executorch/version.py (mirroring torch/version.py) but it isn't surfaced as executorch.__version__. A namespace-safe fix would need a different mechanism (e.g. maintainers deciding on a packaging approach that doesn't reintroduce a top-level __init__.py). Closing this one; happy to follow up if the team wants to pursue a namespace-compatible approach.

@shoumikhin shoumikhin closed this Jun 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants