Add FP32 accumulation option to fused scaled cross entropy - #1391
Open
yueyiming2009 wants to merge 1 commit into
Open
Add FP32 accumulation option to fused scaled cross entropy#1391yueyiming2009 wants to merge 1 commit into
yueyiming2009 wants to merge 1 commit into
Conversation
Add an opt-in accum_dtype for chunked weight-gradient accumulation in the cuTile and PyTorch fallback implementations, with correctness tests, benchmark coverage, and documentation. 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
accum_dtypeto fused scaled cross entropy so chunked weight gradients can accumulate in FP32 before casting back to the parameter dtype.cutile-accum-fp32benchmark provider, and usage documentation.Details
BF16
grad_weightwas previously rounded after every token chunk because the running accumulator inheritedweight.dtype. Withaccum_dtype=torch.float32, supported CUDA systems usetorch.addmm(..., out_dtype=torch.float32)to avoid that chunk-boundary precision loss. The tradeoff is an additionalV x HFP32 buffer.On an NVIDIA B200 at
M=8192, H=4096, V=131072, FP32 accumulation added 0.7% full-pass latency and 2048 MB peak memory. A chunk-count sweep showed the gradient error improvement growing from 1.34x at 16 chunks to 7.31x at 1024 chunks.Testing Done
make testto ensure correctnessmake checkstyleto ensure code stylemake test-convergenceto ensure convergencetest/transformers/test_fused_linear_scaled_cross_entropy.pywithLIGER_KERNEL_IMPL=cutileon B200: 36 passedruff checkandruff format --checkon all changed Python filescutileversuscutile-accum-fp32on B200 for speed, memory, and precision🤖 Generated with GitHub Copilot CLI