+
    "Ý³jã  ã                   óT   € ^ RI t ^ RIHt . R	OtR tR t ! R R]4      tR
R R lltR# )é    N)ÚUniformQuantizationObserverBaseÚPerChannelNormObserverc                 ój  € VR 8:  d   VR8¼  g   Q R4       h\         P                  ! \         P                  ! W,          W,          3^V,
          VR7      4      p\         P                  ! WR^ R7      p\         P                  ! WR^R7      pVP	                  V4      P                  4       P                  4       # )ç      ð?g        z*sparsity should be a value between 0 and 1)Údtype©Údim)ÚtorchÚ	bernoulliÚfullÚrepeat_interleaveÚtoÚ
contiguousÚcuda)ÚMÚNÚ	blocksizeÚsparsityr   ÚAs   &&&&& ÚW/home/luca/screen-checking/.venv/lib/python3.14/site-packages/torchao/sparsity/utils.pyÚcreate_block_sparse_tensorr      s’   € Ø�sŒ?˜x¨3œð Ø4óÐ.ô 	�ŠÜ�
Š
�A•N A¥NÐ3°Q¸µ\ÈÔOó	€Aô 	×Ò °!Ô4€AÜ×Ò °!Ô4€AØ�4‰4�‹;×!Ñ!Ó#×(Ñ(Ó*Ð*ó    c                óº  € \         P                  ! ^ ^W,          ^,          34      P                  4       p\         P                  P                  P                  V^R7      P                  W4      P                  4       P                  \         P                  4      pV\         P                  ! W4      P                  4       V,          ,           pVP                  V4      # )z…
This function returns a 1:2 sparse matrix of size (r, c).
Note that this means this matrix will also be 2:4 and 4:8 sparse as well.
)Únum_classes)r
   Úrandintr   ÚnnÚ
functionalÚone_hotÚreshaper   r   Úint32Úrand)ÚrÚcr   Úchoice_indicesÚmaskÚsparse_weights   &&&   r   Úcreate_semi_structured_tensorr'      sš   € ô —]’] 1 a¨!­%°1­*¨Ó7×<Ñ<Ó>€Nä�‰×Ñ×#Ñ# NÀÐ#ÓBß	‰�‹ß	‰‹ß	‰ŒE�K‰K‹ð	 	ð œEŸJšJ qÓ,×1Ñ1Ó3°dÕ:Õ;€MØ×Ñ˜EÓ"Ð"r   c                   óN   a a€ ] tR t^3t oRtV3R lV 3R lltR tR tRtVt	V ;t
# )r   zX
A custom observer that computes the L2 norm of each channel and stores it in a buffer.
c                ó   <€ V ^8„  d   QhRR/# )é   ÚreturnN© )ÚformatÚ__classdict__s   "€r   Ú__annotate__Ú#PerChannelNormObserver.__annotate__8   s   ø€ ÷ 7ñ 7 Dñ 7r   c                ó*  <€ \         SV `  ! R
R \        P                  R\        P                  RRRRRRR\        P
                  ! \        P                  4      P                  /VB  RV n        V P                  R	\        P                  ! . 4      4       R# )r   ÚqschemeÚreduce_rangeFÚ	quant_minNÚ	quant_maxÚepsr   Únormr,   )ÚsuperÚ__init__r
   Úquint8Úper_channel_affineÚfinfoÚfloat32r6   Úaveraging_constantÚregister_bufferÚtensor)ÚselfÚkwargsÚ	__class__s   &,€r   r9   ÚPerChannelNormObserver.__init__8   s’   ø€ ä‰Òñ 	
Ü—,‘,ð	
ä×,Ñ,ð	
ð ð	
ð ð		
ð
 ð	
