Skip to content

TT block-float forwards narrow weights and FP32 bias before the final cast #3863

Closed

Description

@Qubitium

Reproduction (current main, daa5dae)

import torch
from gptqmodel.nn_modules.qlinear.tt_blockfloat import TTBlockfloatLinear
from gptqmodel.utils import BACKEND

source = torch.nn.Linear(16, 1)
with torch.no_grad():
    source.weight.zero_()
    source.weight[0, 0] = 1024.0
    source.bias.fill_(-1023.5)

layer = TTBlockfloatLinear(
    bits=8, in_features=16, out_features=1, bias=True,
    backend=BACKEND.TT_BLOCKFLOAT, dtype=torch.float32,
).pack(source)
x = torch.zeros(1, 16, dtype=torch.bfloat16)
x[0, 0] = 1
print(layer.bias.dtype, layer(x).item())
# torch.float32 0.0
print((x.float() @ layer.dequantize(dtype=torch.float32).T + layer.bias).bfloat16().item())
# 0.5

A second FP16 case with all weights 4096, bias -65536, and all-one input returns -inf from layer(x) versus 0 when the packed grid is accumulated with the FP32 bias before the final cast.

Cause

TTBlockfloatLinear.forward narrows the preserved FP32 checkpoint bias to the activation dtype before either kernel or fallback execution; the fallback also dequantizes the packed weight to that dtype before F.linear. The CUDA binding requires bias dtype equal to activation dtype and the HIP binding casts it, so the same precision loss applies to native paths. The recent checkpoint-bias precision fix (#3843) preserves storage dtype, but forward execution discards it.

Expected

Accumulate the block-float grid and stored FP32 bias with sufficient range and precision, then cast the final output to the requested activation dtype. Cover cancellation and range cases for BF16/FP16 on fallback and native paths.

Related tied-head fallback

The tied output head has the same early weight-narrowing problem even without bias. On CPU, construct a TTBlockfloatEmbedding(1, 16, bits=8, dtype=torch.float16) with quantized FP32 grid row [65536, -65536, 0, ...], then call TTBlockfloatTiedHead(embedding) on a half-precision input whose first two entries are 1. TTBlockfloatTiedHead.forward decodes the shared weight to FP16 before its CPU matmul and returns nan; the FP32 grid dot is exactly zero and rounds to FP16 0. This tied-head fallback belongs to the same early-narrowing issue, though its native path has not been tested here.

Activity

  1. changed the title [-]TT block-float forward narrows FP32 bias before low-precision epilogue[/-] [+]TT block-float forwards narrow weights and FP32 bias before the final cast[/+] on Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions