From 6743bfb1c125fb91da402b7cbfa2d4d8079566e7 Mon Sep 17 00:00:00 2001 From: emme1t <149944796+emme1t@users.noreply.github.com> Date: Sat, 21 Nov 2026 00:47:21 -0800 Subject: [PATCH] Document CUDA kernel rounding in matmul_4bit --- bitsandbytes/autograd/_functions.py | 7 +++++++ docs/source/reference/nn/linear4bit.mdx | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/bitsandbytes/autograd/_functions.py b/bitsandbytes/autograd/_functions.py index 8a069bd10..a155d96a6 100644 --- a/bitsandbytes/autograd/_functions.py +++ b/bitsandbytes/autograd/_functions.py @@ -411,6 +411,13 @@ def matmul_4bit( out: Optional[torch.Tensor] = None, bias: Optional[torch.Tensor] = None, ): + """Apply a linear transformation to `A` using the packed 4-bit weights `B`. + + On CUDA, the input shape, GPU architecture, and dtype influence whether the + operation uses a fused kernel or dequantizes the weights before calling + `torch.nn.functional.linear`. Floating-point rounding can differ between + these paths, including when a change in batch size switches kernels. + """ if quant_state is None: raise ValueError("quant_state is required") if len(quant_state.shape) != 2: diff --git a/docs/source/reference/nn/linear4bit.mdx b/docs/source/reference/nn/linear4bit.mdx index 7630236c9..44a678ab1 100644 --- a/docs/source/reference/nn/linear4bit.mdx +++ b/docs/source/reference/nn/linear4bit.mdx @@ -21,3 +21,7 @@ [[autodoc]] bitsandbytes.nn.Params4bit - __init__ + +## matmul_4bit + +[[autodoc]] bitsandbytes.matmul_4bit