Skip to content

[Reland] [functorch] Fix linalg batch rules to error on non-matrix inputs#82176

Closed
samdow wants to merge 22 commits intogh/samdow/15/basefrom
gh/samdow/15/head
Closed

[Reland] [functorch] Fix linalg batch rules to error on non-matrix inputs#82176
samdow wants to merge 22 commits intogh/samdow/15/basefrom
gh/samdow/15/head

Conversation

@samdow
Copy link
Contributor

@samdow samdow commented Jul 25, 2022

@facebook-github-bot
Copy link
Contributor

facebook-github-bot commented Jul 25, 2022

🔗 Helpful links

✅ No Failures (2 Pending)

As of commit b78bba1 (more details on the Dr. CI page):

Expand to see more

💚 💚 Looks good so far! There are no failures yet. 💚 💚


This comment was automatically generated by Dr. CI (expand for details).

Please report bugs/suggestions to the (internal) Dr. CI Users group.

Click here to manually regenerate this comment.

@samdow
Copy link
Contributor Author

samdow commented Jul 25, 2022

I wasn't able to add the testing I wanted where we check that the error we get on a vector is the same as a matrix...somehow that failed locally for things where the batch rule wasn't implemented?

Any other thoughts on how to test this are welcome though!

Copy link
Contributor

@zou3519 zou3519 left a comment

Choose a reason for hiding this comment

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

some minor comments/questions

return moveBatchDimToFront(tensor, batch_dim);
}

