Skip to content

Add BF16 support for int8_vectorwise_quant / LLM.int8 activation quant#1985

Open
kru2710shna wants to merge 2 commits into
bitsandbytes-foundation:mainfrom
kru2710shna:feature/int8-bf16-vectorwise-quant
Open

Add BF16 support for int8_vectorwise_quant / LLM.int8 activation quant#1985
kru2710shna wants to merge 2 commits into
bitsandbytes-foundation:mainfrom
kru2710shna:feature/int8-bf16-vectorwise-quant

Conversation

@kru2710shna

Copy link
Copy Markdown

Templates int8VectorQuant on T and adds bf16 kernel instantiations plus a cint8_vector_quant_bf16 C ABI entry point, mirroring the existing gemm_4bit_inference_naive fp16/bf16/fp32 pattern. The blockwise absmax reduction now accumulates in float rather than T: required for bf16 to compile cleanly and slightly improves fp16 accuracy (rowStats was already float, so downstream is unaffected). Removes the forced A.to(torch.float16) casts in MatMul8bitLt so bf16 activations quantize natively.

Closes #1868.

Comment thread csrc/kernels.cu
Comment on lines -1329 to -1334
// One block per row.
// Threads load column values in a striped arrangement.
// e.g. t0 reads row[0], row[0+nthreads], ..
// and t1 reads row[1], row[1+nthreads], ..
// Each thread will determine its local absmax.
// We then do a blockwise reduction to determine the row's absmax.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this comment removed?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not intentional. These got dropped when I rewrote the kernel body for float accumulation. They're accurate and unrelated to the change, so I will restored them verbatim in the next commit

Comment thread csrc/kernels.cu
Comment on lines -1370 to -1371
// For sparse decomposition, we do not want to quantize the outliers.
// Instead they're zeroed out.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove this comment?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same cause as above, accidental during the float-reduction rewrite. Restored. Thanks for catching both.

Comment thread bitsandbytes/autograd/_functions.py Outdated
Comment on lines 127 to 130

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This warning would likely no longer apply.

@matthewdouglas

Copy link
Copy Markdown
Member

I think it would be worthwhile to update some of the other relevant tests to exercise the new bf16 path. E.g. in test_functional.py, test_linear8bit.py, test_modules.py, test_autograd.py where appropriate.

@kru2710shna

Copy link
Copy Markdown
Author

Will do
I'll add bf16 coverage to the higher-level tests (test_functional.py, test_linear8bit.py, test_modules.py, test_autograd.py) in a follow-up commit on this branch.

Templates int8VectorQuant on T and adds bf16 kernel instantiations plus a
cint8_vector_quant_bf16 C ABI entry point, mirroring the existing
gemm_4bit_inference_naive fp16/bf16/fp32 pattern. The blockwise absmax
reduction now accumulates in float rather than T: required for bf16 to
compile cleanly and slightly improves fp16 accuracy (rowStats was already
float, so downstream is unaffected). Removes the forced A.to(torch.float16)
casts in MatMul8bitLt so bf16 activations quantize natively.

Closes bitsandbytes-foundation#1868.
…rning

- Restore explanatory comments in kInt8VectorQuant that were dropped during
  the float-accumulation rewrite (striped-load pattern, sparse-decomp absmax,
  outlier zeroing).
- Remove the 'inputs will be cast to float16' warning in MatMul8bitLt, which
  no longer applies now that the forced fp16 cast is gone.
@kru2710shna kru2710shna force-pushed the feature/int8-bf16-vectorwise-quant branch from e30d08c to cdd9e23 Compare July 7, 2026 09:21
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Question: intentional FP16-only path for int8_vectorwise_quant / LLM.int8 activation quant? (BF16 support + removing casts)

2 participants