Ë
    S^(h•  ã                   óF   — d Z ddlmZmZmZ  e«       rddlmZ 	 	 	 	 dd„Zy)z7SpQR (Sparse-Quantized Representation) integration fileé   )Úis_accelerate_availableÚis_spqr_availableÚis_torch_availableé    Nc                 ó  — |€g }t        «       rddlm} t        «       rddlm} | j                  «       D �]Â  \  }}|€g }|j                  |«       t        |t        j                  «      �rCdj                  |«      dz   |v�r+ «       5  dj                  |«      }	|j                  }
|
j                  «       }|	› d�|v xr |	› d�|v xr |	› d	�|v xr |	› d
�|v }|st        d|	› d�«      ‚|
|	› d�   }|
|	› d�   }|
|	› d	�   }|
|	› d
�   }|j                  }|j                   }j#                  |||j$                  |j&                  |j(                  ||||¬«	      | j*                  |<   d}t-        |«      | j*                  |   _        | j*                  |   j1                  d«       ddd«       n	 t3        t5        |j7                  «       «      «      dkD  rt9        |||||¬«      \  }}|j;                  d«       �ŒÅ | |fS # 1 sw Y   ŒYxY w)af  
    Public method that recursively replaces the Linear layers of the given model with SpQR quantized layers.
    `accelerate` is needed to use this method. Returns the converted model and a boolean that indicates if the
    conversion has been successful or not.

    Args:
        model (`torch.nn.Module`):
            The model to convert, can be any `torch.nn.Module` instance.
        quantization_config (`SpQRConfig`):
            The quantization config object that contains the quantization parameters.
        modules_to_not_convert (`list[str]`, *optional*):
            A list of nn.Linear weights to not convert. If a parameter path is in the list (e.g. `lm_head.weight`), the corresponding module will not be
            converted.
        current_key_name (`list`, *optional*):
            A list that contains the current key name. This is used for recursion and should not be passed by the user.
        has_been_replaced (`bool`, *optional*):
            A boolean that indicates if the conversion has been successful or not. This is used for recursion and
            should not be passed by the user.
    Nr   )Úinit_empty_weights)ÚQuantizedLinearú.z.weightz.dense_weights.shapez.row_offsets.shapez.col_vals.shapez.in_perm.shapezJThe SpQR quantization config does not contain the shape configuration for zG. This indicates that the configuration is either invalid or corrupted.)	ÚrowsÚcolsÚbitsÚbeta1Úbeta2Údense_weights_shapeÚrow_offsets_shapeÚcol_vals_shapeÚin_perm_shapeTF)Úquantization_configÚmodules_to_not_convertÚcurrent_key_nameÚhas_been_replacedéÿÿÿÿ)r   Ú
accelerater   r   Ú
spqr_quantr	   Únamed_childrenÚappendÚ
isinstanceÚnnÚLinearÚjoinÚshapesÚkeysÚ
ValueErrorÚin_featuresÚout_featuresÚcreate_placehodlerr   r   r   Ú_modulesÚtypeÚ
source_clsÚrequires_grad_ÚlenÚlistÚchildrenÚreplace_with_spqr_linearÚpop)Úmodelr   r   r   r   r   r	   ÚnameÚmoduleÚtensor_namer!   Úshapes_keysÚshapes_validr   r   r   r   r$   r%   Ú_s                       ú\/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/integrations/spqr.pyr.   r.      sˆ  € ð4 Ð%Ø!#ÐäÔ Ý1ÜÔÝ.à×,Ñ,Ó.ó @!‰ˆˆfØÐ#Ø!ÐØ×Ñ Ô%ä�fœbŸi™iÕ(à�x‰xÐ(Ó)¨IÑ5Ð=SÒSÙ'Ó)ñ ,?Ø"%§(¡(Ð+;Ó"<�Kà0×7Ñ7�FØ"(§+¡+£-�Kð '˜-Ð';Ð<ÀÐKò JØ*˜mÐ+=Ð>À+ÐMòJà*˜m¨?Ð;¸{ÐJòJð  +˜m¨>Ð:¸kÐIð	 !ñ (Ü(ð1Ø1<°ð >LðMóð ð +1°K°=Ð@TÐ1UÑ*VÐ'Ø(.°+°Ð>PÐ/QÑ(RÐ%Ø%+¨{¨m¸?Ð,KÑ%L�NØ$*¨k¨]¸.Ð+IÑ$J�Mà"(×"4Ñ"4�KØ#)×#6Ñ#6�Là+:×+MÑ+MØ)Ø(Ø0×5Ñ5Ø1×7Ñ7Ø1×7Ñ7Ø,?Ø*;Ø'5Ø&3ð ,Nó 
,�E—N‘N 4Ñ(ð )-Ð%ô 7;¸6³l�E—N‘N 4Ñ(Ô3à—N‘N 4Ñ(×7Ñ7¸Ô>÷Y,?ð ,?ð\ ÜŒt�F—O‘OÓ%Ó&Ó'¨!Ò+Ü#;ØØ$7Ø'=Ø!1Ø"3ô$Ñ ˆAÐ ð 	×Ñ˜RÖ ðA@!ðB Ð#Ð#Ð#÷s,?ð ,?ús   Â
DG?Ç?H	)NNNF)Ú__doc__Úutilsr   r   r   Útorch.nnr   r.   © ó    r7   ú<module>r=      s/   ðñ :ç RÑ Rñ ÔÝð
 ØØØôc$r<   