fix(gpt_oss): free quantized expert tensors per-layer to reduce peak memory#2149
Open
stanley1208 wants to merge 2 commits intoNVIDIA-NeMo:mainfrom
Open
fix(gpt_oss): free quantized expert tensors per-layer to reduce peak memory#2149stanley1208 wants to merge 2 commits intoNVIDIA-NeMo:mainfrom
stanley1208 wants to merge 2 commits intoNVIDIA-NeMo:mainfrom
Conversation
Pop each layer's blocks/scales out of layer_name_to_quantized_weights before producing its dequantized output, so the quantized side is freed per-iteration instead of being pinned for the full loop. Reduces peak memory during GPT-OSS load. Behavioral contract is unchanged. Adds a regression test using weakrefs to verify mid-loop GC. Refs NVIDIA-NeMo#1274 Signed-off-by: stanley1208 <stanley.mei08@gmail.com>
0c2682f to
b471951
Compare
Contributor
|
/ok to test b471951 |
Contributor
|
Hi @stanley1208 , sorry to be bothering you with linting, but can you run commit + push? so that the lint does not compalin. Thank you & sorry for the trouble. |
Signed-off-by: stanley1208 <stanley.mei08@gmail.com>
Contributor
|
/ok to test 16fded5 |
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
Step 1 of #1274.
_dequantize_block_scale_tensorswas holding every layer's quantized blocks/scales alive until the dequant loop finished, doubling peak memory during GPT-OSS load. This pops each entry from the local mapping right before dequantizing. No behavior change.Originally I had a Step 2 too (CPU dequant fallback), but @akoumpa flagged the runtime cost on large models and that it doesn't help on DGX Spark unified memory. Dropped.
Won't fully close the 2× 48GB GPT-OSS 20B OOM on its own, dequantized BF16 tensors still accumulate in
state_dict. I'll measure post-merge and come back with a streaming approach if needed.Tests
26 existing tests in
tests/unit_tests/models/gpt_oss/test_gptoss_state_dict_adapter.pypass. Newtest_dequantize_frees_quantized_between_iterationsusesweakrefto assert layer N's tensors are GC-able when layer N+1 starts. Confirmed it fails without the fix.Refs #1274