feat(cutile): chunk FLCE with Triton sizing and cuBLAS GEMMs - #1455
Draft
vaibhavjindal wants to merge 5 commits into
Draft
vaibhavjindal wants to merge 5 commits into
vaibhavjindal wants to merge 5 commits into
Conversation
Reuse Triton default token-chunk geometry through a private helper without adding a public chunk-size parameter. Bound cuTile logits/statistics workspace, use cuBLAS for all GEMMs, retain FP32 dW until upstream scaling, and preserve legacy low-level helpers. Enable SM100 alongside SM90 and cover numerical, memory, gradient-mask, and older-Torch fallback behavior. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Rename the existing FLCE suite to reflect its Hopper SM90 and Blackwell SM100 coverage; test contents and architecture guards are unchanged. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Use BF16 weight-gradient accumulation by default and FP32 when explicitly requested. Normalize logits gradients before the cuBLAS gradient GEMMs, cast completed dW at the end of forward, and apply only upstream scaling in backward without mutating saved gradients. Preserve legacy raw helper behavior and cover accumulator dtype, rounding, fallback, normalization, and retained-backward semantics. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Allocate fresh logits per chunk and copy temporary dX results into zero-initialized output storage. Accumulate dW into a zero-initialized buffer on every chunk and retain naturally used transpose views like Triton. Defer workspace reuse and direct-output optimizations to a joint follow-up. Preserve BF16 operands under ambient autocast and keep the aligned precision and legacy helper contracts. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add chunked cuTile FLCE on Hopper SM90 and Blackwell SM100, using cuBLAS for all matrix multiplications and matching Triton's current chunking, precision, and forward-allocation baseline. This PR is based on main after #1454 and adds no public
chunk_sizeargument.Matched baseline
inc = ceil(V / (16 * H)),chunk = min(N, next_pow2(ceil(N / inc))).input_chunk @ weight.T; CE overwrites that tensor with dZ. Previous/current chunks can overlap through live gradient/transpose views, as in Triton.dZ @ weightresult copied into a zero-initialized gradient buffer, not a direct GEMM output write.addmmon every chunk, including the first. The meaningful transposed-gradient operand is held in the loop just as in Triton.accum_dtype=Noneor BF16 uses a BF16 running dW buffer; explicit FP32 uses an FP32 buffer and casts the completed gradient to BF16 at the end of forward. Mean normalization is applied in FP32 to dZ before the BF16 store and gradient GEMMs. Backward applies only upstream scaling, out-of-place for retained-graph safety.Deliberately deferred: reusable logits storage, direct dX output writes, and first-chunk initialization shortcuts will be introduced together for Triton and cuTile in a separate optimization PR. There are no artificial padding allocations or unused references to force matching memory numbers.
Memory comparison
Reference shape: N=8192, H=4096, V=128256, BF16 inputs and weights, 4096-row default chunks on both sides. Full forward + backward, mean reduction, upstream 1.0. Values are warmed incremental peak allocated MiB above inputs, not total or reserved memory.
The remaining approximately 1 MiB is cuTile's CE statistics/counter scratch, not a different logits or gradient-buffer allocation strategy. Actual allocation traces confirm two overlapping logits chunks and the same temporary dX pattern in both implementations. Older measurements showing a cuTile-only workspace-memory advantage describe the superseded allocation implementation and should not be used for this revision.
Scope and compatibility
BF16 input/weight, mean/sum, and None/BF16/FP32 accumulation are supported. CE reductions need not be bitwise identical to Triton and optional features such as bias, class weights, z-loss, label smoothing, softcap and token scaling remain unsupported on this cuTile path. The original exported unchunked raw-dZ/7-argument backward helpers retain their compatibility behavior; normal training uses the aligned chunked path. No custom cuTile GEMM remains.
Testing Done
make checkstylepasses.5f1f7b9.make testandmake test-convergencewere not run; the relevant suites above were run.The architecture-neutral test file is
test/cutile/test_fused_linear_cross_entropy.py. User-local setup.py pins are not included.