
    Pi                        d dl Z d dlmZ d dlZd dlmZmZ d dlmZ ej	        fdej
        dej
        dej
        ded	ed
ededej
        fdZdej
        dej
        dej
        ded	edej
        fdZddedefdZdefdZdS )    N)Any)ZeroPointDomain_fake_quantize_affine)_get_per_token_block_sizeinputscaleszero_points	quant_min	quant_max
group_sizezero_point_domainreturnc           
          |dk    sJ | j         d         |z  dk    sJ |                                 dk    sJ d|f}t          | |||t          j        |||          S )N   r      )quant_dtyper
   r   r   )shapedimr   torchint32)r   r   r	   r
   r   r   r   
block_sizes           r/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/torchao/quantization/qat/utils.py _fake_quantize_per_channel_groupr      s     >>>>;r?Z'1,,,,99;;!ZJ K+	 	 	 	    c           	          ddl m}  || ||           t          |           }t          | |||t          j        ||          }|                    |                               | j                  S )Nr   )!_per_token_quant_qparam_dim_check)r   r
   r   )	$torch.ao.quantization.fx._decomposedr   r   r   r   r   
reshape_astodtype)r   r   r	   r
   r   r   r   fqs           r   _fake_quantize_per_tokenr#   .   s     WVVVVV%%eV[AAA*511J	K
 
 
B ==""5;///r   Tn_bit	symmetricc                 L    |rd| dz
  z   }d| dz
  z  dz
  }n
d}d| z  dz
  }||fS )Nr   r   r    )r$   r%   qminqmaxs       r   _get_qmin_qmaxr*   E   sL     uqy!"UQY!#%x!|$<r   old_api_objectc                 H    t          j        d| j        j        z             dS )zr
    Log a helpful deprecation message pointing users to the new QAT API,
    only once per deprecated class.
    a   '%s' is deprecated and will be removed in a future release. Please use the following API instead:

    base_config = Int8DynamicActivationInt4WeightConfig(group_size=32)
    quantize_(model, QATConfig(base_config, step="prepare"))
    # train (not shown)
    quantize_(model, QATConfig(base_config, step="convert"))

Alternatively, if you prefer to pass in fake quantization configs:

    activation_config = IntxFakeQuantizeConfig(torch.int8, "per_token", is_symmetric=False)
    weight_config = IntxFakeQuantizeConfig(torch.int4, group_size=32)
    qat_config = QATConfig(
        activation_config=activation_config,
        weight_config=weight_config,
        step="prepare",
    )
    quantize_(model, qat_config)

Please see https://github.com/pytorch/ao/issues/2630 for more details.
        N)warningswarn	__class____name__)r+   s    r   _log_deprecation_warningr1   O   s7    
 M	( 
"
+)	,    r   )T)r-   typingr   r   %torchao.quantization.quant_primitivesr   r   torchao.quantization.utilsr   INTTensorintr   r#   boolr*   r1   r'   r   r   <module>r9      s                       *9)< <L  	
   ' \   20<0L0 0 	0
 0 \0 0 0 0. # $    S      r   