Repository navigation
[Bugfix] Fix a bug when 0 dim linalg det backwards - #177498
Skylion007 wants to merge 2 commits into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/177498
Note: Links to docs will display an error until the docs builds have been completed. ❌ 1 New FailureAs of commit 311518d with merge base 19afa71 ( NEW FAILURE - The following job has failed:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
lezcano
left a comment
There was a problem hiding this comment.
SG in principle, but should add a proper regression test.
| # When A has 0 elements (e.g. empty batch), backward should return a | ||
| # zeros tensor with the same shape as A, not an undefined tensor. | ||
| for shape in [(0, 3, 3), (2, 0, 0)]: | ||
| A = torch.randn(shape, device=device, dtype=dtype, requires_grad=True) | ||
| det = torch.linalg.det(A) | ||
| det.backward(torch.ones_like(det)) | ||
| self.assertIsNotNone(A.grad) | ||
| self.assertEqual(A.grad.shape, A.shape) | ||
| self.assertEqual(A.grad, torch.zeros_like(A)) | ||
|
|
There was a problem hiding this comment.
This is not a regression test tho, is it?
There was a problem hiding this comment.
ah, you are checking the shape, fine.
|
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Merge failedReason: 1 mandatory check(s) failed. The first few are: Dig deeper by viewing the failures on hud |
|
@pytorchbot merge -i |
Merge startedYour change will be merged while ignoring the following 1 checks: pull / linux-jammy-cpu-py3.10-gcc11-bazel-test / build-and-test (default, 1, 1, lf.linux.4xlarge) Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Zero strided tensor should have gradients be a zero stride tensor, not an undefined Tensor (implicitly 1). This can cause issues with 2nd order and higher derivatives. It also violates the invariants that grad.shape == tensor.shape Pull Request resolved: pytorch#177498 Approved by: https://github.com/lezcano
Zero strided tensor should have gradients be a zero stride tensor, not an undefined Tensor (implicitly 1). This can cause issues with 2nd order and higher derivatives. It also violates the invariants that grad.shape == tensor.shape Pull Request resolved: pytorch#177498 Approved by: https://github.com/lezcano
Zero strided tensor should have gradients be a zero stride tensor, not an undefined Tensor (implicitly 1). This can cause issues with 2nd order and higher derivatives. It also violates the invariants that grad.shape == tensor.shape Pull Request resolved: pytorch#177498 Approved by: https://github.com/lezcano
…DAIfNoMagmaAndNoCusolver) Kept both skipCUDAIfNoMagmaAndNoCusolver and skipCUDAIfNoMagmaAndNoLinalgsolver in imports (2.11 still has tests using the former). Added skipCUDAIf import. Dropped test_det_backward (requires C++ changes from two unrelated PRs pytorch#171225/pytorch#177498). All 22 decorator swaps from the upstream PR applied as-is. Co-authored-by: Cursor <[email protected]>
Zero strided tensor should have gradients be a zero stride tensor, not an undefined Tensor (implicitly 1). This can cause issues with 2nd order and higher derivatives. It also violates the invariants that grad.shape == tensor.shape