perf(ce): single-shot dx_y gradient correction#1268
Open
justinhh4 wants to merge 2 commits into
Open
Conversation
bd42e40 to
5b13f51
Compare
Collaborator
|
@justinhh4 since #1266 and #1267 are merged, we can try merging this now. Can you update the PR description reporting just the benefits from single shot dx_y improvement? This will help us evaluate the individual impact of this change. |
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.
PR3: CE
exp2 + num_warps + dx_y— B200 + H100 benchmarksOptimization measured against the frozen original baseline (
v0_base, == upstream HEAD). Correctness: full CE suite (177 cases, bf16+fp32, weight/softcap/smoothing/z_loss/ignore_index combos) passes.What & why
The CE gradient subtracts 1 only at the true-class index
y. Instead of a per-elementtl.where(X_offsets != y, …)across the whole vocab (in both pass-2 paths), store the plain softmax gradient and apply one scalar correction at indexyafter the loop.O(V)times per row just to touch a single element; the post-loop store makes itO(1). Atl.debug_barrier()orders the loop's in-place writes before the read-back aty.Headline shape (BT=8192, V=128256, full fwd+bwd)
Across context length (V=128256, BT 1024–65536)
Figures
Latency vs context length and vs vocab, baseline vs this PR, on H100 and B200.