static oneOutput apply_one(
Copy link
Contributor

Choose a reason for hiding this comment

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

(no action required) In c++17 we can create a single function that takes the number of returns as a template argument, using constexpr_if. e.g. https://stackoverflow.com/questions/59046161/how-to-change-the-return-type-depending-on-the-input-c . Unfortunately pytorch is still on c++14

@zou3519
Copy link
Contributor

zou3519 commented Jul 26, 2022

I wasn't able to add the testing I wanted where we check that the error we get on a vector is the same as a matrix...somehow that failed locally for things where the batch rule wasn't implemented?
Any other thoughts on how to test this are welcome though!

What failed locally?

@samdow
Copy link
Contributor Author

samdow commented Jul 26, 2022

I wasn't able to add the testing I wanted where we check that the error we get on a vector is the same as a matrix...somehow that failed locally for things where the batch rule wasn't implemented?
Any other thoughts on how to test this are welcome though!

What failed locally?

So the basic of the test was this: go through the sample inputs for every linalg.* function, find one that's 2D, take a 1D slice of it, run the (non-vmapped) function with that under a try, catch any error and then run the vmapped-version (with the input expanded to be a square of the 1D slice) under self.assertRaisesRegex(<that error>).

Occassionally we'll get errors like:
AssertionError: "linalg.pinv(Float{[5]}): expected a tensor with 2 or more dimensions of float, double, cfloat or cdouble types" does not match "linalg.pinv(Float{[5]}): expected a tensor with 2 or more dimensions of float, double, cfloat or cdouble types"
This is something that I looked into briefly and just couldn't figure out what it thought was different

We could also just do a check that the the first part of this matches the function being called but I'm not fully convinced that it's always correct? I guess I could check that

EDIT: just checked and it's not always true that the first part matches the exact function being called (ex: linalg.svdvals will error with an error starting with linalg.svd)

@samdow
Copy link
Contributor Author

samdow commented Jul 28, 2022

@pytorchbot rebase

@pytorchmergebot
Copy link
Collaborator

@pytorchbot successfully started a rebase job. Check the current status here

@pytorchmergebot
Copy link
Collaborator

Successfully rebased gh/samdow/15/orig onto refs/remotes/origin/master, please pull locally before adding more changes (for example, via ghstack checkout https://github.com/pytorch/pytorch/pull/82176)

pytorchmergebot pushed a commit that referenced this pull request Jul 28, 2022
samdow pushed a commit that referenced this pull request Jul 28, 2022
@samdow
Copy link
Contributor Author

samdow commented Jul 28, 2022

@zou3519 when you get a chance to look again, this now has the test we discussed offline that just checks that every function in linalg and tests that it errors if being passed a 1D tensor. The only cases it's skipping at (1) vector_norm which should accept 1D vectors or (2) multi_dot which accepts a list of tensors. This gets its own test case since there's rules around what can and can't be 1D

samdow pushed a commit that referenced this pull request Jul 28, 2022
@pytorchmergebot
Copy link
Collaborator

@pytorchbot successfully started a merge job. Check the current status here

@github-actions
Copy link
Contributor

github-actions bot commented Aug 2, 2022

Hey @samdow.
You've committed this PR, but it does not have both a 'release notes: ...' and 'topics: ...' label. Please add one of each to the PR. The 'release notes: ...' label should represent the part of PyTorch that this PR changes (fx, autograd, distributed, etc) and the 'topics: ...' label should represent the kind of PR it is (not user facing, new feature, bug fix, perf improvement, etc). The list of valid labels can be found here for the 'release notes: ...' and here for the 'topics: ...'.
For changes that are 'topic: not user facing' there is no need for a release notes label.

@zengk95
Copy link
Contributor

zengk95 commented Aug 2, 2022

@pytorchbot revert -m "This looks like it's breaking functorch tests on master" -c nosignal

@pytorchmergebot
Copy link
Collaborator

@pytorchbot successfully started a revert job. Check the current status here

@pytorchmergebot
Copy link
Collaborator

@samdow your PR has been successfully reverted.

pytorchmergebot added a commit that referenced this pull request Aug 2, 2022
…uts (#82176)"

This reverts commit 1dfcad8.

Reverted #82176 on behalf of https://github.com/zengk95 due to This looks like it's breaking functorch tests on master
@samdow samdow reopened this Aug 2, 2022
@samdow samdow changed the title [functorch] Fix linalg batch rules to error on non-matrix inputs [Reland] [functorch] Fix linalg batch rules to error on non-matrix inputs Aug 2, 2022
samdow pushed a commit that referenced this pull request Aug 2, 2022
facebook-github-bot pushed a commit to pytorch/functorch that referenced this pull request Aug 3, 2022
…176) (#82176)

Summary:
X-link: pytorch/pytorch#82176
Approved by: https://github.com/zou3519

Reviewed By: kit1980

Differential Revision: D38359527

Pulled By: samdow

fbshipit-source-id: f41ecc073deaa5d45f5e2733e31cc086a33716f0
facebook-github-bot pushed a commit that referenced this pull request Aug 3, 2022
) (#82176)

Summary:
Pull Request resolved: #82176
Approved by: https://github.com/zou3519

Test Plan: contbuild & OSS CI, see https://hud.pytorch.org/commit/pytorch/pytorch/1dfcad84aaad9c095b4dbbdafd5c351e9a712d45

Reviewed By: kit1980

Differential Revision: D38359527

Pulled By: samdow

fbshipit-source-id: f41ecc073deaa5d45f5e2733e31cc086a33716f0
@samdow
Copy link
Contributor Author

samdow commented Aug 3, 2022

@pytorchbot merge

@pytorchmergebot
Copy link
Collaborator

@pytorchbot successfully started a merge and created land time checks. See merge status here and land check progress here.

pytorchmergebot pushed a commit that referenced this pull request Aug 3, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Aug 3, 2022

Hey @samdow.
You've committed this PR, but it does not have both a 'release notes: ...' and 'topics: ...' label. Please add one of each to the PR. The 'release notes: ...' label should represent the part of PyTorch that this PR changes (fx, autograd, distributed, etc) and the 'topics: ...' label should represent the kind of PR it is (not user facing, new feature, bug fix, perf improvement, etc). The list of valid labels can be found here for the 'release notes: ...' and here for the 'topics: ...'.
For changes that are 'topic: not user facing' there is no need for a release notes label.

facebook-github-bot pushed a commit to pytorch/functorch that referenced this pull request Aug 4, 2022
…uts (#82176)"

Summary:
This reverts commit 1dfcad84aaad9c095b4dbbdafd5c351e9a712d45.

Reverted pytorch/pytorch#82176 on behalf of https://github.com/zengk95 due to This looks like it's breaking functorch tests on master

Reviewed By: kit1980

Differential Revision: D38394721

fbshipit-source-id: 0aedbc4d8284ce3055df5d6768858199f06f230e
facebook-github-bot pushed a commit that referenced this pull request Aug 4, 2022
…uts (#82176)"

Summary:
This reverts commit 1dfcad8.

Reverted #82176 on behalf of https://github.com/zengk95 due to This looks like it's breaking functorch tests on master

Test Plan: contbuild & OSS CI, see https://hud.pytorch.org/commit/pytorch/pytorch/31292599eb8ab41a8f5ac9ced3a5efca1fc0b627

Reviewed By: kit1980

Differential Revision: D38394721

fbshipit-source-id: 0aedbc4d8284ce3055df5d6768858199f06f230e
facebook-github-bot pushed a commit to pytorch/functorch that referenced this pull request Aug 4, 2022
…puts (#82176) (#82176)

Summary:
X-link: pytorch/pytorch#82176
Approved by: https://github.com/zou3519

Reviewed By: kit1980

Differential Revision: D38395303

Pulled By: samdow

fbshipit-source-id: ea69a28d2d413f4194ed6e96bdeaeaba6c01a3a1
facebook-github-bot pushed a commit that referenced this pull request Aug 4, 2022
…puts (#82176) (#82176)

Summary:
Pull Request resolved: #82176
Approved by: https://github.com/zou3519

Test Plan: contbuild & OSS CI, see https://hud.pytorch.org/commit/pytorch/pytorch/fbbd036871406a3895607a79dc58dc08551df486

Reviewed By: kit1980

Differential Revision: D38395303

Pulled By: samdow

fbshipit-source-id: ea69a28d2d413f4194ed6e96bdeaeaba6c01a3a1
@facebook-github-bot facebook-github-bot deleted the gh/samdow/15/head branch August 7, 2022 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants