Skip to content

[BugFix][Engram] Support non-divisible SM90 block counts#2

Closed
JayceSu98 wants to merge 1 commit into
mainfrom
jayce/engram-sm90-nondivisible-blocks
Closed

[BugFix][Engram] Support non-divisible SM90 block counts#2
JayceSu98 wants to merge 1 commit into
mainfrom
jayce/engram-sm90-nondivisible-blocks

Conversation

@JayceSu98

Copy link
Copy Markdown
Owner

Context

TileKernels declares NVIDIA SM90 support, but engram_grad_w_reduce_kernel.py assumed the persistent block count can always be split into exactly four batches:

num_batches = 4
assert num_persistent_blocks % num_batches == 0

That is not true for every supported SM90 GPU. H100 PCIe exposes 114 SMs, so a persistent-block count derived from the SM count can fail this assertion before the kernel reaches code generation or execution.

Fix

Choose the largest batch count in [4, 3, 2, 1] that divides num_persistent_blocks.

This preserves the original four-batch behavior whenever it is valid, while allowing other supported SM90 block counts to run with the same persistent reduction structure.

Why this is a TileKernels fix

The failure comes from a TileKernels launch-shape assumption, not from a backend-specific compiler issue. A supported SM90 device can have a valid SM count that is not divisible by four, so the kernel should pick a compatible batch split instead of rejecting the configuration.

Validation

Validated as part of the H100 PCIe CuTeDSL full correctness and benchmark run after the matching TileLang CuTeDSL fixes were applied.

Local sanity checks for this split branch:

  • git diff --check origin/main..74b4d17
  • ruff check on the changed TileKernels Python files

The README declares SM90 GPUs as supported, but the Engram grad-w reduce kernel hard-coded four persistent batches and asserted that the persistent block count was divisible by four.

That assumption is not true for all SM90 parts. For example, H100 PCIe exposes 114 SMs, so the CUDA/CuTeDSL full test path can fail before code generation reaches the actual kernel logic.

Choose the largest batch count up to four that divides the persistent block count. This keeps the original four-batch layout when it is valid, while allowing other SM90 block counts to use the same persistent kernel shape without tripping the launch-time assertion.

Co-authored-by: dingsg <shengge.ding@enflame-tech.com>
@JayceSu98

Copy link
Copy Markdown
Owner Author

Duplicate fork-local PR. The Engram fix is already tracked upstream as deepseek-ai#17.

@JayceSu98 JayceSu98 closed this Jun 12, 2026
@JayceSu98 JayceSu98 deleted the jayce/engram-sm90-nondivisible-blocks branch June 12, 2026 06:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant