+
    "Ý³j©  ã                   ó"  € ^ RI t ^ RIHt ^ RIHtHt ^ RIt^ RIHtH	t	 ^ RI
Ht ^ RIHt ^ RIHtHtHt ^ RIHtHt ^ R	IHt R
 t] ! R R]4      4       t]t]! ]4      R R l4       t ! R R]4      t]t]! ]4      R R l4       tRR R lltR# )é    N)Ú	dataclass)ÚCallableÚOptional)ÚSparseSemiStructuredTensorÚto_sparse_semi_structured)ÚAOBaseConfig)ÚWeightNormSparsifier)Ú
_is_linearÚ_linear_extra_reprÚ)_replace_with_custom_fn_if_matches_filter)Ú_QUANTIZE_CONFIG_HANDLERÚ register_quantize_module_handler)ÚBlockSparseTensorc                ó2  € VP                  R\        4      p. pV P                  4        F+  w  rEV! WT4      '       g   K  VP                  RV R2/4       K-  	  \	        RR^R7      pVP                  W4       VP                  4        VP                  4        R# )zG
This function simulates 2:4 sparsity on all linear layers in a model.
Ú	filter_fnÚ
tensor_fqnz.weightg      ð?)Úsparsity_levelÚsparse_block_shapeÚzeros_per_blockN)é   é   )Úpopr
   Únamed_modulesÚappendr	   ÚprepareÚstepÚsquash_mask)ÚmodelÚkwargsr   Úsparse_configÚnameÚmodÚ
sparsifiers   &,     Ú\/home/luca/screen-checking/.venv/lib/python3.14/site-packages/torchao/sparsity/sparse_api.pyÚapply_fake_sparsityr%      sŒ   € ð —
‘
˜;¬
Ó3€Ià€MØ×(Ñ(Ö*‰	ˆÙ�S×ÔØ× Ñ  ,°4°&¸Ð0@Ð!AÖBñ +ô &Ø¨vÀqô€Jð ×Ñ�uÔ,Ø‡O�OÔØ×ÑÖó    c                   ó6   a € ] tR t^1t o ^@tR tV 3R ltRtV tR# )ÚBlockSparseWeightConfigc                óD   € \         P                  P                  R 4       R# )z(torchao.sparsity.BlockSparseWeightConfigN©ÚtorchÚ_CÚ_log_api_usage_once©Úselfs   &r$   Ú__post_init__Ú%BlockSparseWeightConfig.__post_init__5   s   € Ü�‰×$Ñ$Ð%OÖPr&   c                ó&   <€ V ^8„  d   Qh/ S[ ;R&   # )é   Ú	blocksize©Úint)ÚformatÚ__classdict__s   "€r$   Ú__annotate__Ú$BlockSparseWeightConfig.__annotate__1   s   ø‡ ‚ áÑò r&   © N)	Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__r4   r0   Ú__annotate_func__Ú__static_attributes__Ú__classdictcell__)r8   s   @r$   r(   r(   1   s   ø‡ € à€IòQ÷	 ƒ r&   r(   c                óX   € V ^8„  d   QhR\         P                  P                  R\        /# )r3   ÚmoduleÚconfig)r+   ÚnnÚModuler(   )r7   s   "r$   r9   r9   >   s$   € ÷ ñ Ü�H‰H�O‰Oðä#ñr&   c                 óì   € VP                   p\        P                  ! V P                  V4      p\        P
                  P                  VR R7      V n        \        P                  ! \        V 4      V n
        V # )F©Úrequires_grad)r4   r   Ú
from_denseÚweightr+   rF   Ú	ParameterÚtypesÚ
MethodTyper   Ú
extra_repr)rD   rE   r4   Ú
new_weights   &&  r$   Ú_block_sparse_weight_transformrR   =   s[   € ð
 × Ñ €IÜ"×-Ò-¨f¯m©m¸YÓG€JÜ—H‘H×&Ñ& zÀÐ&ÓG€F„MÜ×(Ò(Ô);¸VÓD€FÔØ€Mr&   c                   ób   a a€ ] tR t^It oRt]P                  3V3R lV 3R llltR tRt	Vt
V ;t# )ÚSemiSparseWeightConfigz]
Configuration for converting the weight of linear modules to semi-structured (2:4) sparsity
c                ó    <€ V ^8„  d   QhRS[ /# )r3   Úalg_idr5   )r7   r8   s   "€r$   r9   Ú#SemiSparseWeightConfig.__annotate__N   s   ø€ ÷ ñ ™sñ r&   c                ó0   <€ \         SV `  4        Wn        R # ©N)ÚsuperÚ__init__rV   )r/   rV   Ú	__class__s   &&€r$   r[   ÚSemiSparseWeightConfig.__init__N   s   ø€ Ü‰ÑÔØŽr&   c                óD   € \         P                  P                  R 4       R# )z'torchao.sparsity.SemiSparseWeightConfigNr*   r.   s   &r$   r0   Ú$SemiSparseWeightConfig.__post_init__R   s   € Ü�‰×$Ñ$Ð%NÖOr&   ©rV   )r<   r=   r>   r?   Ú__doc__r   Ú_DEFAULT_ALG_IDr[   r0   rA   rB   Ú__classcell__)r\   r8   s   @@r$   rT   rT   I   s,   ù‡ € ñð &@×%OÑ%O÷ õ ÷Pò Pr&   rT   c                óŒ   € V ^8„  d   QhR\         P                  P                  R\        R\         P                  P                  /# )r3   rD   rE   Úreturn)r+   rF   rG   rT   )r7   s   "r$   r9   r9   [   s6   € ÷ ñ Ü�H‰H�O‰Oðä"ðô ‡X�X‡_�_ñr&   c                 óö  € R \         P                  9   ;'       g/    R\         P                  9   ;'       g    R\         P                  9   pV'       d#   \        V P                  VP                  R7      pM?VP                  \
        P                  8w  d   \        R4      h\        V P                  4      p\         P                  P                  VRR7      V n        \        P                  ! \        V 4      V n        V # )ÚdevÚgitÚfbr`   zDSemiSparseWeightConfig.alg_id is only supported in nightly or sourceFrI   )r+   Ú__version__r   rL   rV   r   rb   Ú
ValueErrorrF   rM   rN   rO   r   rP   )rD   rE   Úis_nightly_or_sourcerQ   s   &&  r$   Ú_semi_sparse_weight_transformrm   Z   sÉ   € ð 	”×"Ñ"Ñ"÷ 	%ð 	%Ø”E×%Ñ%Ñ%÷	%ð 	%à”5×$Ñ$Ñ$ð ÷
 Ü.¨v¯}©}ÀVÇ]Á]ÔS‰
