-
Notifications
You must be signed in to change notification settings - Fork 26.3k
[fix] handle empty args in chain_matmul #43553
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
[fix] handle empty args in chain_matmul #43553
Conversation
|
Hey @kshitij12345! Would you add a test for this behavior to ensure it doesn't regress? |
| run_test([10, 20, 30, 5]) | ||
| run_test([15, 5, 10, 20, 25]) | ||
|
|
||
| with self.assertRaisesRegex(RuntimeError, "chain_matmul: Expected one or more matrices"): |
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.
Have updated the existing test here. To verify the behaviour.
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.
Lines 7224 to 7241 in 5fb5244
| @dtypes(torch.double) | |
| def test_chain_matmul(self, device, dtype): | |
| def product(matrices): | |
| for mat in matrices[1:]: | |
| matrices[0] = matrices[0].mm(mat) | |
| return matrices[0] | |
| def run_test(p): | |
| matrices = [] | |
| for (pi, pi_1) in zip(p[:-1], p[1:]): | |
| matrices.append(torch.randn(pi, pi_1, dtype=dtype, device=device)) | |
| self.assertEqual(torch.chain_matmul(*matrices), product(matrices)) | |
| run_test([10, 20, 30, 5]) | |
| run_test([15, 5, 10, 20, 25]) | |
| with self.assertRaisesRegex(RuntimeError, "chain_matmul: Expected one or more matrices"): | |
| torch.chain_matmul() |
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.
Awesome! Thanks @kshitij12345!
facebook-github-bot
left a comment
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.
@mruberry has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
Fixes #41817