Skip to content

New pip build system #2499

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

New pip build system #2499

wants to merge 1 commit into from

Conversation

dbort
Copy link
Contributor

@dbort dbort commented Mar 19, 2024

Summary:
Compatible with python -m build -wheel instead of using the deprecated python setup.py bdist_wheel.

A new custom build command builds all CMake targets, and a new custom build_ext command installs built files into the wheel.

A new custom build_py command copies platform-independent files into the wheel instead of copying them into the source tree.

Puts all generated files under pip-out instead of mixing with files in the tree.

Uses Command methods like mkpath and copy_file to benefit from setuptools concepts like dry_run, and to get logging for free.

Adds flatc to the wheel and puts it on the user's PATH. Removes the call to install_flatc.sh in install_requirements.sh; but, leaves the script in place since someone might want to run it on their own.

Also:

  • Enables runtime logging for pybindings even in release mode
  • Fixes another -fPIC requirement when building the flatcc host tools
  • Picks a number of build jobs based on the cores in the system, instead of defaulting to 9
  • Removes now-unnecessary steps from the Getting Started docs
  • Removes a use of ${arg^^}, which doesn't work with older versions of bash

Test Plan:
Iteration command to test wheel building without completely rebuilding the system:

rm -rf \
    /tmp/wheel-out \
    pip-out/lib* \
    pip-out/bdist.* \
    pip-out/temp.*/cmake-out/CMake* \
    executorch.egg-info \
    third-party/flatcc/{bin,lib} \
    ; \
  python setup.py bdist_wheel --dist-dir /tmp/wheel-out

To fully rebuild the system, also rm -rf pip-out.

The wheel file is written to (e.g.)

/tmp/wheel-out/executorch-0.1.0-cp310-cp310-linux_x86_64.whl

Examine it with unzip -l, or install it with pip install /tmp/wheel-out/executorch*.whl.

Also tested creating the wheel via install_requirements.sh and creating a simple model file.

./install_requirements.sh
python3 -m examples.portable.scripts.export --model_name="add"
<creates add.pte file>

Also tested that it can build pybindings with xnnpack when invoked via install_requirements.sh:

./install_requirements.sh --pybind xnnpack
python -m unittest backends/xnnpack/test/models/mobilenet_v2.py

Builds successfully, but trying to run the test currently fails during xnnpack init() due to T184024365. But it fails in the same way that the main branch does, so this new diff does not regress.

Reviewers:

Subscribers:

Tasks:

Tags:

Copy link

pytorch-bot bot commented Mar 19, 2024

🔗 Helpful Links

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

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

❌ 1 New Failure, 1 Unrelated Failure

As of commit fddd6c8 with merge base db7c057 (image):

NEW FAILURE - The following job has failed:

FLAKY - The following job failed but was likely due to flakiness present on trunk:

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

@facebook-github-bot facebook-github-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 Mar 19, 2024
@dbort
Copy link
Contributor Author

dbort commented Mar 19, 2024

I still need to clean this up, but now that it's sort of working I'd like to get some eyes on it. There's a lot going on here that's hard to separate, since it's a rewrite of setup.py.

Haven't tried it in CI yet so I bet things are broken.

@dbort dbort force-pushed the dbort-pip branch 2 times, most recently from 5b56340 to b41035e Compare March 19, 2024 18:01
Copy link
Contributor

@larryliu0820 larryliu0820 left a comment

Choose a reason for hiding this comment

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

Thanks for putting this up! It would be great if you can paste the temp directory tree structure and also things in the wheel so that we know what's inside.

Comment on lines -10 to -13
exir/_serialize/scalar_type.fbs
exir/_serialize/program.fbs
sdk/bundled_program/serialize/bundled_program_schema.fbs
sdk/bundled_program/serialize/scalar_type.fbs
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh nice finding we probably don't want to ignore all these

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We needed to before this, because setup.py copied them directly into the source tree.

