
    Z j                         S SK r SSKJr  SSKJr  \" 5       (       a  S SKJr  S SKJr  SSK	J
r
   " S S	\
5      rS
\4S jrg)    N   )get_module_from_name)is_fouroversix_available)ModelQuantizationConfig)FourOverSixConfig)ConversionOpsc                       \ rS rSrS r   SS\\\R                  4   S\R                  R                  S-  S\S-  S\\   S-  S\\\R                  4   4
S	 jjrS
rg)FourOverSixQuantize   c                     Xl         g )Nhf_quantizer)selfr   s     v/root/GenerationalWealth/GenerationalWealth/venv/lib/python3.13/site-packages/transformers/integrations/fouroversix.py__init__FourOverSixQuantize.__init__   s    (    N
input_dictmodelfull_layer_namemissing_keysreturnc                    U R                   R                  R                  (       a  U$ [        X#5      u  pgUR	                  SS5      S   n[        UR                  5       5      S   n	U	R                  U S3SS5      n
X   S   nUR                  X5      n[        Xj5      (       a  [        Xj5        U H  nUR                  U5        M     U Vs0 s H  nU SU 3X   _M     sn$ s  snf )a2  
We need to store some parameters to create the quantized weight. For example, fouroversix
requires 4 values that are stored in the checkpoint to recover the quantized weight. So we
store them in a dict that is stored in hf_quantizer for now as we can't save it in the op
since we create an op per tensor.
.   r    )r   quantization_configkeep_master_weightsr   rsplitlistkeysreplaceget_quantized_parametershasattrdelattrdiscard)r   r   r   r   r   kwargsmodule_module_namefull_parameter_nameparameter_name	parameterquantized_parameterskeyquantized_keys                  r   convertFourOverSixQuantize.convert   s     00DD(@	%,,S!4Q7":??#45a8,44}A5FAN3A6	%>>~Y 6**F+ C  % 
 "6
!5 m1]O,.B.QQ!5
 	
 
s   C$r   )NNN)__name__
__module____qualname____firstlineno__r   dictstrtorchTensornnModuler    r1   __static_attributes__ r   r   r
   r
      s    ) )-&*)-&
ell*+&
 xx%&
 t	&

 3i$&&
 
c5<<	 &
 &
r   r
   configc                 \   [        U R                  U R                  U R                  U R                  U R
                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  S9$ )N)activation_dtypeactivation_scale_ruledtypegradient_dtypegradient_scale_ruler   matmul_backendoutput_dtypequantize_backend
scale_ruleweight_dtypeweight_scale_2dweight_scale_rulemodules_to_not_convertmodule_config_overrides)r   rA   rB   rC   rD   rE   r   rF   rG   rH   rI   rJ   rK   rL   rM   rN   )r?   s    r   adapt_fouroversix_configrO   <   s    "00$::ll,,"66"66,,((00$$((.. 22%<< & > > r   )r9   quantizers.quantizers_utilsr   utilsr   fouroversixr   &transformers.utils.quantization_configr   core_model_loadingr   r
   rO   r>   r   r   <module>rU      s<     > , 3 D .*
- *
Z%6 r   