:param x: input tensor, (batch, M) :param weight: weight matrix, (M // pack_num, N) :param qzeros: (M // group_size // pack_num, N) :param scales: (M // group_size, N) :return: result tensor, (batch, N)
(a, qw, qzeros, scales, M, N, pack_num, group_size, w_bit, offset)
| 245 | |
| 246 | |
| 247 | def quant_gemv_v2(a, qw, qzeros, scales, M, N, pack_num, group_size, w_bit, offset): |
| 248 | """ |
| 249 | :param x: input tensor, (batch, M) |
| 250 | :param weight: weight matrix, (M // pack_num, N) |
| 251 | :param qzeros: (M // group_size // pack_num, N) |
| 252 | :param scales: (M // group_size, N) |
| 253 | :return: result tensor, (batch, N) |
| 254 | """ |
| 255 | batch, _ = a.shape |
| 256 | c = torch.empty((batch, N), dtype=torch.float16, device=a.device) |
| 257 | |
| 258 | assert qw.shape == (M // pack_num, N) |
| 259 | # assert qzeros.shape == (M // group_size // pack_num, N) |
| 260 | # assert scales.shape == (M // group_size, N) |
| 261 | assert all(x.is_contiguous() for x in [a, qw, c, qzeros, scales]) |
| 262 | # BLOCK_SIZE_K has possible values of 32, 64 |
| 263 | # group_size, K must be divisible by BLOCK_SIZE_K |
| 264 | assert group_size % 64 == 0, f"group_size {group_size} is not a multiple of 64" |
| 265 | assert M % 64 == 0, f"K {K} is not a multiple of 64" |
| 266 | # BLOCK_SIZE_N has possible values of 32, 64, 128, 256 |
| 267 | # N must be divisible by BLOCK_SIZE_N |
| 268 | assert N % 256 == 0, f"N {N} is not a multiple of 256" |
| 269 | |
| 270 | |
| 271 | grid = lambda META: (triton.cdiv(M, META["BLOCK_M"]), |
| 272 | triton.cdiv(N, META["BLOCK_N"]),) |
| 273 | transposed_gemv_atomicadd_kernel[grid]( |
| 274 | a_ptr=a, |
| 275 | qw_ptr=qw, |
| 276 | c_ptr=c, |
| 277 | scales_ptr=scales, |
| 278 | zeros_ptr=qzeros, |
| 279 | M=M, |
| 280 | N=N, |
| 281 | pack_num=pack_num, |
| 282 | w_bit=w_bit, |
| 283 | group_size=group_size, |
| 284 | offset=offset, |
| 285 | CACHE_KEY_M=M, # key for triton cache (limit number of compilations) |
| 286 | CACHE_KEY_N=N, |
| 287 | stride_am=qw.stride(0), |
| 288 | BATCHSIZE=batch |
| 289 | ) |
| 290 | |
| 291 | return c |
| 292 | |
| 293 | |
| 294 | # def triton_transposed_gemv_v2(x: torch.Tensor, |
nothing calls this directly
no outgoing calls
no test coverage detected