profile: measure the chunked_cross_entropy memory spike and find its source (#2190) [2/3] - #2311
Open
OnePunchMonk wants to merge 1 commit into
Open
profile: measure the chunked_cross_entropy memory spike and find its source (#2190) [2/3]#2311OnePunchMonk wants to merge 1 commit into
OnePunchMonk wants to merge 1 commit into
Conversation
OnePunchMonk
requested review from
andyland,
k223kim,
lianakoleva and
t-vi
as code owners
August 28, 2026 08:25
This was referenced Aug 28, 2026
Open
Contributor
Author
|
The failing tests.yaml / Lit Job check is not a lint failure. Looking at the CI log, it's test_serve_with_generate_strategy[tensor_parallel] in tests/test_serve.py. The server does start (NCCL init, model load, and "Application startup complete" all show up in the log), it just finishes right around the 30s mark, and the test's polling loop only waits 30s total before asserting failure. This PR doesn't touch test_serve.py or serving code, and #2312 hits the identical failure on a completely different diff, so this looks like a pre-existing timeout that's too tight for the 2-GPU tensor_parallel case on this runner, not something caused by 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.
Part of #2190.
Part 2 of 3, split out of #2300 so each piece is reviewable on its own. This is the "profile it and find the actual source" ask from #2190.
chunked_cross_entropyhas a comment saying the memory spike is suspected to come from the backward pass, but nobody had measured it. This addslitgpt/scripts/profile_memory.py, which sweepschunk_sizeand profiles the forward and backward withtorch.profiler(profile_memory=True,record_shapes=True) on CPU or CUDA, and commits the results underdocs/profiling/.What the profile shows
On a T4 at
B=2, T=2048, V=32000, peak CUDA memory allocated drops from 2097MB unchunked to about 1580MB for anychunk_sizein[32, 512], roughly 25 percent, and it is flat across that whole range at this scale. The CPU sweep agrees.The op table pins the spike on
aten::_log_softmaxandaten::_log_softmax_backward_data, each holding a 500MB CUDA allocation at the same time in the unchunked case. So the comment's suspicion was right.The memory timelines make the mechanism visible: unchunked allocates one block that grows 500MB to 980MB to 1950MB and is not freed until the whole backward finishes, while chunking turns that into a sawtooth of smaller allocate/free cycles that never all coexist.
Three follow-up experiments are included too:
torch.compilevs eager, an end to end training step (to check how much of a real step this actually accounts for), and a sweep of the budget formula that part 3 uses.Notes
Related: #2310 (KV cache) and #2312 (tunable chunking).
AI Usage Disclaimer