Repository navigation
Guard fused MoE auxiliary loss integer offsets - #3569
arcusbuilds wants to merge 7 commits into
Conversation
Signed-off-by: Srijan Keshri <212402043+arcusbuilds@users.noreply.github.com>
[Medium impact] The PR appears safe to merge. SummaryThe PR guards fused MoE auxiliary loss shapes and fixes arithmetic at the largest accepted shape.
The previous overflow finding is fixed. No new actionable issues were found. Reviews (7) · Last reviewed commit: "Use 64-bit loop counters in fused MoE au..." · Reviewed by Greptile |
denera
left a comment
There was a problem hiding this comment.
Thanks for the PR!
It looks good to me overall. Just two nits:
- Unnecessary skip condition on CUDA GPU presence.
fused_moe_aux_loss.cuneeds#include <climits>forINT_MAX. This currently comes in transitively from another header, but as a matter of code style and header safety, we include it explicitly in other fused MoE/top-K files too. This one should adopt the same approach.
Co-authored-by: Alp Dener <adener@nvidia.com> Signed-off-by: Srijan Keshri <212402043+arcusbuilds@users.noreply.github.com>
|
Actually, I have a different concern - if the problem is that the shapes could exceed the int32 maximum then we should actually make the kernel work with int64/size_t for the variables that could overflow. |
Signed-off-by: Srijan Keshri <212402043+arcusbuilds@users.noreply.github.com>
|
Extended the kernels to use int64_t indexing instead of rejecting shapes above INT_MAX. |
@ptrendx I took a closer look across the entire fused router stack of kernels and I would argue that #3568 is NOT actually a real bug. The The reported bug says:
So this bug was never actually observed in execution, and it couldn't have been in a pure-TE implementation anyway because our top-k and score kernels will never feed a shape into aux loss that would overflow. If we want to make our fused router accept Otherwise, I think the right approach here is to simply add the same @arcusbuilds In local testing, I'm seeing a forward pass perf difference between the old int32 and the new int64 implementations. I believe this is because the compiler is unrolling the int64 loop but not unrolling the int32. Could you add |
Signed-off-by: arcusbuilds <srijankeshri007@gmail.com>
|
@denera Added |
|
@arcusbuilds After internal discussion about this, we're going to move forward with the original recommendation of rejecting Effort to support int64 max sizes in the fused router should be deferred to a separate PR because it's going to have to touch ALL of the fused router kernels, not just aux loss. |
Match the other fused router kernels, which reject num_tokens * num_experts > INT_MAX. Keep #pragma unroll 4 on the forward row loops. Signed-off-by: arcusbuilds <srijankeshri007@gmail.com>
Shapes at the INT_MAX guard (e.g. INT_MAX x 1) overflowed the int loop counters on their last increment and the backward grid-size math. Flattened offsets stay 32-bit, which the guard bounds. Signed-off-by: arcusbuilds <srijankeshri007@gmail.com>
|
@denera Reverted the int64 change and brought back the While testing the limit I found that a shape like |
denera
left a comment
There was a problem hiding this comment.
LGTM! We'll merge after a clean pipeline (which is going to be slightly delayed because of some ongoing infra issues at the moment).
Description
The fused MoE auxiliary loss kernels use 32-bit flattened offsets. Reject shapes above
INT_MAXin both forward launchers and the backward launcher before launching a kernel.Fixes #3568
Type of change
Changes
num_rows * num_colswith 64-bit arithmetic in all three launchers.INT_MAXelements gives the right result on each path.Verification
pre-commiton both changed files: all hooks passed.fused_moe_aux_loss.cuagainst stub headers and ran it on an RTX 2000 Ada (8 GB). AtINT_MAX x 1, before the counter change both forward paths hit an illegal memory access and backward failed to launch. After it, all three return the right result. Kernel times in ncu at base clocks are within ±1.3% of the int32 version.__uint128_tcode), so the new PyTorch tests haven't run yet. CI covers that.Checklist