Skip to content
This repository was archived by the owner on Feb 24, 2026. It is now read-only.
This repository was archived by the owner on Feb 24, 2026. It is now read-only.

Output wrong result when using W2A8 #316

Description

test.zip

The W2A8 fails the assert_close test. Bitblas version is 0.1.0.post

Code:

importtorchimportbitblasimporttorch.nnasnn# enabling debug outputN=4096K=2560importpicklewithopen('log.bin', 'rb') asf:
loaded_tensors=pickle.load(f)
input_tensor, weight_tensor=loaded_tensorsprint(input_tensor.size())
print(input_tensor.max())
print(input_tensor.min())
print(weight_tensor.size())
print(weight_tensor.max())
print(weight_tensor.min())
bitblas.set_log_level("Info")
matmul_config=bitblas.MatmulConfig(
# M=1, # M dimensionN=N, # N dimensionK=K, # K dimensionA_dtype="int8", # activation A dtypeW_dtype="int2", # weight W dtypeaccum_dtype="int32", # accumulation dtypeout_dtype="float32", # output dtypelayout="nt", # matrix layout, "nt" indicates the layout of A is non-transpose and the layout of W is transposewith_bias=False, # bias# configs for weight only quantizationgroup_size=None, # setting for grouped quantizationwith_scaling=False, # setting for scaling factorwith_zeros=False, # setting for zeroszeros_mode=None, # setting for how to calculating zeros
)
matmul=bitblas.Matmul(config=matmul_config)
# Transform weight tensor to int4 data typeweight_tensor_int8=matmul.transform_weight(weight_tensor)
# Perform mixed-precision matrix multiplicationoutput_tensor=matmul(input_tensor, weight_tensor_int8)
# Reference result using PyTorch matmul for comparison# ref_result = torch.matmul(input_tensor.to(torch.float32), weight_tensor.t().to(torch.float32))ref_result=nn.functional.linear(input_tensor.to(torch.float32), weight_tensor.to(torch.float32))
print("Ref output:", ref_result)
print("BitBLAS output:", output_tensor)
torch.testing.assert_close(output_tensor, ref_result, rtol=1e-2, atol=1e-0)

The output of one go is:

torch.Size([1, 10, 2560])
tensor(127, device='cuda:0', dtype=torch.int8)
tensor(-128, device='cuda:0', dtype=torch.int8)
torch.Size([4096, 2560])
tensor(1, device='cuda:0', dtype=torch.int8)
tensor(-1, device='cuda:0', dtype=torch.int8)
Refoutput: tensor([[[ -297., 476., 115., ..., 374., 27., 261.],
[-1267., 83., -95., ..., 700., 69., 2158.],
[ 515., -2524., 572., ..., 398., -636., -1122.],
...,
[ -297., 476., 115., ..., 374., 27., 261.],
[ 621., -1438., -826., ..., -850., -388., 464.],
[ 515., -2524., 572., ..., 398., -636., -1122.]]],
device='cuda:0')
BitBLASoutput: tensor([[[ -297., 476., 115., ..., 374., 27., 181.],
[-1267., 83., -95., ..., 700., 69., 1391.],
[ 515., -2524., 572., ..., 398., -636., -587.],
...,
[ -297., 476., 115., ..., 374., 27., 181.],
[ 621., -1438., -826., ..., -850., -388., 788.],
[ 515., -2524., 572., ..., 398., -636., -587.]]],
device='cuda:0')
Traceback (mostrecentcalllast):
AssertionError: Tensor-likesarenotclose!
Mismatchedelements: 2554/40960 (6.2%)
Greatestabsolutedifference: 19645.0atindex (0, 2, 463) (upto1.0allowed)
Greatestrelativedifference: 303.5atindex (0, 0, 1087) (upto0.01allowed)

Oddly, when I run another go, the results match! My guess is different kernel is selected. See attached (see test.zip above) for the complete log and the data I use.

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