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

Function embedding_2bit

exir/passes/_quant_patterns_and_replacements.py:248–285  ·  view source on GitHub ↗
(
    weight: torch.Tensor,
    weight_scales: torch.Tensor,
    weight_zero_points: Optional[torch.Tensor],
    weight_quant_min: int,
    weight_quant_max: int,
    indices: torch.Tensor,
)

Source from the content-addressed store, hash-verified

246
247@impl(quantized_decomposed_lib, "embedding_2bit", "CompositeExplicitAutograd")
248def embedding_2bit(
249 weight: torch.Tensor,
250 weight_scales: torch.Tensor,
251 weight_zero_points: Optional[torch.Tensor],
252 weight_quant_min: int,
253 weight_quant_max: int,
254 indices: torch.Tensor,
255) -> torch.Tensor:
256 assert (
257 weight_quant_min == -2
258 ), "embedding_2bit in ExecuTorch expects weight_quant_min == -2"
259 assert (
260 weight_quant_max == 1
261 ), "embedding_2bit in ExecuTorch expects weight_quant_max == 1"
262
263 embedding_weight_checks(weight, weight_scales, weight_zero_points)
264 group_size = (4 * weight.size(1)) // (
265 weight_scales.size(1) if weight_scales.dim() == 2 else 1
266 )
267 weight_0 = weight & 3
268 weight_1 = (weight & 12) >> 2
269 weight_2 = (weight & 48) >> 4
270 weight_3 = (weight & 192) >> 6
271 weight_unpacked = torch.stack((weight_0, weight_1, weight_2, weight_3), dim=-1)
272 weight = weight_unpacked.view(weight.shape[0], -1)
273 weight = weight.view(torch.int8).add(-2)
274
275 weight = torch.ops.quantized_decomposed.dequantize_per_channel_group.default(
276 weight,
277 weight_scales,
278 weight_zero_points,
279 weight_quant_min,
280 weight_quant_max,
281 weight.dtype,
282 group_size,
283 weight_scales.dtype,
284 )
285 return torch.ops.aten.embedding.default(weight, indices)
286
287
288@register_fake("quantized_decomposed::embedding_2bit")

Callers 1

embedding_2bit_out_metaFunction · 0.85

Calls 3

embedding_weight_checksFunction · 0.85
addMethod · 0.45
defaultMethod · 0.45

Tested by

no test coverage detected