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
[export] Fix tree spec matching behavior. #109679
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/109679
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 6d70453 with merge base 6e3a747 (): This comment was automatically generated by Dr. CI and updates every 15 minutes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this just a cleaner way of doing things? Or is there actually a bug that it's fixing?
1cd7d10
to
95b0239
Compare
@angelayi yeah I'm trying to fix an internal test. The current behavior of tree_flatten_spec doesn't not actually check whether we're using up all the elements in a container. For example, the following will pass today: _, spec = pytree.tree_flatten([1])
res = fx_pytree.tree_flatten_spec([1, 2, 3], spec)
assert len(res) == 1 In this case, pytree will drop the rest of elements that're not mentioned in the original spec. Now this might be intended for most cases, for our case we also need to check whether we have an exact match on pytree. |
95b0239
to
8538b7c
Compare
@zhxchen17 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
8538b7c
to
a24c919
Compare
@zhxchen17 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can also add some tests in OSS?
Summary: Test Plan: Internal test. Reviewers: Subscribers: Tasks: Tags:
a24c919
to
6d70453
Compare
@zhxchen17 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
Added unit test |
@pytorchbot merge -f "unblocking internal server model enablement" |
Merge startedYour change will be merged immediately since you used the force (-f) flag, bypassing any CI checks (ETA: 1-5 minutes). Please use Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
This is not intended. We should fix tree_flatten_spec instead of adding this new API. |
@zou3519 To be clear I'm not adding a new API, I'm adding a new flag to existing tree_flatten_spec without trying to break the existing code. |
@zhxchen17 this PR modified the register_pytree_flatten_spec to take in two functions, a flatten_fn_spec function and an flatten_fn_exact_match_spec function. Assuming that the correct semantics are "flatten AND check that the number of elements match", then the better design is to fix the existing
|
@zou3519 The problem of fixing pytree_flatten_spec entirely is, it's almost impossible to land a change like this with unknown number of clients who is already relying on the undesirable behavior. For example, we can have a torch packaged program who make a lot of calls to pytree_flatten_spec() and the number of elements doesn't match in production systems, and I also saw a torch xla test depending on the previous more permissive behavior. If we really want to fix the behavior for all existing cases, I can help with a second PR to flip the exect_structural_match to True by default and observe all the test failures and fix them incrementally (or simply remove the flag and do the same). Which makes more sense to you? |
We should at least attempt a yolo fix via a follow-up PR that flips the default and seeing what breaks. If it's too much, then yeah, it's probably not worth cleaning this up, but the hypothesis is that tree_flatten_spec silently ignoring too many elements is not expected behavior |
following up in #109841 |
Summary:
Test Plan:
Internal test.
Reviewers:
Subscribers:
Tasks:
Tags:
Fixes #ISSUE_NUMBER