8000 Use search-strategy: all for all site packages in pyre config by stroxler · Pull Request #25 · pytorch-labs/helion · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Use search-strategy: all for all site packages in pyre config #25

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 3 commits into from
May 7, 2025

Conversation

stroxler
Copy link
Contributor
@stroxler stroxler commented May 7, 2025

This PR attempts to make Pyre capable of checking using either installed torch from site packages, or if it is available a torch coming from a repository at ../pytorch, relative to the current helion repository.


The first diff improves our options for making a local pytorch repo work, because it eliminates the rigid assumption that we'll find torch in the site-packages directory (otherwise, Pyre will crash complaining about an invalid search path entry).

It's also generally simpler, and eliminates other potential consequences of trying to enumerate the site pachage entries; this is the go-to mode I would generally use for Pyre.

Tested by setting up a virtualenv, making sure pyre check works on trunk, and seeing that I get a clean result after this config change.


The second diff uses an "optional_search_path" to specify that ../pytorch should be used as a search path, but only if it exists. I verified that:

  • if there is no ../pytorch, this will run as before
  • if there is a ../pytorch, it winds up as a search root, and precedes site-packages

Note that there's a tradeoff here: the fact that ../pytorch gets precedence this means if there is a ../pytorch directory but we are not intending to use it in the current development environment, we're still going to pick it up. That could lead to confusion if it's mismatched against the current conda env, but I don't really see a way around it.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Meta Open Source bot. label May 7, 2025
I'm trying to find a way to support, in Pyre1, dual development
modes where pytorch might be installed via site-packages but
alternatively might be installed from source in the same project.

If we try to use a regular `search_path` it won't work; on my
machine I don't have `../pytorch`, and Pyre will crash complaining
about a missing search path elment.

Luckily, though, we added an optional_search_path with exactly the
behavior we need a while back: Pyre1 will ignore it if the path doesn't
exist, and include it if it does.

Note that
@@ -10,12 +10,8 @@
"source": "examples"
}
],
"optional_search_path": ["../pytorch"],
Copy link
Contributor

Choose a reason for hiding this comment

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

Regarding:

Note that there's a tradeoff here: the fact that ../pytorch gets precedence this means if there is a ../pytorch directory but we are not intending to use it in the current development environment, we're still going to pick it up. That could lead to confusion if it's mismatched against the current conda env, but I don't really see a way around it.

Piggy-backing on Jason's idea in a chat, perhaps we can create two .pyre_configuration files (one has "optional_search_path" and one doesn't) , and decide which one to use based on torch.__file__ in the current conda env?

Copy link
Contributor

Choose a reason for hiding this comment

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

Does the all change alone suffice?

Any idea why python setup.py develop breaks the old config? The files should still be symlinked from site-packages.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Any idea why python setup.py develop breaks the old config? The files should still be symlinked from site-packages.

I'm not entirely sure what's going on here, it's been a while since I looked deeply at Pyre's import logic and it was never terribly well optimized for external use cases. My best guess is that it isn't following the links properly

Does the all change alone suffice?

I'm actually not 100% sure why the "all" change is needed, but when I dropped the explicit search paths it couldn't find "triton" - my guess is that this is because triton is missing a py.typed marker file, which PEP561 says is required

perhaps we can create two .pyre_configuration files

You definitely could have two configurations, but you'd have to swap them out manually which might be annoying. A wrapper script could certainly do it

@@ -10,12 +10,8 @@
"source": "examples"
}
],
"optional_search_path": ["../pytorch"],
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 also add "../pytorch-hg", this might be only for me but i have multiple pytorch checkouts, one git one mercurial

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@oulgen oulgen merged commit d59d718 into pytorch-labs:main May 7, 2025
4 checks passed
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 Meta Open Source bot.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
0