Conversation
Co-Authored-By: Ananth Veluvali <ananth.veluvali@cognition.ai>
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
The default FLCE path (
accum_dtype=None) accumulates the weight gradient per chunk asThis materializes the V×H product twice (a bf16 mm output, then a ~2.0 GB fp32 copy at
llama-3-8B shapes) and re-reads/rewrites
grad_weight: several GB of avoidable HBMtraffic per chunk, O(V·H) regardless of token count. It made default FLCE slower than
the HF
linear+CrossEntropyLossbaseline at all measured sizes and heavier belowBT=8192.
Changes (Triton kernel and chunk geometry untouched):
grad_weightviamm/addmmout=on both accumulation pathsmm, beta=0) instead of accumulating, dropping oneread-modify-write pass over
grad_weightgrad_weight/grad_inputwithempty_like; the loop writes every elementNumerics are equal or better: cuBLAS accumulates the product and
beta*Cin fp32 androunds once, where the old path rounded the product to bf16 before adding.
Overlaps with #1324, which also routes same-dtype fp16/bf16/fp32 accumulation through
addmm out=. This PR additionally skips the first-chunk read-modify-write, drops thezero-fills, and keeps the mixed-dtype fallback. Happy to consolidate the two.
Details
Measured on current
main(2798d08) vs this branch, H100 80GB HBM3, torch2.13.0+cu130 / triton 3.7.1, llama-3-8B shapes (V=128256, H=4096), bf16,
reduction=mean, full pass (fwd+bwd). Standalone script equivalent to
benchmark/scripts/benchmark_fused_linear_cross_entropy.py(same model definitionsand providers), median of
triton.testing.do_bench; each config run twice, runsagreed within ~1–3%.
Default
ligerprovider (accum_dtype=None):After the change the default path matches or beats the HF baseline on latency at
BT ≥ 2048 (previously slower at every size) and uses less peak memory everywhere,
41% less at BT=8192. At BT=1024 it remains ~1 ms slower on latency at equal memory.
The 2.0–2.9 GB memory drop matches the eliminated V×H fp32 product
(128256×4096×4 B ≈ 2.0 GB).
accum_dtype=torch.float32(already on theaddmm(out_dtype=)path) gains 7–16%latency from the beta=0 first chunk and the dropped zero-fills, memory flat; the
BT=8192 row is within noise.
The dispatch layer added in #1416 is unaffected: the default (no
LIGER_KERNEL_IMPL)path and the
_tritonbackend adapter both importLigerFusedLinearCrossEntropyFunctionfrom the patched module;ascend/cute/cutedsl/cutilebackends are opt-in and untouched.Developed with AI assistance (Cognition's Devin: profiling, patch, and benchmark
runs); human-reviewed.
Testing Done
On this branch (current
main2798d08 + this commit), H100 80GB:make test(full suite): passedpython -m pytest test/transformers/test_fused_linear_cross_entropy.py: 141 passed(AMP,
accum_dtype, ce_weight, softcap, z-loss, label smoothing,reduction="none")python -m pytest test/convergence/bf16/test_mini_models.py -k llama3: passedmake checkstyle: cleanHardware Type: H100-80G-HBM3
run
make testto ensure correctnessrun
make checkstyleto ensure code stylerun
make test-convergenceto ensure convergence (llama3 bf16 subset run; full suite not run)