Skip to content

Commit e30d08c

Browse files
committed
Address review: restore kernel comments, remove obsolete fp16 cast warning
- 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.
1 parent c6814fd commit e30d08c

3 files changed

Lines changed: 11 additions & 10 deletions

File tree

bitsandbytes/autograd/_functions.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,6 @@ def forward(
124124

125125
input_shape = A.shape
126126

127-
# Cast A to fp16
128-
if A.dtype != torch.float16 and not _is_compiling():
129-
logger.warning("MatMul8bitLt: inputs will be cast from %s to float16 during quantization", A.dtype)
130-
131127
if len(A.shape) == 3:
132128
A = A.reshape(-1, A.shape[-1])
133129

csrc/kernels.cu

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,9 +1323,13 @@ __launch_bounds__(256, 3) __global__ void kOptimizerStatic8bit1StateBlockwise(
13231323
template <typename T, int THREADS, int SPARSE_DECOMP>
13241324
__launch_bounds__(1024, BNB_MAX_THREADS_PER_SM / 1024) __global__
13251325
void kInt8VectorQuant(T* __restrict__ A, int8_t* out, float* rowStats, float threshold, int rows, int cols) {
1326-
1326+
// One block per row.
1327+
// Threads load column values in a striped arrangement.
1328+
// e.g. t0 reads row[0], row[0+nthreads], ..
1329+
// and t1 reads row[1], row[1+nthreads], ..
1330+
// Each thread will determine its local absmax.
1331+
// We then do a blockwise reduction to determine the row's absmax.
13271332
using BlockReduceT = bnb_cub::BlockReduce<float, THREADS>;
1328-
13291333
__shared__ typename BlockReduceT::TempStorage temp_storage;
13301334
__shared__ float smem_row_absmax;
13311335

@@ -1336,7 +1340,8 @@ __launch_bounds__(1024, BNB_MAX_THREADS_PER_SM / 1024) __global__
13361340
float row_local_absmax = -FLT_MIN;
13371341
for (int i = threadIdx.x; i < cols; i += THREADS) {
13381342
const float absval = fabsf((float)__ldcs(&(row_data[i])));
1339-
1343+
// For sparse decomposition, values outside of the threshold are not to be
1344+
// included when calculating the row's absmax.
13401345
if constexpr (SPARSE_DECOMP) {
13411346
row_local_absmax = fmaxf(row_local_absmax, absval < threshold ? absval : row_local_absmax);
13421347
} else {
@@ -1355,8 +1360,9 @@ __launch_bounds__(1024, BNB_MAX_THREADS_PER_SM / 1024) __global__
13551360
const float scale = __fdividef(127.0f, smem_row_absmax);
13561361
for (int i = threadIdx.x; i < cols; i += THREADS) {
13571362
float val = (float)row_data[i];
1358-
13591363
if constexpr (SPARSE_DECOMP) {
1364+
// For sparse decomposition, we do not want to quantize the outliers.
1365+
// Instead they're zeroed out.
13601366
out[row_id * cols + i] = fabsf(val) < threshold ? __float2int_rn(val * scale) : 0;
13611367
} else {
13621368
out[row_id * cols + i] = __float2int_rn(val * scale);

csrc/ops.cu

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,8 +486,7 @@ template void int8VectorQuant<half>(
486486
half* __restrict__ A, int8_t* out, float* rowStats, float threshold, int rows, int cols, bnb_stream_t stream
487487
);
488488
template void int8VectorQuant<bnb_bfloat16>(
489-
bnb_bfloat16* __restrict__ A, int8_t* out, float* rowStats, float threshold, int rows, int cols,
490-
bnb_stream_t stream
489+
bnb_bfloat16* __restrict__ A, int8_t* out, float* rowStats, float threshold, int rows, int cols, bnb_stream_t stream
491490
);
492491

493492
template int igemmlt<32, 0>(

0 commit comments

Comments
 (0)