Add CUDA sync + NaN/Inf check after each expert GEMM in grouped kernel

This commit is contained in:
2026-05-14 11:27:58 +00:00
parent 1dfe5ffd05
commit c016e66e23

View File

@@ -79,6 +79,15 @@ def cutlass_grouped_nvfp4_gemm(
M_expert, N, K,
) # (M_expert, N) bfloat16
# Check for CUDA errors after each expert GEMM
err = torch.cuda.current_stream().synchronize()
# Validate output
if torch.isnan(expert_out).any() or torch.isinf(expert_out).any():
if MEGA_MOE_DEBUG:
print(f"[cutlass_grouped_gemm] WARNING: expert {e} produced NaN/Inf, skipping")
continue
# Scatter back with routing weights
for t_idx, token_idx in enumerate(token_indices):
for k_idx in range(num_topk):