Repository navigation
Conversation
…tsandbytes plugin 1. In `_ignore_missing_weights_hook`, iterating over `reversed(incompatible_keys.missing_keys)` and calling `incompatible_keys.missing_keys.remove(key)` on each `"*weight"` entry scans from index 0 of the list on every removal, resulting in O(N^2) time across models with many quantized Linear layers. Replace with an in-place list slice comprehension (`missing_keys[:] = [...]`) to filter missing weight keys in O(N) time while preserving the list instance. 2. In `_Linear8bitLt.to_empty()` and `_Linear8bitLt.reset_parameters()`, the quantized-weight guards checked `self.weight.dtype == torch.uint8` and `isinstance(self.weight, bnb.nn.Params4bit)` (copied from `_Linear4bit`), even though `_Linear8bitLt` uses `bnb.nn.Int8Params` with `torch.int8` storage (`quantize_()` checks `weight.data.dtype == torch.int8` and `isinstance(self.weight, bnb.nn.Int8Params)`). Update both methods in `_Linear8bitLt` to check `bnb.nn.Int8Params` and `torch.int8`. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Parth Vadera <parthvadera@gmail.com>
deep1blue
requested review from
ethanwharris,
justusschock and
tchaton
as code owners
October 22, 2026 07:30
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.
What does this PR do?
Fixes two issues in
src/lightning/fabric/plugins/precision/bitsandbytes.py:In-place$O(N)$ filtering in
_ignore_missing_weights_hook:Previously,
_ignore_missing_weights_hookiterated overreversed(incompatible_keys.missing_keys)and calledincompatible_keys.missing_keys.remove(key)on each"*weight"entry:Because$O(N^2)$ time). Replacing this with in-place slice assignment ($O(N)$ time (reducing 10,000-key filtering from
list.remove(key)always searches linearly from index0, removing elements from the end ofmissing_keysrequires scanning the entire prefix on every removal (incompatible_keys.missing_keys[:] = [key for key in incompatible_keys.missing_keys if not key.endswith("weight")]) preserves themissing_keyslist object identity in401.2 msto0.49 ms, an ~825x speedup).Correct
Int8Params/torch.int8guards in_Linear8bitLt.to_empty()and_Linear8bitLt.reset_parameters():_Linear8bitLt.to_empty()and_Linear8bitLt.reset_parameters()checkedself.weight.dtype == torch.uint8andisinstance(self.weight, bnb.nn.Params4bit)(which are the 4-bit invariants from_Linear4bit), whereas_Linear8bitLtusesbnb.nn.Int8Paramsandtorch.int8storage (as checked in_Linear8bitLt.quantize_()). As a result:to_empty()on an already-quantized_Linear8bitLtlayer (dtype == torch.int8) bypassed theNotImplementedErrorguard._Linear8bitLt.reset_parameters(),linear_init_finished = isinstance(self.weight, bnb.nn.Params4bit)was alwaysFalse, bypassing both the quantizedNotImplementedErrorguard (causingkaiming_uniform_to fail withRuntimeError: "normal_kernel_cpu" not implemented for 'Char') and the post-init re-quantization /_replace_parambranch.Validation
Acknowledgments
Credit and thanks to @carmocca (Carlos Mocholí,
#18655,#19150), @awaelchli (Adrian Wälchli,#19886,#20121), @Borda (Jirka Borovec,#20911), @matthewdouglas (Matthew Douglas,#20956), and @bhimrazy (Bhimraj Yadav,#21858) for designing and maintaining theBitsandbytesPrecisionplugin in Lightning Fabric.