Determine the quantization statistics for input matrix `A` in accordance to the `LLM.int8()` algorithm. The statistics are determined both row-wise and column-wise (transposed). For more information, see the [LLM.int8() paper](https://arxiv.org/abs/2208.07339). This function
(
A: torch.Tensor,
col_stats: Optional[torch.Tensor] = None,
row_stats: Optional[torch.Tensor] = None,
out_col: Optional[torch.Tensor] = None,
out_row: Optional[torch.Tensor] = None,
threshold=0.0,
)
| 1588 | |
| 1589 | |
| 1590 | def int8_double_quant( |
| 1591 | A: torch.Tensor, |
| 1592 | col_stats: Optional[torch.Tensor] = None, |
| 1593 | row_stats: Optional[torch.Tensor] = None, |
| 1594 | out_col: Optional[torch.Tensor] = None, |
| 1595 | out_row: Optional[torch.Tensor] = None, |
| 1596 | threshold=0.0, |
| 1597 | ): |
| 1598 | """Determine the quantization statistics for input matrix `A` in accordance to the `LLM.int8()` algorithm. |
| 1599 | |
| 1600 | The statistics are determined both row-wise and column-wise (transposed). |
| 1601 | |
| 1602 | For more information, see the [LLM.int8() paper](https://arxiv.org/abs/2208.07339). |
| 1603 | |
| 1604 | <Tip> |
| 1605 | This function is useful for training, but for inference it is advised to use [`int8_vectorwise_quant`] instead. |
| 1606 | This implementation performs additional column-wise transposed calculations which are not optimized. |
| 1607 | </Tip> |
| 1608 | |
| 1609 | Args: |
| 1610 | A (`torch.Tensor` with dtype `torch.float16`): The input matrix. |
| 1611 | col_stats (`torch.Tensor`, *optional*): A pre-allocated tensor to hold the column-wise quantization scales. |
| 1612 | row_stats (`torch.Tensor`, *optional*): A pre-allocated tensor to hold the row-wise quantization scales. |
| 1613 | out_col (`torch.Tensor`, *optional*): A pre-allocated tensor to hold the column-wise quantized data. |
| 1614 | out_row (`torch.Tensor`, *optional*): A pre-allocated tensor to hold the row-wise quantized data. |
| 1615 | threshold (`float`, *optional*): |
| 1616 | An optional threshold for sparse decomposition of outlier features. |
| 1617 | |
| 1618 | No outliers are held back when 0.0. Defaults to 0.0. |
| 1619 | |
| 1620 | Returns: |
| 1621 | `Tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor, Optional[torch.Tensor]]`: A tuple containing the quantized tensor and relevant statistics. |
| 1622 | - `torch.Tensor` with dtype `torch.int8`: The row-wise quantized data. |
| 1623 | - `torch.Tensor` with dtype `torch.int8`: The column-wise quantized data. |
| 1624 | - `torch.Tensor` with dtype `torch.float32`: The row-wise quantization scales. |
| 1625 | - `torch.Tensor` with dtype `torch.float32`: The column-wise quantization scales. |
| 1626 | - `torch.Tensor` with dtype `torch.int32`, *optional*: A list of column indices which contain outlier features. |
| 1627 | """ |
| 1628 | |
| 1629 | if row_stats is not None: |
| 1630 | raise ValueError("row_stats must be None. int8_double_quant() does not support pre-allocated row_stats.") |
| 1631 | if col_stats is not None: |
| 1632 | raise ValueError("col_stats must be None. int8_double_quant() does not support pre-allocated col_stats.") |
| 1633 | if out_col is not None: |
| 1634 | raise ValueError("out_col must be None. int8_double_quant() does not support pre-allocated out_col.") |
| 1635 | if out_row is not None: |
| 1636 | raise ValueError("out_row must be None. int8_double_quant() does not support pre-allocated out_row.") |
| 1637 | |
| 1638 | return torch.ops.bitsandbytes.int8_double_quant.default(A, threshold=threshold) |
| 1639 | |
| 1640 | |
| 1641 | def int8_vectorwise_dequant(A: torch.Tensor, stats: torch.Tensor): |
nothing calls this directly
no outgoing calls
no test coverage detected