Repository navigation
Conversation
`aten::rms_norm` declares `Tensor? weight=None`, but `rms_norm_composite` gated the weight multiply on `weight_opt.has_value()` alone. A C++ caller that forwards a possibly-undefined Tensor where an optional is expected produces an engaged optional holding an undefined tensor, and that reached `upcasted_result.mul(<undefined>)`, which the autograd layer's `unpack()` rejects with "Expected a proper Tensor but got None (or an undefined Tensor in C++) for argument #1 'other'". The same call shape on `at::layer_norm` works, because `math_native_layer_norm` also checks `.defined()`. The MPS branch of `rms_norm_symint` had the identical has_value()-without-defined() gate and would have handed an undefined weight to `_fused_rms_norm_mps`, so it is fixed here rather than left as a twin of the bug being removed. I have no MPS hardware, so that half is reasoned from the source and left to CI. Test Plan: The failure is only reachable from C++ - Python cannot construct an engaged optional holding an undefined tensor - so the regression test is a gtest in `undefined_tensor_test.cpp`, which `aten/tools/run_tests.sh` already runs. It went there rather than `math_kernel_test.cpp` because that file is built but is in no runner list, so it would not have gated this PR. This machine's Device Guard policy refuses to launch freshly linked gtest binaries, so the assertions were exercised through a `cpp_extension` against a locally built `torch_cpu`. Before: ``` nullopt : ok, numel=6 engaged-but-undefined : has_value=1 defined=0 : THREW -> Expected a proper Tensor but got None ... layer_norm same call : ok, numel=6 ``` After: ``` nullopt : ok, numel=6 engaged-but-undefined : has_value=1 defined=0 : ok, numel=6 layer_norm same call : ok, numel=6 ``` The test's own assertion, and that a real weight is still applied: ``` equal(undef, nullopt) : true max abs diff : 0 weight still applied : true ``` Built with: ``` USE_CUDA=0 BUILD_TEST=1 python -m pip install -e . -v --no-build-isolation ``` `clang-format` 19.1.5 is clean on the changed lines. Developed with AI assistance (Claude). Co-Authored-By: Claude Opus 5 <[email protected]>
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/195574
Note: Links to docs will display an error until the docs builds have been completed. ✅ You can merge normally! (2 Unrelated Failures)As of commit 94e0af8 with merge base 69c9b15 ( CRCR (non-blocking) - The following CRCR downstream CI jobs failed but are non-blocking:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
@pytorchbot label "release notes: nn" "topic: bug fixes" |
|
@Skylion007 this is the @albanD you approved both #121364, which introduced the 🤖 Drafted with Claude Code; I reproduced the failure and ran the checks in the description. |
|
@malfet @Skylion007 - tagging you because you have both touched
The fix adds the missing This was found while reviewing #193936: the C++ CI is green (156 passed) and there is a regression in 🤖 Drafted with Claude Code; I reviewed this before posting. |
|
@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 |
pytorch#195574 made at::rms_norm treat an engaged-but-undefined weight as no weight, so the nullopt conversion and the comment describing the old ATen behavior are no longer needed. RMSNormNoAffine covers that path. Test Plan: On the previous base (7744b78) with pytorch#195574 cherry-picked: ``` build/bin/test_api.exe --gtest_filter=*RMSNorm*:*LayerNorm* ``` 9 tests passed, including ModulesTest.RMSNormNoAffine. Developed with AI assistance (Claude). Co-Authored-By: Claude Opus 5.5 <[email protected]>
aten::rms_normdeclaresTensor? weight=None, butrms_norm_compositegates the weight multiply onweight_opt.has_value()alone. A C++ caller forwarding a possibly-undefined Tensor where an optional is expected produces an engaged optional holding an undefined tensor, and that reachesupcasted_result.mul(<undefined>):at::layer_normaccepts the same call, becausemath_native_layer_normalso checks.defined(). That asymmetry is the bug.The MPS branch of
rms_norm_syminthad the same gate and would have handed an undefined weight to_fused_rms_norm_mps, so it is fixed here rather than left as a twin of the one being removed. I have no MPS hardware; that half is reasoned from the source and left to CI.Test
The failure is only reachable from C++ — Python cannot construct an engaged optional holding an undefined tensor — so the regression test is a gtest in
undefined_tensor_test.cpp, whichaten/tools/run_tests.shalready runs. It went there rather thanmath_kernel_test.cpp, which is built but appears in no runner list and so would not have gated this PR.This machine's Device Guard policy refuses to launch freshly linked gtest binaries, so the assertions were exercised through a
cpp_extensionagainst a locally builttorch_cpu. Same harness before and after:and the test's own assertion, plus a check that a real weight is still applied:
Related
#193936 adds
torch::nn::RMSNormand currently works around this by converting an undefined weight tostd::nulloptbefore callingat::rms_norm. If this lands first, that conversion and its comment can be dropped there.Developed with AI assistance (Claude); I reproduced the failure, wrote the fix and ran the checks above.