à�=‰=Ô6×FÑFÔFÜØVóð ô /¨v¯}©}Ó=ˆ
Ü—H‘H×&Ñ& zÀÐ&ÓG€F„MÜ×(Ò(Ô);¸VÓD€FÔØ€Mr&   c          	      ó  € V ^8„  d   QhR\         P                  P                  R\        R\        \
        \         P                  P                  \        .\        3,          ,          R\         P                  P                  /# )r3   r   rE   r   re   )r+   rF   rG   r   r   r   ÚstrÚbool)r7   s   "r$   r9   r9   q   s\   € ÷ %ñ %Ü�8‰8�?‰?ð%äð%ô œ¤%§(¡(§/¡/´3Ð!7¼Ð!=Õ>Õ?ð%ô ‡X�X‡_�_ñ	%r&   c                ó¤   € \         P                  P                  R4       \        \	        V4      ,          p\        T TVf   \        MTV3R7       R# )aí  Convert the weight of linear modules in the model with `apply_tensor_subclass`.
This function is essentially the same as quantize, put for sparsity subclasses.

Currently, we support semi-structured (2:4) sparsity with `semi_sparse_weight`.

Args:
    model (torch.nn.Module): input model
    config (AOBaseConfig): a workflow configuration object
    filter_fn (Optional[Callable[[torch.nn.Module, str], bool]]): function that takes a nn.Module instance and fully qualified name of the module, returns True if we want to apply the specified workflow to this module.

**Example:**
::
        import torch
        import torch.nn as nn
        from torchao.sparsity import sparsify_

        def filter_fn(module: nn.Module, fqn: str) -> bool:
            return isinstance(module, nn.Linear)

        m = nn.Sequential(nn.Linear(32, 1024), nn.Linear(1024, 32))

        # for 2:4 sparsity
        from torchao.sparse_api import semi_sparse_weight
        m = sparsify_(m, semi_sparse_weight(), filter_fn)
ztorchao.sparsity.sparsify_N)Ú
extra_args)r+   r,   r-   r   Útyper   r
   )r   rE   r   Úhandlers   &&& r$   Ú	sparsify_ru   q   sB   € ô< 
‡H�H× Ñ Ð!=Ô>Ü&¤t¨F£|Õ4€GÜ-ØØØÒ'�
¨YØ�9÷	r&   rY   )rN   Údataclassesr   Útypingr   r   r+   Útorch.sparser   r   Útorchao.core.configr   Ú<torchao.prototype.sparsity.sparsifier.weight_norm_sparsifierr	   Útorchao.quantization.quant_apir
   r   r   Ú%torchao.quantization.transform_moduler   r   Útorchao.sparsity.blocksparser   r%   r(   Úblock_sparse_weightrR   rT   Úsemi_sparse_weightrm   ru   r;   r&   r$   Ú<module>r€      s±   ðó Ý !ß %ã ß Nå ,õ÷ñ ÷
õ ;òð& ôQ˜ló Qó ðQð .Ð ñ "Ð"9Ó:ôó ;ðô
P˜\ô 
Pð ,Ð ñ "Ð"8Ó9ôó :ð÷,%ñ %r&   