fix(ttx/npu): keep SwiGLU intermediate computations in FP32 - #461
Conversation
Claude Code ReviewVerdict: Request changes -- The a5 backward kernel has duplicated/leftover statements that will reintroduce the low-precision path and likely fail to compile or produce wrong results. SummaryKeeps the SiLU/product intermediate in fp32 in the NPU SwiGLU forward and backward, rounding only on the store, and adds a bitwise-equality accuracy test against the fp32 reference. The a5 variant's backward edit is incomplete and contains leftover code from the previous version. Must fix
SuggestionsSuggestions (2)
NitsNits (1)
Notes
|
Claude Code ReviewVerdict: Approve -- Fixes a real precision bug by keeping SiLU/derivative intermediates in fp32 until the final store; backward math is also simplified correctly. SummaryThe change removes premature down-casts in the SwiGLU forward and backward NPU kernels so the SiLU intermediate and derivative factor stay in fp32 until stored. The backward Must fixNone. Suggestions (2)
Nits (2)
Notes
|
| swiglu = MojoSwiGLU() | ||
| actual = swiglu(gate, up) | ||
| expected = (torch.nn.functional.silu(gate.float()) * up.float()).to(gate.dtype) | ||
| torch.testing.assert_close(actual, expected, atol=0, rtol=0) No newline at end of file |
There was a problem hiding this comment.
Is bitwise equality required here?
Claude Code ReviewVerdict: Comment -- Correct fix to keep SiLU/backward intermediates in fp32, but there's duplicated code across a2/a5 and the test's docstring claims bitwise equality while the assertion uses a loose tolerance. SummaryThe PR changes the NPU SwiGLU forward and backward kernels to keep the SiLU (and dc, b) intermediates in fp32 and only round at the store, matching the reference torch/bumi contract. It also simplifies the backward Must fixNone. SuggestionsSuggestions (3)
NitsNits (1)
Notes
|
Claude Code ReviewVerdict: Approve -- Improves numerical precision by keeping SwiGLU intermediates in fp32 before the final store; kernels and math look correct. SummaryThe PR keeps the SiLU/SwiGLU forward and backward intermediates in fp32 (promoting Must fixNone. Suggestions (2)
Nits (2)
Notes
|
No description provided.