MCPcopy Create free account
hub / github.com/pytorch/executorch / _dequant_matmul

Function _dequant_matmul

backends/cuda/int4_dispatch.py:56–73  ·  view source on GitHub ↗

Dequant INT4 weights to input dtype and call F.linear.

(x, qdata, scale, zero, group_size)

Source from the content-addressed store, hash-verified

54
55
56def _dequant_matmul(x, qdata, scale, zero, group_size):
57 """Dequant INT4 weights to input dtype and call F.linear."""
58 N, K_half = qdata.shape
59 K = K_half * 2
60 n_groups = K // group_size
61 gs_half = group_size // 2
62 dtype = x.dtype
63
64 p = qdata.to(torch.uint8).reshape(N, n_groups, gs_half)
65 low = (p & 0x0F).to(dtype)
66 high = ((p >> 4) & 0x0F).to(dtype)
67 data = torch.stack([low, high], dim=-1).reshape(N, n_groups, group_size)
68
69 s = scale.to(dtype).t().unsqueeze(-1)
70 z = zero.to(dtype).t().unsqueeze(-1)
71 w_deq = ((data - z) * s).reshape(N, K)
72
73 return F.linear(x, w_deq)
74
75
76# ---------------------------------------------------------------------------

Callers 2

_cudaFunction · 0.85
_Function · 0.85

Calls 2

tMethod · 0.80
toMethod · 0.45

Tested by

no test coverage detected