
    #j                         d dl Z ddlmZ ddlmZ  e            rd dlmZ d dlmZ ddl	m
Z
  G d d	e
          Zd
efdZdS )    N   )get_module_from_name)is_fouroversix_available)ModelQuantizationConfig)FourOverSixConfig)ConversionOpsc                       e Zd Zd Z	 	 	 d	deeej        f         dej        j	        dz  dedz  de
e         dz  deeej        f         f
dZdS )
FourOverSixQuantizec                     || _         d S )N)hf_quantizer)selfr   s     o/lsinfo/ai/hellotax_ai/base_platform/venv/lib/python3.11/site-packages/transformers/integrations/fouroversix.py__init__zFourOverSixQuantize.__init__   s    (    N
input_dictmodelfull_layer_namemissing_keysreturnc                    | j         j        j        r|S t          ||          \  }}|                    dd          d         t          |                                          d         }|                     ddd          }	||         d         }
|                    |	|
          t          ||	          rt          ||	           |D ]}|                    |           fdD             S )aZ  
        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    c                 ,    i | ]} d | |         S )r    ).0quantized_keymodule_namequantized_parameterss     r   
<dictcomp>z/FourOverSixQuantize.convert.<locals>.<dictcomp>6   s?     
 
 
 ,,],,.B=.Q
 
 
r   )r   quantization_configkeep_master_weightsr   rsplitlistkeysreplaceget_quantized_parametershasattrdelattrdiscard)r   r   r   r   r   kwargsmodule_full_parameter_nameparameter_name	parameterkeyr   r   s               @@r   convertzFourOverSixQuantize.convert   s)    0D 	(@@	%,,S!44Q7":??#4#455a8,445F5F5FANN23A6	%>>~yYY 6>** 	,FN+++  	& 	&C  %%%%
 
 
 
 
!5
 
 
 	
r   )NNN)__name__
__module____qualname__r   dictstrtorchTensornnModuler$   r2   r   r   r   r
   r
      s        ) ) ) )-&*)-&
 &
el*+&
 x%&
 t	&

 3i$&&
 
c5<	 &
 &
 &
 &
 &
 &
r   r
   configc                     t          | j        | j        | j        | j        | j        | j        | j        | j        | j	        | j
        | j        | j        | j        | j        | j                  S )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   r>   r?   r@   rA   rB   r"   rC   rD   rE   rF   rG   rH   rI   rJ   rK   )r<   s    r   adapt_fouroversix_configrL   <   sr    "0$:l,"6"6,(0$(. 2%< & >   r   )r8   quantizers.quantizers_utilsr   utilsr   fouroversixr   &transformers.utils.quantization_configr   core_model_loadingr   r
   rL   r   r   r   <module>rR      s     > > > > > > , , , , , ,  4333333 D D D D D D . . . . . .*
 *
 *
 *
 *
- *
 *
 *
Z%6      r   