mirror of
https://github.com/deepseek-ai/DeepGEMM.git
synced 2026-11-05 00:47:26 +00:00
[PR #457] [Fix] Honor deterministic algorithms in SM90 bmk,bnk->mn einsum #462
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
deepseek-ai/DeepGEMM#462
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/deepseek-ai/DeepGEMM/pull/457
Author: @LiRunGuo
Created: 9/22/2026
Status: 🔄 Open
Base:
main← Head:deterministic-bmk-bnk-mn📝 Commits (2)
56d6e1cHonor deterministic algorithms in SM90 bmk,bnk->mn einsumad03662Assert an FP32 D in the SM90 bmk,bnk->mn launcher📊 Changes
3 files changed (+50 additions, -5 deletions)
View changed files
📝
csrc/jit_kernels/impls/sm90_bmk_bnk_mn.hpp(+14 -4)📝
deep_gemm/include/deep_gemm/impls/sm90_bmk_bnk_mn.cuh(+6 -1)📝
tests/test_einsum.py(+30 -0)📄 Description
Problem
deep_gemm.einsum('bmk,bnk->mn', ...)returns a different result on every call for the same inputs, even withdeep_gemm.use_deterministic_algorithms(True).On SM90,
sm90_bmn_bnk_mn_gemmsplits thes * kreduction across CTAs (split_factor) and adds each CTA's partial sum into D withfloat2atomicAdd. The order of those additions changes between runs. With DeepGEMMmain(78b6900) on an H200, 50 identical calls give:use_deterministic_algorithms(True)The flag is already honored by the other einsum paths, the BF16 GEMM,
mega_mhcandmega_gate, but not by this one.Fix (SM90)
In deterministic mode, and only when there is more than one split:
[num_splits, m, n]FP32 workspace. Its size is at most aboutnum_sms * 128 * 128floats, sincenum_splits * num_mn_blocksis bounded by the SM count.kUseSplitWorkspacetemplate flag makes each split accumulate into its own slice. Every element then has a single writer, so the atomic additions no longer depend on ordering.split_workspace.sum(0).With the flag off, or with a single split, the generated kernel and launch are the same as before.
The SM100 kernel reduces the splits with TMA reduce-add in the same way, and I left it unchanged because I have no SM100 machine to test on. The same approach should apply there.
Testing (H200, CUDA 13.0, PyTorch 2.11.0+cu130)
test_bmk_bnk_mn_deterministic(SM90 only) fails onmainand passes with this change. It checks 10 identical calls for bitwise equality and compares them with the reference.use_deterministic_algorithms(True)python tests/test_einsum.pypasses.mainThe deterministic mode costs a roughly fixed 12–15 µs for the extra zeroing, reduction and addition. That is about 2x on the smallest problems and 2–11% on the larger ones.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.