Repository navigation
Conversation
|
Thanks for contributing to TorchTPU, @Kaap10! 🔥 To ensure smooth code reviews, we kindly ask authors and reviewers to follow the process documented in https://github.com/google-pytorch/torch_tpu/blob/main/CONTRIBUTING.md#code-reviews. Happy hacking! |
ghpvnist
left a comment
There was a problem hiding this comment.
Thanks for the contribution! Added a few comments.
Refine the size mismatch error message in addmv_aten_kernels.cc to include all operand shapes, and update reviewer attribution to gunhyun in tests/errors_test.py per review comments on google-pytorch#6011.
|
Thanks for the review - @ghpvnist I have addressed all the comments:
Ready for another look whenever you have time! |
|
|
||
| with et.assert_raises_message( | ||
| RuntimeError, | ||
| tpu="""addmv(): expected the first argument to be a vector or scalar (0D or 1D tensor), got 2D tensor""", |
There was a problem hiding this comment.
Can we swap "vector" and "scalar" to match the order of "0D or 1D"?
There was a problem hiding this comment.
Done, swapped to "scalar or vector".
|
|
||
| with et.assert_raises_message( | ||
| RuntimeError, | ||
| tpu="""addmv(): expected arguments shapes [5], [2, 3], [3] to have compatible shapes, got 5 vs 2 which is not compatible""", |
There was a problem hiding this comment.
Grammar nit: "arguments shapes" => "argument shapes"
There was a problem hiding this comment.
Done, updated to "argument shapes".
|
|
||
| with et.assert_raises_message( | ||
| RuntimeError, | ||
| tpu="""addmv(): expected arguments shapes [5], [2, 3], [3] to have compatible shapes, got 5 vs 2 which is not compatible""", |
There was a problem hiding this comment.
Nit: simplify "have compatible shapes" to "be compatible"?
Then we can drop " which is not compatible" as it's obvious.
There was a problem hiding this comment.
Done, simplified to "to be compatible, got 5 vs 2".
zhanyong-wan
left a comment
There was a problem hiding this comment.
Please fix the CI errors.
c98da2a to
0092530
Compare
Fixed. Before: << " to be compatible, got " << self.size(0) << " vs "
<< mat.size(0);After: << " to be compatible, got " << self.size(0) << " vs " << mat.size(0);Verified locally with clang-format. |
|
@ghpvnist , the imported CL fails in internal testing. Could you fix up cl/1010873988 to get this landed? Thanks. |
| RuntimeError, | ||
| tpu="""addmv(): expected the first argument to be a scalar or vector (0D or 1D tensor), got 2D tensor""", | ||
| gpu="""vector + matrix @ vector expected, got 2, 2, 1""", | ||
| message_reviewed_by="gunhyun", |
There was a problem hiding this comment.
There's a rebase conflict here and recently there was an api change to remove the message_reviewd_by parameter. Could you rebase to head and remove this field?
There was a problem hiding this comment.
Done, rebased onto latest head and removed the message_reviewed_by parameter from the error tests.
Also updated the error macro registry in tests/error_coverage_data.yaml.
Fixes google-pytorch#6010 Validate that self is a scalar or vector (dim <= 1) and that when dim == 1, its length matches mat.size(0) or is 1 in ValidateAddmvInputs before dispatching to Addmv. This prevents silent execution on invalid shapes when beta=0 and unhandled StableHLO broadcast failures when beta!=0. Add test coverage in tests/errors_test.py.
Refine the size mismatch error message in addmv_aten_kernels.cc to include all operand shapes, and update reviewer attribution to gunhyun in tests/errors_test.py per review comments on google-pytorch#6011.
0092530 to
64b04d8
Compare
Description
Fixes #6010
torch.addmv(self, mat, vec)validates thatmat.dim() == 2,vec.dim() == 1, andmat.size(1) == vec.size(0)incsrc/ops/addmv/addmv_aten_kernels.cc. However,ValidateAddmvInputsperformed no dimension or shape validation onself:selfis a scalar or vector (self.dim() <= 1).selfis 1-D, it omitted validating that its length matchesmat.size(0)(or is1for singleton broadcast).This caused two issues:
beta=0:Addmvexecutes theif (beta.IsZero())branch which completely dropsselfand delegates toBuildAddmvShloBetaZero. Becauseselfwas never validated inValidateAddmvInputs, invalid inputs (e.g. 2D/3D tensors or mismatched 1D lengths) silently succeeded on TPU, whereas PyTorch CPU/CUDA raisesRuntimeError.beta != 0: Incompatible shapes failed deep inside StableHLO lowering withfailed to broadcast tensor: ...instead of a standard PyTorchRuntimeError.This PR:
self.dim() <= 1validation inValidateAddmvInputs.self.size(0) == 1 || self.size(0) == mat.size(0)length validation for 1-DselfinValidateAddmvInputs.tests/errors_test.py(test_addmv_not_a_vector_or_scalarandtest_addmv_size_mismatch) covering bothbeta=1andbeta=0.Test Plan
ruff check tests/errors_test.py(all checks passed with 0 errors).csrc/ops/addmv/addmv_aten_kernels.ccstrictly adhere to <= 80 columns.beta=1andbeta=0.