o
    i                     @   s   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dZdej
dej
dej
ded	edej
fddZddedefddZdefd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              
   C   sT   |dksJ | j d | dksJ |  dksJ d|f}t| |||tj|||dS )N   r      )quant_dtyper	   r
   r   )shapedimr   torchint32)r   r   r   r	   r
   r   r   
block_size r   R/home/ubuntu/.local/lib/python3.10/site-packages/torchao/quantization/qat/utils.py _fake_quantize_per_channel_group   s   	r   c              	   C   sJ   ddl m} || || t| }t| |||tj||d}|| | 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   fqr   r   r   _fake_quantize_per_token.   s   	r    Tn_bit	symmetricc                 C   sB   |rd| d   }d| d  d }||fS d}d|  d }||fS )Nr   r   r   r   )r!   r"   qminqmaxr   r   r   _get_qmin_qmaxE   s   r%   old_api_objectc                 C   s   t d| jj  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&   r   r   r   _log_deprecation_warningO   s
   r+   )T)r'   typingr   r   %torchao.quantization.quant_primitivesr   r   torchao.quantization.utilsr   INTTensorintr   r    boolr%   r+   r   r   r   r   <module>   sL   


