Fix int8 offload hook detachment statistics restoration#4044
Open
jiqing-feng wants to merge 1 commit into
Open
Fix int8 offload hook detachment statistics restoration#4044jiqing-feng wants to merge 1 commit into
jiqing-feng wants to merge 1 commit into
Conversation
Signed-off-by: jiqing-feng <jiqing.feng@intel.com>
Contributor
Author
|
Hi @SunMarc . Would you please review this PR? Thanks! |
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
Fix
AlignDevicesHook.detach_hook()so removing offload hooks restores bitsandbytes int8 weights together with their fp16 quantization statistics.Sequential CPU offload stores module weights in
weights_mapand moves parameters to the meta device. For bnb int8 modules, theSCBstatistics are saved as extra state-dict entries instead of regular parameters or buffers.pre_forward()already passed those statistics back intoset_module_tensor_to_device(), butdetach_hook()did not. As a result, removing hooks could restore the int8 weight while leavingweight.SCBon the meta device, causing the next offload pass to fail with:This change centralizes the lookup of int8 fp16 statistics in
AlignDevicesHook._get_fp16_statistics()and uses it from bothpre_forward()anddetach_hook(). The existing forward path keeps the same behavior, while hook removal now materializes int8 weights with their matching statistics.Reproduction
This is a minimal reproduction of the failing sequence: enable sequential CPU offload, remove hooks recursively, then enable sequential CPU offload again.
Expected output: