Reduce peak GPU memory in Eagle3 online target generation by avoiding an extra logits copy#528
Open
zijiexia wants to merge 2 commits intosgl-project:mainfrom
Open
Reduce peak GPU memory in Eagle3 online target generation by avoiding an extra logits copy#528zijiexia wants to merge 2 commits intosgl-project:mainfrom
zijiexia wants to merge 2 commits intosgl-project:mainfrom
Conversation
Contributor
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
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.
Motivation
This PR fixes an out-of-memory issue in Eagle3 online training caused by an unnecessary full-tensor copy when shifting target logits.
Previously,
generate_eagle3_data()accumulated per-sample logits into a list, concatenated them into a[B, T, V]tensor, and then calledpadding(target_out, left=False)to shift the logits left and append a zero row at the end. For large vocab models, that final padding step materialized another full[B, T, V]allocation and could trigger multi-GB peak memory spikes.This change pre-allocates the final
target_outtensor once and writes the shifted logits directly into it:target_out[idx, :-1] = logits[..., 1:, :]target_out[idx, -1] = 0That preserves the original semantics while removing the extra full-size allocation.
Root Cause
The old implementation created peak memory pressure in two stages:
target_outtensor.padding(target_out, left=False), which internally builds a zero padding tensor and concatenates again, creating another full-sized[B, T, V]tensor.For Eagle3 online training,
Vis the target model vocabulary size, so this copy is extremely expensive. In practice this showed up as OOM duringgenerate_eagle3_data()even though steady-state memory usage was otherwise close to fitting.Modifications
target_outas a Python list of per-sample logits tensors.has_logits = logits_list[0] is not None.target_outwith shape[B, T, V]using the first logits tensor's device and dtype.padding(target_out, left=False)call entirely.Related Issues
Accuracy Test
Benchmark & Profiling
Checklist