ô —’œEŸM™MÓ*×.Ñ.ð	
ð ò	
ð #&ˆÔØ×Ñ˜V¤U§\¢\°"Ó%5Ö6r   c                ót  € VP                  4       ^ 8X  d   V# VP                  4       p\        VP                  4       4       Uu. uF  q3NK  	  ppVR,          V^ ,          uV^ &   VR&   VP	                  V4      p\
        P                  ! V^R7      p\
        P                  P                  V^R7      ^,          pV P                  P                  4       ^ 8X  dC   V P                  P                  VP                  4       V P                  P                  V4       V# V ;P                  V,          un	        V# u upi )r   )Ú	start_dimr   éÿÿÿÿ)ÚnumelÚdetachÚranger	   Úpermuter
   ÚflattenÚlinalgÚvector_normr7   Úresize_ÚshapeÚcopy_)rA   Úx_origÚxÚiÚnew_axis_listÚyr7   s   &&     r   ÚforwardÚPerChannelNormObserver.forwardI   sö   € Ø�<‰<‹>˜QÔØˆMØ�M‰M‹Oˆô %*¨!¯%©%«'¤NÓ3¡N˜qš¡NˆÐ3Ø.;¸BÕ.?ÀÈqÕAQÐ+ˆ�aÑ˜-¨Ñ+Ø�I‰I�mÓ$ˆÜ�MŠM˜! qÔ)ˆÜ�|‰|×'Ñ'¨¨qÐ'Ó1°QÕ6ˆà�9‰9�?‰?Ó Ô!Ø�I‰I×Ñ˜dŸj™jÔ)Ø�I‰I�O‰O˜DÔ!ð ˆð �IŠI˜Õ�Iàˆùò 4s   Á
D5c                ó   € \        R 4      h)z>PerChannelNormObserver is designed to store activations only. )ÚNotImplementedError)rA   s   &r   Úcalculate_qparamsÚ(PerChannelNormObserver.calculate_qparams_   s   € Ü!ØLó
ð 	
r   )r>   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r9   rW   r[   Ú__static_attributes__Ú__classdictcell__Ú__classcell__)rC   r.   s   @@r   r   r   3   s#   ù‡ € ñ÷7ó 7ò"÷,
ò 
r   c                óp   € V ^8„  d   QhR\         P                  R\        R\        R\         P                  /# )r*   r@   r   r   r+   )r
   ÚTensorÚint)r-   s   "r   r/   r/   e   s8   € ÷ ñ Ü�L‰Lðä
ðô ðô ‡\�\ñ	r   c                ó  € RpV P                  4       V,          ^ 8w  d   \        RV P                   RV R24      hV P                  4       V,          pV P                  4       P	                  4       P                  WB4      p\        P                  ! V^R7      RR\        W!,
          4      13,          p\        P                  ! VP                  VP                  R7      pVP                  ^V^ R7      P                  V P                  4      pV# )	a¡  
Class for creating N:M sparsity masks.
Masks will be created using the N:M ratio, where for every block of
M weights, N will be pruned based on ranked weight value. Each mask
will correspond to the given tensor.
:param tensor: The input tensor to create a mask for
:param N: The number of weights in a group to keep
:param M: The size of a weight group
:return: A mask tensor with the same shape as the input tensor
NzTensor of size z can't be evenly divided into z groupsr   :NNN)Údevice)r	   ÚindexÚvalue)rH   Ú
ValueErrorrP   rI   Úabsr   r
   Úargsortrg   Úonesri   Úscatter_)r@   r   r   r%   Ú
num_groupsÚtensor_temprj   Úw_bs   &&&     r   Úmask_creatorrt   e   sÚ   € ð €Dà‡|�|ƒ~˜Õ˜QÔÜØ˜fŸl™l˜^Ð+IÈ!ÈÈGÐTó
ð 	
ð —‘“ 1Õ$€Jð —-‘-“/×%Ñ%Ó'×/Ñ/°
Ó>€KÜ�MŠM˜+¨1Ô-¨a°´3°qµu³:°¨oÕ>€Eä
�*Š*�[×&Ñ&¨{×/AÑ/AÔ
B€CØ�<‰<˜A U°!ˆ<Ó4×<Ñ<¸V¿\¹\ÓJ€Dà€Kr   )r   r'   r   rt   )r*   é   )r
   Útorch.ao.quantization.observerr   Ú__all__r   r'   r   rt   r,   r   r   Ú<module>rx      s6   ðó Ý Jò€ò	+ò#ô,/
Ð<ô /
÷dñ r   