Stop shipping files nothing can reach in the wheel - #22584
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/22584
Note: Links to docs will display an error until the docs builds have been completed. ⏳ No Failures, 12 PendingAs of commit 3cb2a1d with merge base 7dc8641 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
360f24a to
4711a4e
Compare
4711a4e to
ab12a82
Compare
ab12a82 to
a358865
Compare
aafbf6c to
c88163f
Compare
c88163f to
3d829dc
Compare
3d829dc to
0760db6
Compare
0760db6 to
0ddda19
Compare
| keep = _reachable_test_modules() | ||
| return [ | ||
| entry | ||
| for entry in modules | ||
| if entry[1] == "__init__" or f"{package}.{entry[1]}" in keep | ||
| ] |
There was a problem hiding this comment.
Should we also prune the files that we don't keep from the pip-out build?
A pip install of ExecuTorch carries about 1150 test modules, 188 shader templates, and the Python sources of vendored third-party checkouts. Nothing in an installed wheel can reach any of it. Test cases are the largest group. pytest loads them from a path in the checkout, never through the installed name. Shared helpers are the opposite: the suites import each other by installed name, and one helper has 267 importers. A file name cannot tell them apart, since test_pipeline.py and test_add.py look alike and only one can go. ### What ships now Vendored trees are found by asking git for its submodules, so a hand-edited list cannot go stale. A test module ships only if something can still reach it: an import from anywhere in the tree followed through, a relative import, a literal name passed to importlib.import_module, or a name a workflow runs as `python -m`. Workflow names are listed explicitly, since a source distribution has no .github directory, and a test re-derives the list so it cannot drift. A yaml file ships unless it carries a shader template key, matched on content rather than a path list. Editable installs are untouched. A rebuild also deletes what an earlier build staged and this one does not want, limited to Python and yaml. Without that, building twice into the same directory keeps the old files and the wheel packages them, with no sign anything went wrong. The removed files are Python and yaml, apart from one marker file, so the same 1651 files leave every platform. Rebuilding each released wheel without them: Linux CPU 19.2 -> 16.0 MB 3.2 MB smaller, 16.9% Linux CUDA 27.1 -> 24.0 MB 3.1 MB smaller, 11.4% macOS 18.8 -> 15.7 MB 3.1 MB smaller, 16.4% Windows 14.1 -> 11.0 MB 3.1 MB smaller, 22.0% ### Test plan Built the macOS wheel and compared against one from the same base without the change. Everything removed was vendored, a test module, or a shader template, nothing was added, and the shipped headers, cmake files, schemas and libraries are unchanged in number. The other three rows come from applying that removal list to the released wheels, not from a build on each platform. Installed it and ran the suites CI runs, collected from the checkout: 1, 75 and 350 tests, identical to a wheel with everything in it. Ran a model through the portable kernels and the XNNPACK delegate against eager, and partitioned one through Vulkan with no shader yaml present. Added unit tests beside the existing wheel checks, each confirmed to go red when the behaviour it covers is switched off.
|
Good catch, and yes. I had only stopped the copy, so a second build into a directory an earlier build had used kept everything the first one put there, and the wheel packaged it with nothing to warn about. The build now removes the Python and yaml files it no longer wants from the build directory. Two guards on it, both of which I got wrong first and found by testing: It only removes a file that also exists in the source tree. Otherwise it deleted the generated init file behind the flatc console script, because build_py runs before build_ext and that file is not in build_py's own list. It refuses to run at all when the package list is empty, which is what a build started from outside the repository root used to produce. Measured on a directory staged by a build of the base branch: it now reduces to exactly what a clean build produces, and the generated file survives. |
A pip install of ExecuTorch carries about 1150 test modules, 188 shader templates, and
the Python sources of vendored third-party checkouts. Nothing in an installed wheel
can reach any of it.
Test cases are the largest group. pytest loads them from a path in the checkout, never
through the installed name. Shared helpers are the opposite: the suites import each other
by installed name, and one helper has 267 importers. A file name cannot tell them apart,
since test_pipeline.py and test_add.py look alike and only one can go.
What ships now
Vendored trees are found by asking git for its submodules, so a hand-edited list
cannot go stale.
A test module ships only if something can still reach it: an import from anywhere in
the tree followed through, a relative import, a literal name passed to
importlib.import_module, or a name a workflow runs as
python -m. Workflow names arelisted explicitly, since a source distribution has no .github directory, and a test
re-derives the list so it cannot drift.
A yaml file ships unless it carries a shader template key, matched on content rather
than a path list. Editable installs are untouched.
A rebuild also deletes what an earlier build staged and this one does not want, limited
to Python and yaml. Without that, building twice into the same directory keeps the old
files and the wheel packages them, with no sign anything went wrong.
The removed files are Python and yaml, apart from one marker file, so the same 1651 files
leave every platform. Rebuilding each released wheel without them:
Linux CPU 19.2 -> 16.0 MB 3.2 MB smaller, 16.9%
Linux CUDA 27.1 -> 24.0 MB 3.1 MB smaller, 11.4%
macOS 18.8 -> 15.7 MB 3.1 MB smaller, 16.4%
Windows 14.1 -> 11.0 MB 3.1 MB smaller, 22.0%
Test plan
Built the macOS wheel and compared against one from the same base without the change.
Everything removed was vendored, a test module, or a shader template, nothing was
added, and the shipped headers, cmake files, schemas and libraries are unchanged in
number. The other three rows come from applying that removal list to the released
wheels, not from a build on each platform.
Installed it and ran the suites CI runs, collected from the checkout: 1, 75 and 350
tests, identical to a wheel with everything in it. Ran a model through the portable
kernels and the XNNPACK delegate against eager, and partitioned one through Vulkan
with no shader yaml present.
Added unit tests beside the existing wheel checks, each confirmed to go red when the
behaviour it covers is switched off.