Repository navigation
perf: avoid repeated INT8 cast-warning records - #2127
Open
yfukuda-oqc wants to merge 2 commits into
Open
yfukuda-oqc wants to merge 2 commits into
yfukuda-oqc wants to merge 2 commits into
Conversation
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
MatMul8bitLt.forwardlogs a warning on every non-FP16 eager call. Repeated FP32 or BF16 inputs therefore construct repeatedLogRecordobjects, even when a downstream handler discards duplicate messages.Change
Emit the cast warning once per input dtype per process. Keep the existing warning text and level, and preserve the FP16 intermediate cast and all quantization and autograd operations.
A bitsandbytes-owned set tracks the warned dtypes. A lock serializes first emission for concurrent callers; subsequent calls return before acquiring the lock or constructing a record. Calls with WARNING disabled do not consume the first warning. The existing compilation guard remains in place.
This introduces no public API. Related: #2031 addresses a different 4-bit warning; #1985 proposes native BF16 quantization, which changes the numerical path.
Validation
Tested on Windows 11, Python 3.12.16, Torch 2.8.0+cu128, CUDA 12.8, and an NVIDIA GeForce RTX 4060 Laptop GPU (8 GiB, driver 617.42).
int8_double_quant, which this backend does not implement.rtol=0,atol=0.torch.compile(backend="eager", fullgraph=True)with frozen, prequantized weights preserves repeated forward results and input gradients on CPU/CUDA without emitting cast warnings.Baseline Python revision:
a616886cacf86701514f0cb1d6be760f967481c0. An additional local comparison loaded that baseline source into a separate module and compared 12 CPU/CUDA cases over three momentum-SGD updates each. All 288 output, gradient, parameter and momentum-buffer comparisons matched exactly. This supplemental comparison is separate from the committed regression suite.Both baseline and candidate used
libbitsandbytes_cuda128.dllfrom the official bitsandbytes 0.50.2 Windows wheel (SHA256391825688f575c1eeed41c84441ef0b94f5b05c4089231b7125f27ecf0a44ce7). The Python package was imported from the source checkout; no native code changed or new native build was used.The full platform suite, inductor/CUDA graphs, multiple GPUs and bitsandbytes-specific optimizer comparisons were not exercised. No end-to-end training speedup is claimed.