Repository navigation
Conversation
Keep the SCB metadata when generic parameter conversion omits a target device. Signed-off-by: Afloat <ShuffleMonkey@163.com>
This branch has not been deployed
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.
Problem
For a quantized
Int8Params,to()creates a new parameter and preserves its packed data, but only copiesSCBwhen the caller explicitly supplies a device. Valid no-device calls such asweight.to(),weight.to(dtype=torch.int8), andweight.to(non_blocking=True)therefore discard the row scales.Replacing an embedding or a linear layer's weight with that result breaks its first quantized forward pass.
Change
Carry the existing
SCBinto the new parameter before handling an explicit device move. Continue bindingCBto the returned parameter's data, and forwardnon_blockingwhen moving the scales.Validation
Embedding8bitandLinear8bitLtcases replace the weight before the first forward, so cached matmul statistics cannot hide lost metadata. Their outputs, downstream gradients, and two SGD updates match the unchanged models exactly.Exact production commit:
eeaa2f804eda7d04d4326097e6140429b01e247a.Validation: https://github.com/Afloat16/bitsandbytes/actions/runs/43401310219