
    h                     &   S SK Jr  \" SS9 " S S5      5       r\" SS9 " S S\5      5       r\" SS9 " S S	\5      5       r\" SS9 " S
 S\5      5       r\" SS9 " S S\5      5       r\" SS9 " S S\5      5       r\" SS9 " S S\5      5       rg)    )	dataclassT)frozenc                       \ rS rSrSrSrg)Granularity
   z
Base class for representing the granularity of quantization.

This class serves as a parent for specific granularity types used in
quantization operations, such as per-tensor or per-axis quantization.
 N__name__
__module____qualname____firstlineno____doc____static_attributes__r       Z/home/james-whalen/.local/lib/python3.13/site-packages/torchao/quantization/granularity.pyr   r   
        	r   r   c                       \ rS rSrSrSrg)	PerTensor   z
Represents per-tensor granularity in quantization.

This granularity type calculates the quantization parameters
based off the entire tensor.
r   Nr	   r   r   r   r   r      r   r   r   c                   $    \ rS rSr% Sr\\S'   Srg)PerAxis"   a  
Represents per-axis granularity in quantization.

This granularity type calculates different quantization parameters
along a specified axis of the tensor.

For example if the input tensor is shape [8, 16] and axis=0, then
the quantization parameters are calculated for each row of the tensor.
Giving a total of 8 quantization parameters.

Attributes:
    axis (int): The axis along which reduction is performed.
axisr   Nr
   r   r   r   r   int__annotations__r   r   r   r   r   r   "   s     Ir   r   c                   $    \ rS rSr% Sr\\S'   Srg)PerGroup5   a  
Represents per-channel group granularity in quantization.

This granularity type calculates different quantization parameters
for each group of <group_size> elements.

For example if the input tensor is shape [8, 16], and the group size is 4, then
the input tensor is reshaped to [64, 4]
quantization parameters are calculated for each group of 4 elements,
giving a total of 64 quantization parameters.

Attributes:
    group_size (int): The size of each quantization group


group_sizer   Nr   r   r   r   r   r   5   s      Or   r   c                       \ rS rSrSrSrg)PerRowJ   a  
Represents row-wise granularity in quantization.

This is a special case of per-axis quantization and is unique to Float8 matmuls
where the input is quantized with a block_size of (1, ..., input.shape[-1]). And the weight
is quantized with a block_size of (1, weight.shape[1]).
r   Nr	   r   r   r   r"   r"   J   s     	r   r"   c                       \ rS rSrSrSrg)PerTokenW   a  
Represents per-token granularity in quantization.

This granularity type calculates a different set of quantization parameters
for each token, which is represented as the last dimension of the tensor.

For example, if the input tensor has shape [2, 3, 4], then there are 6 tokens
with 4 elements each, and we will calculate 6 sets of quantization parameters,
one for each token.

If the input tensor has only two dimensions, e.g. [8, 16], then this is
equivalent to `PerAxis(axis=0)`, which yields 8 sets of quantization parameters.
r   Nr	   r   r   r   r%   r%   W   s     	r   r%   c                   .    \ rS rSr% Sr\\S4   \S'   Srg)PerBlockj   z
Represents per-block granularity in quantization. See
:func:`~torchao.quantization.quant_primitives.quantize_affine` for docs for
`block_size`
Attributes:
    block_size (tuple[int, ...]): The size of each quantization group
.
block_sizer   N)	r
   r   r   r   r   tupler   r   r   r   r   r   r(   r(   j   s     c3hr   r(   N)	dataclassesr   r   r   r   r   r"   r%   r(   r   r   r   <module>r-      s    " $	 	 	 $	 	 	 $k  $ ${  ( $		[ 		 		 $	{ 	 	$ $	 { 	  	 r   