CMakeLists.txt Outdated
@@ -301,10 +301,10 @@ endif()
# ${CMAKE_INSTALL_PREFIX}/
install(
TARGETS executorch
DESTINATION lib
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
Copy link
Contributor

Choose a reason for hiding this comment

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

Does CMake provide a default value for CMAKE_INSTALL_LIBDIR or we need to always pass in a value

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah it defaults to lib but can be lib64 in some situations, or a big ProgramFiles path on windows. So this is more portable then just saying lib.

Comment on lines 72 to 73
echo STOP # @nocommit
exit 1
Copy link
Contributor

Choose a reason for hiding this comment

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

remove this?

pyproject.toml Outdated
requires = [
"setuptools",
"wheel",
# @nocommit: insted we're using --no-isolation
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah is there a way to force --no-build-isolation in pip install?

#
# See build.initialize_options() in
# setuptools/_distutils/command/build.py for the default.
self.build_base = "pip-out"
Copy link
Contributor

Choose a reason for hiding this comment

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

so one thing I noticed in the previous pip install experience, is that the build base directory name contains useful information such as python version and os arch. Do we still have that in the new directory name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, this just moves the root from build/... to pip-out/... so it doesn't sit on top of our existing build/ directory. All of the platform-based directories live under this.

@dbort dbort force-pushed the dbort-pip branch 4 times, most recently from e4a18ec to 9b5e454 Compare March 23, 2024 03:05
@dbort
Copy link
Contributor Author

dbort commented Mar 23, 2024

It would be great if you can paste the temp directory tree structure and also things in the wheel so that we know what's inside.

Here's the listing from the latest version: https://gist.github.com/dbort/4a79eac7e1d1ebe7306f437bb2583482

The data directory is the interesting part that I've been getting into shape. Now you can see that it has flatc, and an __init__.py wrapper that knows how to execute it. See 9b5e454

     1811  03-23-2024 02:33   executorch/data/bin/__init__.py
  2250288  03-23-2024 01:35   executorch/data/bin/flatc
   179456  03-23-2024 01:38   executorch/data/lib/liboptimized_native_cpu_ops_lib.a
    16414  03-23-2024 01:35   executorch/data/lib64/libbundled_program.a
    41846  03-23-2024 01:35   executorch/data/lib64/libetdump.a
   174748  03-23-2024 02:42   executorch/data/lib64/libexecutorch.a
    12056  03-23-2024 01:35   executorch/data/lib64/libextension_data_loader.a
   203986  03-23-2024 02:42   executorch/data/lib64/libflatccrt.a
 88238252  03-23-2024 01:38   executorch/data/lib64/libportable_kernels.a
   179392  03-23-2024 01:38   executorch/data/lib64/libportable_ops_lib.a
     2715  03-23-2024 01:34   executorch/data/lib64/cmake/executorch/executorch-config.cmake

Oh whoops looks like I need to update liboptimized_native_cpu_ops_lib.a to use the proper LIBDIR. (lib64 is the LIBDIR value picked by the GNU Coding Conventions when building on my x86_64 machine)

Copy link
Contributor

@larryliu0820 larryliu0820 left a comment

Choose a reason for hiding this comment

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

Not sure if ci is reliable at this stage..

@dbort dbort force-pushed the dbort-pip branch 7 times, most recently from 42282fb to 64748f5 Compare March 26, 2024 19:10
@dbort dbort force-pushed the dbort-pip branch 2 times, most recently from d4caf74 to 2dc73ea Compare March 27, 2024 19:12
@facebook-github-bot
Copy link
Contributor

@dbort has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@dbort has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@dbort has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@dbort has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.


# Default build parallelism based on number of cores, but allow
# overriding through the environment.
default_parallel = str(os.cpu_count() - 1)
Copy link
Member

@GregoryComer GregoryComer Mar 28, 2024

Choose a reason for hiding this comment

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

This is nice QOL change. This should speed up builds significantly on higher core count systems.

@GregoryComer
Copy link
Member

This looks great. Thanks for taking all of this on.

@dbort dbort force-pushed the dbort-pip branch 2 times, most recently from ba122bd to 98a17b3 Compare March 30, 2024 21:49
@facebook-github-bot
Copy link
Contributor

@dbort has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

Summary:
Compatible with `pythom -m build` instead of using the deprecated
`python setup.py bdist_wheel`.

A new custom build command builds all necessary CMake targets, and a new
custom build_ext command installs built files into the wheel.

A new custom build_py command copies platform-independent files into the
wheel instead of copying them into the source tree.

Puts all generated files under pip-out instead of mixing with files in
the tree.

Uses Command methods like `mkpath` and `copy_file` to benefit from
setuptools concepts like dry_run, and to get logging for free.

Adds `flatc` to the wheel and installs a wrapper to make it available
on the path.

Test Plan:
Iteration command to test wheel building without completely rebuilding
the system:
```
rm -rf \
    /tmp/wheel-out \
    pip-out/lib* \
    pip-out/bdist.* \
    pip-out/temp.*/cmake-out/CMake* \
    executorch.egg-info \
    third-party/flatcc/{bin,lib} \
    ; \
  python setup.py bdist_wheel --dist-dir /tmp/wheel-out
```
To fully rebuild the system, also `rm -rf pip-out`.

The wheel file is written to (e.g.)
```
/tmp/wheel-out/executorch-0.1.0-cp310-cp310-linux_x86_64.whl
```

Examine it with `unzip -l`, or install it with `pip install
/tmp/wheel-out/executorch*.whl`.
@facebook-github-bot
Copy link
Contributor

@dbort has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@dbort merged this pull request in 250f681.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ciflow/trunk CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants