+
    "Ý³j  ã                   ó–  € ^ RI Ht ^ RIt]! RR7       ! R R4      4       t]! RR7       ! R R]4      4       t]! RR7       ! R	 R
]4      4       t]! RR7       ! R R]4      4       t]! RR7       ! R R]4      4       t]! RR7       ! R R]4      4       t]! RR7       ! R R]4      4       t	]P                  P                  ]	]].4       R# )é    )Ú	dataclassNT)Úfrozenc                   ó   € ] tR t^tRtRtR# )ÚGranularityzÊ
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   ó    Úa/home/luca/screen-checking/.venv/lib/python3.14/site-packages/torchao/quantization/granularity.pyr   r      ó   † ñó 	r   r   c                   ó   € ] tR t^tRtRtR# )Ú	PerTensorz�
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                   ó0   a € ] tR t^$t o RtV 3R ltRtV tR# )ÚPerAxisaÇ  
Represents per-axis granularity in quantization.

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

Examples:
* input_tensor shape [A, B], axis 0 -> scale_shape [A, 1]
* input_tensor shape [A, B], axis 1 -> scale_shape [1, B]
* input_tensor shape [A, B, C], axis 1 -> scale_shape [1, B, 1]

Attributes:
    axis (int): The axis which is kept, reduction is performed across all
      the other axes
c                ó&   <€ V ^8„  d   Qh/ S[ ;R&   # )é   Úaxis©Úint)ÚformatÚ__classdict__s   "€r   Ú__annotate__ÚPerAxis.__annotate__$   s   ø‡ ‚ ñ$ �Iò% r   r   N©r	   r
   r   r   r   Ú__annotate_func__r   Ú__classdictcell__©r   s   @r   r   r   $   ó   ø‡ € ñ÷ ƒ r   r   c                   ó0   a € ] tR t^9t o RtV 3R ltRtV tR# )ÚPerGroupaÜ  
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

c                ó&   <€ V ^8„  d   Qh/ S[ ;R&   # )r   Ú
group_sizer   )r   r   s   "€r   r   ÚPerGroup.__annotate__9   s   ø‡ ‚ ñ$ �Oò% r   r   Nr   r"   s   @r   r%   r%   9   r#   r   r%   c                   ó4   a € ] tR t^Nt o RtRtV 3R ltRtV tR# )ÚPerRowa}  
Represents row-wise granularity in quantization.

Examples:
* input_tensor shape [A, B], dim 0 -> scale_shape [1, B]
* input_tensor shape [A, B], dim 1 -> scale_shape [A, 1]
* input_tensor shape [A, B], dim -1 -> scale_shape [A, 1]
* input_tensor shape [A, B, C], dim 1 -> scale_shape [A, 1, C]

Attributes:
    dim (int): The dim which is reduced across, all other dims are kept
c                ó&   <€ V ^8„  d   Qh/ S[ ;R&   # )r   Údimr   )r   r   s   "€r   r   ÚPerRow.__annotate__N   s   ø‡ ‚ ñ 
�Mò r   r   Néÿÿÿÿ)	r	   r
   r   r   r   r,   r    r   r!   r"   s   @r   r*   r*   N   s   ø‡ € ñð €C÷ ƒ r   r*   c                   ó   € ] tR t^`tRtRtR# )ÚPerTokena  
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   r0   r0   `   s   † ñó 	r   r0   c                   ó0   a € ] tR t^st o RtV 3R ltRtV tR# )ÚPerBlockaû  
Represents multidimensional per-block granularity in quantization.

Example:
* block_size has shape [X, Y]
* input_tensor shape [A] -> scaling undefined
* input_tensor shape [A, B] -> scale shape [A // X, B // Y]
* input_tensor shape [A, B, C] -> scale shape [A, B // X, C // Y]
* input_tensor shape [A, B, C, D] -> scale shape [A, B, C // X, D // Y], and so on

Note that `PerBlock((1, Y))` is equivalent to `PerGroup(Y)`

Attributes:
    block_size (tuple[int, ...]): The size of each quantization group
c                ó:   <€ V ^8„  d   Qh/ S[ S[R3,          ;R&   # )r   .Ú
block_size)Útupler   )r   r   s   "€r   r   ÚPerBlock.__annotate__s   s   ø‡ ‚ ñ6 ‘c˜3�h•Ñò7 r   r   Nr   r"   s   @r   r2   r2   s   r#   r   r2   )Údataclassesr   Útorchr   r   r   r%   r*   r0   r2   ÚserializationÚadd_safe_globalsr   r   r   Ú<module>r;      s  ðõ "ã ñ �$Ô÷	ð 	ó ð	ñ �$Ôô	�ó 	ó ð	ñ �$Ôôˆkó ó ðñ( �$Ôôˆ{ó ó ðñ( �$Ôôˆ[ó ó ðñ" �$Ôô	ˆ{ó 	ó ð	ñ$ �$Ôô ˆ{ó  ó ð ð: × Ñ × $Ñ $ h°¸	Ð%BÖ Cr   