
    h                     f   S SK r S SKJr  S SKrS SKJrJr  S SKJr  \R                  4S\R                  S\R                  S\R                  S\S	\S
\S\S\R                  4S jjrS\R                  S\R                  S\R                  S\S	\S\R                  4S jrSS\S\4S jjrS\4S jrg)    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                     US:  d   eU R                   S   U-  S:X  d   eU R                  5       S:X  d   eSU4n[        U UUU[        R                  UUUS9$ )N   r      )quant_dtyper
   r   r   )shapedimr   torchint32)r   r   r	   r
   r   r   r   
block_sizes           X/home/james-whalen/.local/lib/python3.13/site-packages/torchao/quantization/qat/utils.py _fake_quantize_per_channel_groupr      sq     >>;;r?Z'1,,,99;!ZJ KK+	 	    c           
          SSK Jn  U" XU5        [        U 5      n[        U UUU[        R
                  UUS9nUR                  U 5      R                  U R                  5      $ )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%e[A*51J	KK
B ==""5;;//r   n_bit	symmetricc                 X    U(       a  SU S-
  -  * nSU S-
  -  S-
  nX#4$ SnSU -  S-
  nX#4$ )Nr   r   r    )r$   r%   qminqmaxs       r   _get_qmin_qmaxr*   E   sO    uqy!"UQY!# < %x!|<r   old_api_objectc                 ^    [         R                  " SU R                  R                  -  5        g)zf
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   s+    
 MM	( 
"
"
+
+)	,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)<)<<<LL  	
   ' \\20<<0LL0 0 	0
 0 \\0.# $ S r   