(
self,
bits,
group_size,
infeatures,
outfeatures,
bias,
trainable=False,
**kwargs
)
| 27 | QUANT_TYPE = "triton" |
| 28 | |
| 29 | def __init__( |
| 30 | self, |
| 31 | bits, |
| 32 | group_size, |
| 33 | infeatures, |
| 34 | outfeatures, |
| 35 | bias, |
| 36 | trainable=False, |
| 37 | **kwargs |
| 38 | ): |
| 39 | super().__init__() |
| 40 | # if bits not in [2, 4, 8]: |
| 41 | # raise NotImplementedError("Only 2,4,8 bits are supported.") |
| 42 | # if infeatures % 32 != 0 or outfeatures % 32 != 0: |
| 43 | # raise NotImplementedError("in_feature and out_feature must be divisible by 32.") |
| 44 | self.infeatures = infeatures |
| 45 | self.outfeatures = outfeatures |
| 46 | self.bits = bits |
| 47 | self.group_size = group_size if group_size != -1 else infeatures |
| 48 | self.maxq = 2 ** self.bits - 1 |
| 49 | self.register_buffer( |
| 50 | 'qweight', |
| 51 | torch.zeros((math.ceil(infeatures / (32 // self.bits)), outfeatures), dtype=torch.int32) |
| 52 | ) |
| 53 | self.register_parameter( |
| 54 | 'scales', |
| 55 | torch.nn.Parameter(torch.zeros((math.ceil(infeatures / self.group_size), outfeatures), dtype=torch.float16)) |
| 56 | ) |
| 57 | self.register_buffer( |
| 58 | 'qzeros', |
| 59 | torch.zeros((math.ceil(infeatures / self.group_size), math.ceil(outfeatures / (32 // self.bits))), dtype=torch.int32) |
| 60 | ) |
| 61 | self.register_buffer( |
| 62 | 'g_idx', |
| 63 | torch.tensor([i // self.group_size for i in range(infeatures)], dtype=torch.int32) |
| 64 | ) # not used, just for consistent with GPTQ models |
| 65 | if bias: |
| 66 | self.register_buffer('bias', torch.zeros((outfeatures), dtype=torch.float16)) |
| 67 | else: |
| 68 | self.bias = None |
| 69 | |
| 70 | self.zeros_dim0, self.zeros_dim1 = self.scales.shape |
| 71 | self.trainable = trainable |
| 72 | self.scales.requires_grad = True |
| 73 | self.use_fake = False |
| 74 | |
| 75 | def post_init(self): |
| 76 | pass |
nothing calls this directly
no outgoing calls
no test coverage detected