MCPcopy Create free account
hub / github.com/OpenBitSys/BitDistiller / quant_gemv_v3

Function quant_gemv_v3

quantization/triton_kernels.py:427–468  ·  view source on GitHub ↗

:param a: input tensor, (batch, N) :param weight: weight matrix, (M, N // pack_num) :param qzeros: (M, N // group_size // pack_num) :param scales: (M, N // group_size) :return: result tensor, (batch, M)

(a, qw, qzeros, scales, M, N, pack_num, group_size, w_bit, offset)

Source from the content-addressed store, hash-verified

425
426
427def quant_gemv_v3(a, qw, qzeros, scales, M, N, pack_num, group_size, w_bit, offset):
428 """
429 :param a: input tensor, (batch, N)
430 :param weight: weight matrix, (M, N // pack_num)
431 :param qzeros: (M, N // group_size // pack_num)
432 :param scales: (M, N // group_size)
433 :return: result tensor, (batch, M)
434 """
435 batch, _ = a.shape
436 c = torch.empty((batch, M), dtype=torch.float16, device=a.device)
437
438 assert qw.shape == (M, N // pack_num)
439 # assert qzeros.shape == (M // group_size // pack_num, N)
440 # assert scales.shape == (M // group_size, N)
441 assert all(x.is_contiguous() for x in [a, qw, c, qzeros, scales])
442 assert group_size % 64 == 0, f"group_size {group_size} is not a multiple of 64"
443 # assert (N // pack_num) % 256 == 0, f"N // pack_num {N // pack_num} is not a multiple of 256"
444
445 # 1D launch kernel where each block gets its own program.
446 grid = lambda META: (triton.cdiv(M, META["BLOCK_M"]),) # noqa
447
448 gemv_kernel_v3[grid](
449 a_ptr=a,
450 qw_ptr=qw,
451 c_ptr=c,
452 scales_ptr=scales,
453 zeros_ptr=qzeros,
454 M=M,
455 N=N,
456 pack_num=pack_num,
457 w_bit=w_bit,
458 group_size=group_size,
459 offset=offset,
460 CACHE_KEY_M=M // 512, # key for triton cache (limit number of compilations)
461 CACHE_KEY_N=N // 1024,
462 stride_qw=qw.stride(0),
463 stride_scale=scales.stride(0),
464 stride_zeros=qzeros.stride(0),
465 BATCHSIZE=batch
466 )
467
468 return c

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected