MCPcopy Create free account
hub / github.com/OpenGVLab/EfficientQAT / dequant_kernel_dim1

Function dequant_kernel_dim1

quantize/triton_utils/kernels.py:169–211  ·  view source on GitHub ↗

dequant the quantized tensor to fp tensor B is of shape (M, N/(32//bits)) int32 C is of shape (M, N) float16

(
    b_ptr, c_ptr,
    M, N,
    bits, maxq,
    stride_bk, stride_bn,
    stride_cm, stride_cn,
    BLOCK_SIZE_M: tl.constexpr, BLOCK_SIZE_N: tl.constexpr
)

Source from the content-addressed store, hash-verified

167)
168@triton.jit
169def dequant_kernel_dim1(
170 b_ptr, c_ptr,
171 M, N,
172 bits, maxq,
173 stride_bk, stride_bn,
174 stride_cm, stride_cn,
175 BLOCK_SIZE_M: tl.constexpr, BLOCK_SIZE_N: tl.constexpr
176):
177 """
178 dequant the quantized tensor to fp tensor
179 B is of shape (M, N/(32//bits)) int32
180 C is of shape (M, N) float16
181 """
182
183 bits_per_feature = 32 // bits
184
185 pid = tl.program_id(axis=0)
186 num_pid_m = tl.cdiv(M, BLOCK_SIZE_M)
187 num_pid_n = tl.cdiv(N, BLOCK_SIZE_N)
188
189 pid_m = pid // num_pid_n
190 pid_n = pid % num_pid_n
191
192 offs_am = pid_m * BLOCK_SIZE_M + tl.arange(0, BLOCK_SIZE_M)
193 offs_bn = pid_n * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N)
194
195
196 # b_ptrs = b_ptr + ((offs_am[:, None] // bits_per_feature) * stride_bk + offs_bn[None, :] * stride_bn)
197 b_ptrs = b_ptr + (offs_am[:, None] * stride_bk + (offs_bn[None, :] // bits_per_feature) * stride_bn)
198
199 # shifter = (offs_am[:, None] % bits_per_feature) * bits
200 shifter = (offs_bn[None, :] % bits_per_feature) * bits
201
202
203
204 b = tl.load(b_ptrs)
205 b = (b >> shifter) & maxq
206
207 c = b
208
209 c_ptrs = c_ptr + stride_cm * offs_am[:, None] + stride_cn * offs_bn[None, :]
210 c_mask = (offs_am[:, None] < M) & (offs_bn[None, :] < N)
211 tl.store(c_ptrs, c, mask=c_mask)
212
213
214@triton.jit

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected