Skip to content

[build] Properly implement editable mode #8722

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

Merged
merged 4 commits into from
Feb 26, 2025
Merged

[build] Properly implement editable mode #8722

merged 4 commits into from
Feb 26, 2025

Conversation

larryliu0820
Copy link
Contributor

@larryliu0820 larryliu0820 commented Feb 26, 2025

Summary

Fixes #2871 #8379

This PR fixes a bunch of issues:

  • Trigger build command in build_ext to make sure the extensions are built.
  • Copy the built extensions (shared libraries or binaries) to the correct inplace locations.
    • For example, for normal install flatc will be installed to <site-packages>/executorch/data/bin but in editable it goes to executorch/data/bin.
    • Similarly <site-packages>/executorch/extension/llm/custom_ops/libcustom_ops_aot_lib.[dylib|so] goes into executorch/extension/llm/custom_ops/libcustom_ops_aot_lib.[dylib|so].
  • Make sure PYTHONPATH contains the site package path of whatever virtual environment where setuptools is being run from.
  • Change the way executorch/extension/llm/custom_ops/custom_ops.py find the library so that it can find the library in both normal build mode and editable build mode.

Test plan

Added CI jobs to pull.yml and trunk.yml.

Copy link

pytorch-bot bot commented Feb 26, 2025

🔗 Helpful Links

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

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

⏳ No Failures, 5 Pending

As of commit 9fb9ce0 with merge base 84273f4 (image):
💚 Looks good so far! There are no failures yet. 💚

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 Feb 26, 2025
@mergennachin mergennachin self-requested a review February 26, 2025 14:32
@jackzhxng jackzhxng added the release notes: build Changes related to build, including dependency upgrades, build flags, optimizations, etc. label Feb 26, 2025
Copy link
Member

@GregoryComer GregoryComer left a comment

Choose a reason for hiding this comment

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

Looks great. Thanks for fixing this.

@larryliu0820 larryliu0820 merged commit 1caa0a1 into main Feb 26, 2025
120 checks passed
@larryliu0820 larryliu0820 deleted the refactor_setup branch February 26, 2025 20:57
@@ -226,6 +235,9 @@ def main(args):
"-m",
"pip",
"install",
]
+ (["--editable"] if args.editable else [])
Copy link
Contributor

Choose a reason for hiding this comment

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

Thoughts on making this default? Or at least have a PR in draft mode to test the whole CI pipeline with editable?

return

if self.editable_mode:
self._ran_build = True
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't you need to set _ran_build = True in non editable mode too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No non-editable mode will trigger build by default so we don't have to trigger build in build_ext

file from the build directory to the correct location in the local
directory.

This should only be triggered when inplace mode (editable mode) is enabled.
Copy link
Contributor

Choose a reason for hiding this comment

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

This should only be triggered when inplace mode (editable mode) is enabled.

Where's the code that enforces that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment on lines +404 to +419
if isinstance(ext, BuiltExtension):
modpath = ext.name.split(".")
package = ".".join(modpath[:-1])
package_dir = os.path.abspath(build_py.get_package_dir(package))
else:
# HACK: get rid of the leading "executorch" in ext.dst.
# This is because we don't have a root level "executorch" module.
package_dir = ext.dst.removeprefix("executorch/")

# Ensure that the destination directory exists.
self.mkpath(os.fspath(package_dir))

regular_file = ext.src_path(self)
inplace_file = os.path.join(
package_dir, os.path.basename(ext.src_path(self))
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you comment what's happening here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See my PR description:

* Copy the built extensions (shared libraries or binaries) to the correct inplace locations.
  * For example, for normal install flatc will be installed to <site-packages>/executorch/data/bin but in editable it goes to executorch/data/bin.
  * Similarly <site-packages>/executorch/extension/llm/custom_ops/libcustom_ops_aot_lib.[dylib|so] goes into executorch/extension/llm/custom_ops/libcustom_ops_aot_lib.[dylib|so].

@mergennachin
Copy link
Contributor

In your Test Plan, can you comment an actual workflow of editable mode?

./install_executorch --editable
run a script
modify a .py file in executorch/exir/
rerun a script and make sure it is reflected

@mergennachin mergennachin requested a review from malfet February 26, 2025 21:07
@mergennachin
Copy link
Contributor

@malfet - can you take a look at this PR too to see anything obvious we're missing?

@malfet
Copy link
Contributor

malfet commented Feb 26, 2025

@malfet - can you take a look at this PR too to see anything obvious we're missing?

This looks OK to me, though personally I still do python setup.py develop instead of doing pip install --editable as user might have setuptools but no pip on their systems (pretty common for say conda environments)

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. release notes: build Changes related to build, including dependency upgrades, build flags, optimizations, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error in Pip Install Editable Mode
6 participants