(
weight: torch.Tensor,
weight_scales: torch.Tensor,
weight_zero_points: Optional[torch.Tensor],
weight_quant_min: int,
weight_quant_max: int,
indices: torch.Tensor,
)
| 423 | |
| 424 | @impl(quantized_decomposed_lib, "embedding_4bit", "CompositeExplicitAutograd") |
| 425 | def embedding_4bit( |
| 426 | weight: torch.Tensor, |
| 427 | weight_scales: torch.Tensor, |
| 428 | weight_zero_points: Optional[torch.Tensor], |
| 429 | weight_quant_min: int, |
| 430 | weight_quant_max: int, |
| 431 | indices: torch.Tensor, |
| 432 | ) -> torch.Tensor: |
| 433 | assert ( |
| 434 | weight_quant_min == -8 |
| 435 | ), "embedding_4bit in ExecuTorch expects weight_quant_min == -8" |
| 436 | assert ( |
| 437 | weight_quant_max == 7 |
| 438 | ), "embedding_4bit in ExecuTorch expects weight_quant_max == 7" |
| 439 | |
| 440 | embedding_weight_checks(weight, weight_scales, weight_zero_points) |
| 441 | group_size = (2 * weight.size(1)) // ( |
| 442 | weight_scales.size(1) if weight_scales.dim() == 2 else 1 |
| 443 | ) |
| 444 | weight_even = weight.div(16, rounding_mode="trunc") |
| 445 | weight_odd = weight.remainder(16) |
| 446 | weight_unpacked = torch.stack((weight_even, weight_odd), dim=-1) |
| 447 | weight = weight_unpacked.view(weight.shape[0], -1) |
| 448 | weight = weight.view(torch.int8).add(-8) |
| 449 | |
| 450 | weight = torch.ops.quantized_decomposed.dequantize_per_channel_group.default( |
| 451 | weight, |
| 452 | weight_scales, |
| 453 | weight_zero_points, |
| 454 | weight_quant_min, |
| 455 | weight_quant_max, |
| 456 | weight.dtype, |
| 457 | group_size, |
| 458 | weight_scales.dtype, |
| 459 | ) |
| 460 | return torch.ops.aten.embedding.default(weight, indices) |
| 461 | |
| 462 | |
| 463 | @register_fake("quantized_decomposed::embedding_4bit") |
no test coverage detected