importtorchimportbitblasbatch_size=1num_tokens=2in_features=16out_features=32model=bitblas.Linear(
in_features=in_features,
out_features=out_features,
bias=False,
A_dtype="int8", # activation A dtypeW_dtype="int4", # weight W dtypeaccum_dtype="int32", # accumulation dtypeout_dtype="float32", # output dtype# 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# Target optimization var for dynamic symbolic.# For detailed information please checkout docs/PythonAPI.md# By default, the optimization var is [1, 16, 32, 64, 128, 256, 512]opt_M=[1, 16, 32, 64, 128],
)
x=torch.ones((batch_size, num_tokens, in_features)).to(torch.int8)
w=torch.ones((out_features, in_features)).to(torch.int8)
x=x.cuda()
w=w.cuda()
model=model.cuda()
model.load_and_transform_weight(w)
model.eval()
withtorch.no_grad():
y=model(x)
print(y)
tensor([[[ 32., 32., 32., 32., 32., 32., 32., 32., 32., 32.,
32., 32., 32., 32., 32., 32., 32., 32., 32., 32.,
32., 32., 32., 32., 32., 32., 32., 32., 32., 32.,
32., -104.],
[ 16., 16., 16., 16., 16., 16., 16., 16., 16., 16.,
16., 16., 16., 16., 16., 16., 16., 16., 16., 16.,
16., 16., 16., 16., 16., 16., 16., 16., 16., 16.,
16., 16.]]], device='cuda:0')
torch: 2.3.0+cu121
cuda version: 12.1
GPU: NVIDIA GeForce RTX 4090
I am trying to use
bitblas.LinearwithA_dtype="int8"andW_dtype="int4".I expected the output to be all
16.0(since both inputs and weights are filled with ones), but I got unexpected values.result:
environment: