
    iy              
          S r SSKrSSKJrJr  SSKJrJrJr  SSK	r	SSK
Jr  SSKJr  SSKJrJrJr  SSKJr  SS	KJrJrJrJrJrJrJrJrJrJr  SS
KJ r   / SQr!SSS\"4S jr#SSS\"4S jr$SSS\"4S jr%SSS\"4S jr& " S S\\5      r' " S S\'5      r( " S S\(5      r) " S S\(5      r* " S S\(5      r+\(RY                  \SS\	RZ                  \	R\                  SS9r/ \(RY                  \S S!\	R`                  \	Rb                  S"S9r2 \(RY                  \SSS\	RZ                  S#S$9r3 \)RY                  \S%9r4\)RY                  \S%9r5\4r6\5r7\(RY                  \S S!\	R`                  \	Rp                  S"SS&9r9 \(RY                  \\	Rt                  \	RZ                  SSSS#S'9r; \(RY                  \\	Rt                  S\	Rx                  S#S(9r=\(RY                  \SS\	RZ                  \	R\                  SS9r> \*RY                  \SS\	RZ                  S)9r? \*RY                  \S S!\	R`                  \	Rb                  S*9r@ \*RY                  \S S!\	R`                  \	Rp                  S*9rA \*RY                  \S+S!\	R`                  \	Rb                  S,S-9rB \*RY                  \S+S!\	R`                  \	Rp                  S,S-9rC \+RY                  \\R                  \	R                  \" 5       S.9rF \+RY                  \\R                  \	R                  \" S/5      S.9rI \+RY                  \\R                  \	R                  \" S5      S.9rJ S0 rKS1 rLS2 rMS3 rNS4 rOg)5z6Implements modules  used to perform fake quantization.    N)ABCabstractmethod)AnyOptionalTuple)Node)Module)PerAxisPerGroup	PerTensor)AffineQuantizedMinMaxObserver)
AffineQuantizedObserverBaseFixedQParamsObserverHistogramObserverMappingTypeMovingAverageMinMaxObserver%MovingAveragePerChannelMinMaxObserverZeroPointDomain
_with_args)default_fixed_qparams_range_0to1_observer,default_fixed_qparams_range_neg1to1_observer)_fake_quantize_affine)FakeQuantizeBaseFakeQuantizeFixedQParamsFakeQuantizeFusedMovingAvgObsFakeQuantizeAffineFakeQuantizedisable_fake_quantdisable_observerenable_fake_quantenable_observerdefault_fake_quantdefault_weight_fake_quantdefault_dynamic_fake_quant.default_fixed_qparams_range_neg1to1_fake_quant+default_fixed_qparams_range_0to1_fake_quant*default_symmetric_fixed_qparams_fake_quant'default_affine_fixed_qparams_fake_quant%default_per_channel_weight_fake_quantdefault_embedding_fake_quant!default_embedding_fake_quant_4bitdefault_histogram_fake_quantdefault_fused_act_fake_quantdefault_fused_wt_fake_quant'default_fused_per_channel_wt_fake_quant(fused_wt_fake_quant_range_neg_127_to_1274fused_per_channel_wt_fake_quant_range_neg_127_to_127default_affine_fake_quantdefault_groupwise_fake_quant"default_affine_per_axis_fake_quantqschemeztorch.qschemereturnc                 f    U [         R                  [         R                  [         R                  4;   $ N)torchper_channel_symmetricper_channel_affine per_channel_affine_float_qparamsr5   s    f/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/torchao/quantization/pt2e/fake_quantize.py_is_per_channelr?   G   s/    ##  ..      c                 H    U [         R                  [         R                  4;   $ r8   )r9   per_tensor_symmetricper_tensor_affiner=   s    r>   _is_per_tensorrD   O   s    u1153J3JKKKr@   c                 H    U [         R                  [         R                  4;   $ r8   )r9   rB   r:   r=   s    r>   _is_symmetric_quantrF   S   s    u1153N3NOOOr@   c                 *    U [         R                  4;   $ r8   )r9   r<   r=   s    r>   _is_float_qparamsrH   W   s    ..  r@   c                     ^  \ rS rSr% Sr\R                  \S'   \R                  \S'   SU 4S jjr\	S 5       r
\	S	 5       r\R                  R                  SS
\SS4S jj5       r\R                  R                  S 5       r\R                  R                  SS
\SS4S jj5       r\R                  R                  S 5       r\S 5       rSrU =r$ )r   ]   a  Base fake quantize module.

Base fake quantize module
Any fake quantize implementation should derive from this class.

Concrete fake quantize module should follow the same API. In forward, they will update
the statistics of the observed Tensor and fake quantize the input. They should also provide a
`calculate_qparams` function that computes the quantization parameters given
the collected statistics.

fake_quant_enabledobserver_enabledr6   Nc                    > [         TU ]  5         U R                  S[        R                  " S/[        R
                  S95        U R                  S[        R                  " S/[        R
                  S95        g)z,Set fake_quant_enabled and observer_enabled.rK      dtyperL   N)super__init__register_bufferr9   tensoruint8)self	__class__s    r>   rR   FakeQuantizeBase.__init__m   sT     	15<<5;;3WX/qc1UVr@   c                     g r8    )rV   xs     r>   forwardFakeQuantizeBase.forwardv       r@   c                     g r8   rZ   )rV   kwargss     r>   calculate_qparams"FakeQuantizeBase.calculate_qparamsz   r^   r@   enabledc                 4    U(       a  SOSU R                   S'   g NrN   r   )rK   rV   rc   s     r>   r    "FakeQuantizeBase.enable_fake_quant~   s    *1Qq"r@   c                 &    U R                  S5        g NF)r    rV   s    r>   r   #FakeQuantizeBase.disable_fake_quant   s    u%r@   c                 4    U(       a  SOSU R                   S'   g re   )rL   rf   s     r>   r!    FakeQuantizeBase.enable_observer   s    (/1Qa r@   c                 &    U R                  S5        g ri   )r!   rj   s    r>   r   !FakeQuantizeBase.disable_observer   s    U#r@   c                 ,    [        U 40 UD6nSUl        U$ )Nz'torchao.quantization.pt2e.fake_quantize)r   
__module__)clsr`   fake_quant_constructors      r>   	with_argsFakeQuantizeBase.with_args   s$    !+C!:6!: -V)%%r@   rZ   )r6   N)T)__name__rq   __qualname____firstlineno____doc__r9   Tensor__annotations__rR   r   r\   ra   jitexportboolr    r   r!   r   classmethodrt   __static_attributes____classcell__rW   s   @r>   r   r   ]   s    
 $ll"W     YY9 9 9 9 YY& & YY7t 7t 7 7 YY$ $ & &r@   r   c                     ^  \ rS rSr% Sr\R                  \S'   \R                  \S'   \SSS4U 4S jjr	\R                  R                  S 5       rS	 r\R                  R                  S
 5       rU 4S jrU 4S jrSrU =r$ )r      a  Simulate the quantize and dequantize operations in training time.

The output of this module is given by::

    x_out = (
      clamp(round(x/scale + zero_point), quant_min, quant_max) - zero_point
    ) * scale

* :attr:`is_dynamic` indicates whether the fake quantie is a placeholder for dynamic quantization
  operators (choose_qparams -> q -> dq) or static quantization operators (q -> dq)

* :attr:`scale` defines the scale factor used for quantization.

* :attr:`zero_point` specifies the quantized value to which 0 in floating point maps to

* :attr:`fake_quant_enabled` controls the application of fake quantization on tensors, note that
  statistics can still be updated.

* :attr:`observer_enabled` controls statistics collection on tensors

* :attr:`dtype` specifies the quantized dtype that is being emulated with fake-quantization,
    allowable values are torch.qint8 and torch.quint8.

Args:

    observer (module): Module for observing statistics on input tensors and calculating scale
      and zero-point.
    observer_kwargs (optional): Arguments for the observer module

Attributes:
    activation_post_process (Module): User provided module that collects statistics on the input tensor and
      provides a method to calculate scale and zero-point.

scale
zero_pointNFc                 ~  > [         TU ]  5         Ub  Ub  X#::  d   S5       eUR                  S[        R                  5      n[        US5      (       a(  [        [        US0 5      S0 5      R                  SU5      n[        R                  " U5      R                  U::  d   S5       eU[        R                  " U5      R                  ::  d   S5       eUR                  X#S.5        XES'   U" S0 UD6U l        U R                  R                  U l        U R                  R                  U l        U R                  R                  U l        [        U R                  R                   5      (       a  [        R"                  nO[        R$                  nU R'                  S	[        R(                  " S
/[        R"                  S95        U R'                  S[        R(                  " S/US95        U R                  R*                  U l        U R                  R                   U l        [        U R                  S5      (       a  U R                  R,                  OSU l        [/        U R                   5      (       d7  [1        U R                   5      (       d   S[3        U R                   5      -   5       e[/        U R                   5      U l        g )Nz1quant_min must be less than or equal to quant_maxrP   pkeywordszquant_min out of boundzquant_max out of bound)	quant_min	quant_max
is_dynamicr         ?rO   r   r   ch_axiszYOnly per channel and per tensor quantization are supported in fake quantize got qscheme: rZ   )rQ   rR   getr9   quint8hasattrgetattriinfominmaxupdateactivation_post_processr   r   r   rH   r5   floatintrS   rT   rP   r   r?   rD   stris_per_channel)	rV   observerr   r   r   observer_kwargsrP   zero_point_dtyperW   s	           r>   rR   FakeQuantize.__init__   s@    	 Y%:) C) $''>Ex%%  #r :JKOOU ;;u%))Y6P8PP6E 2 6 66P8PP6""#ST(2%'/'B/'B$ 55??55??66AAT99AABB${{$yyWellC5&LM\5<<CS+TU1177
33;; t33Y?? ((00 	
 t||,,t||0L0L 	
$,, 	
L
 .dll;r@   c                 6    U R                   R                  5       $ r8   r   ra   rj   s    r>   ra   FakeQuantize.calculate_qparams       ++==??r@   c                 $   U R                   S   S:X  Ga  U R                  UR                  5       5        U R                  5       u  p#UR	                  U R
                  R                  5      UR	                  U R                  R                  5      p2U R
                  R                  UR                  :w  aJ  U R
                  R                  UR                  5        U R                  R                  UR                  5        U R
                  R                  U5        U R                  R                  U5        U R                  S   S:X  a  U R                  (       ac  [        R                  " UU R
                  U R                  U R                  U R                  R                   U R                  R"                  5      nU$ [        R$                  " UU R
                  U R                  U R                  R                   U R                  R"                  5      nU$ )Nr   rN   )rL   r   detachra   tor   devicer   shaperesize_copy_rK   r   r9    fake_quantize_per_channel_affiner   r   r   fake_quantize_per_tensor_affinerV   X_scale_zero_points       r>   r\   FakeQuantize.forward   s     #q(((4"&"8"8":F		$**++,t556   zz6<</

""6<<0''(9(9:JJV$OO!!+.""1%*""::JJOOLL00::00::   99JJOO00::00:: r@   c                    SU R                    SU R                   SU R                  R                   SU R                  R                   SU R
                   SU R                   SU R                   SU R                   S	U R                   3$ )
Nfake_quant_enabled=, observer_enabled=, quant_min=, quant_max=, dtype=
, qscheme=z
, ch_axis=, scale=, zero_point=)
rK   rL   r   r   r   rP   r5   r   r   r   rj   s    r>   
extra_reprFakeQuantize.extra_repr  s     "$"9"9!::MdNcNcMd e55??@TMiMiMsMsLt uZZL
4<<.
4<<. QZZLdoo->@	
r@   c                 j   > [         TU ]  XU5        U R                  XS-   '   U R                  XS-   '   g Nr   r   )rQ   _save_to_state_dictr   r   )rV   destinationprefix	keep_varsrW   s       r>   r    FakeQuantize._save_to_state_dict   s6     	#KC(,

W$%-1__\)*r@   c           	      $  > SS/nU H  n	X)-   n
X;   a  X   nU	S:X  a&  U R                   R                  UR                  5        O-U	S:X  d   eU R                  R                  UR                  5        [        R
                  R                  5       (       aH  U	S:X  a  U R                   R                  U5        M  U	S:X  d   eU R                  R                  U5        M  M  U(       d  M  UR                  U
5        M     [        TU ])  UUUUUUU5        g r   )r   r   r   r   r9   r|   is_scriptingr   appendrQ   _load_from_state_dict)rV   
state_dictr   local_metadatastrictmissing_keysunexpected_keys
error_msgslocal_statenamekeyvalrW   s               r>   r   "FakeQuantize._load_from_state_dict'  s     -D-C  o
 7?JJ&&syy1<///OO++CII6 99))++w

((-#|333--c2 , ##C(-  . 	%	
r@   )r   r   rP   r   r   r5   r   r   )rv   rq   rw   rx   ry   r9   rz   r{   r   rR   r|   r}   ra   r\   r   r   r   r   r   r   s   @r>   r   r      s    !F << -1<f YY@ @ D YY
 
=,
 ,
r@   r   c                      ^  \ rS rSrSrU 4S jr\R                  R                  S 5       r	\R                  R                  S 5       r
SrU =r$ )r   iV  zSimulate quantize and dequantize in training time.

Simulate quantize and dequantize with fixed quantization
parameters in training time. Only per tensor quantization
is supported.
c                   > [         TU ]  US9  [        U R                  5      [        :X  d.   U R
                  R                   S[        R                   35       eXl        U R                  R                  U l        U R                  R                  U l	        [        U R                  5      (       d   S[        U R                  5      -   5       eg )Nr   z's observer must be a zWOnly per tensor quantization is supported FixedQParamsFakeQuantize module, got qscheme:)rQ   rR   typer   r   rW   rv   _observer_ctrr   r   rD   r5   r   )rV   r   rW   s     r>   rR   !FixedQParamsFakeQuantize.__init___  s    (+D0015II 	
~~&&''=>R>[>[=\]	
I &1177
66AAdll++ 	
?$,, 	
+r@   c                 2    U R                   U R                  4$ r8   )r   r   rj   s    r>   ra   *FixedQParamsFakeQuantize.calculate_qparamsm  s    zz4??**r@   c                     SU R                    SU R                   SU R                   SU R                   SU R                   SU R
                  R                   SU R
                  R                   SU R                   3$ )	z:Define a string representation of the object's attributes.r   r   r   r   r   r   r   r   )	rK   rL   r   r   rP   r   r   r   r5   rj   s    r>   r   #FixedQParamsFakeQuantize.extra_reprq  s     "$"9"9!::MdNcNcMd eZZLdoo-> ?ZZLT-I-I-S-S,T U55??@
4<<.Z	
r@   )r   r   r   )rv   rq   rw   rx   ry   rR   r9   r|   r}   ra   r   r   r   r   s   @r>   r   r   V  sI    
 YY+ + YY
 
r@   r   c                   :  ^  \ rS rSrSr\SS4S\S\S\S\S	S
4
U 4S jjjr\	R                  R                  S	\\	R                  \	R                  4   4S j5       r\	R                  R                  S	\4S j5       rS\	R                  S	\	R                  4S jrSrU =r$ )r   i|  a  Define a fused module to observe the tensor.

Fused module that is used to observe the input tensor (compute min/max), compute
scale/zero_point and fake_quantize the tensor.
This module uses calculation similar MovingAverageMinMaxObserver for the inputs,
to compute the min/max values in order to compute the scale/zero_point.
The qscheme input in the observer is used to differentiate between symmetric/affine
quantization scheme.

The output of this module is given by
x_out = (clamp(round(x/scale + zero_point), quant_min, quant_max)-zero_point)*scale

Similar to :class:`~torchao.quantization.pt2e.FakeQuantize`, and accepts the same attributes as the
base class.

r      r   r   r   r   r6   Nc                   > [         TU ]  " XU40 UD6  [        U R                  [        [
        45      (       d   S5       eU R                  S[        R                  " S/[        R                  S95        U R                  S[        R                  " S/[        R                  S95        [        U R                  R                  5      U l        g )NzLFused observer+fake_quant module only works with MovingAverageMinMaxObserverrK   rN   rO   rL   )rQ   rR   
isinstancer   r   r   rS   r9   rT   longrF   r5   is_symmetric_quant)rV   r   r   r   r   rW   s        r>   rR   &FusedMovingAvgObsFakeQuantize.__init__  s     	iK?K(((*OP
 
 	
 [		
 
 	15<<5::3VW/qc1TU"5((00#
r@   c                 6    U R                   R                  5       $ r8   r   rj   s    r>   ra   /FusedMovingAvgObsFakeQuantize.calculate_qparams  r   r@   c                 ,   SU R                    SU R                   SU R                   SU R                   SU R                   SU R
                  R                   SU R
                  R                   SU R                   S	U R
                  R                   3$ )
Nr   r   r   r   r   r   r   r   z, reduce_range=)
rK   rL   r   r   rP   r   r   r   r5   reduce_rangerj   s    r>   r   (FusedMovingAvgObsFakeQuantize.extra_repr  s     "$"9"9!::MdNcNcMd eZZLdoo->htzzl S55??@TMiMiMsMsLt u||nOD4P4P4]4]3^`	
r@   r   c                    [         R                  " UU R                  U R                  U R                  R
                  U R                  R                  U R                  U R                  U R                  R                  U R                  R                  U R                  R                  U R                  U R                  U R                  5      $ r8   )r9   fused_moving_avg_obs_fake_quantrL   rK   r   min_valmax_valr   r   averaging_constantr   r   r   r   r   )rV   r   s     r>   r\   %FusedMovingAvgObsFakeQuantize.forward  s    44!!##((00((00JJOO((;;((22((22LL##
 	
r@   )r   )rv   rq   rw   rx   ry   r   r   r   rR   r9   r|   r}   tuplerz   ra   r   r   r\   r   r   r   s   @r>   r   r   |  s    & 4	

 
 	

 
 

 
( YY@5u||)C#D @ @ YY
C 
 

 
%,, 
 
r@   r   c                      \ rS rSr% Sr\R                  \S'   \R                  \S'   \S4S\	4S jjr
\R                  R                  S\\R                  \R                  4   4S	 j5       rS
\R                  S\R                  4S jr\R                  R                  S\4S j5       rS\R$                  R&                  S\4S jrSrg)r   i  a2  Simulate quantize and dequantize with affine quantization in training time.

This fake quantize module supports all granularities including per-tensor,
per-axis, per-group, per-block, per-row, and per-token quantization through
the affine quantization primitives. It works with AffineQuantizedObserverBase
subclasses like AffineQuantizedMinMaxObserver and
AffineQuantizedMovingAverageMinMaxObserver.

The output of this module is given by::

    x_out = fake_quantize_affine(x, block_size, scale, zero_point, ...)

Args:
    observer (module): Module for observing statistics on input tensors and
        calculating scale and zero-point. Must be a subclass of
        AffineQuantizedObserverBase.
    is_dynamic (bool): Whether this is for dynamic quantization.
    **observer_kwargs: Arguments passed to the observer constructor.

Attributes:
    activation_post_process (AffineQuantizedObserverBase): The observer instance.
    scale (Tensor): The quantization scale.
    zero_point (Tensor): The quantization zero point.
    target_dtype (torch.dtype): The target quantized dtype.
    quant_min (Optional[int]): Minimum quantization value.
    quant_max (Optional[int]): Maximum quantization value.
    zero_point_domain (ZeroPointDomain): Domain of the zero point.
    mapping_type (MappingType): Mapping type for quantization.
    is_dynamic (bool): Whether this is dynamic quantization.
    block_size (Optional[Tuple[int, ...]]): Block size for groupwise quantization.

Example::

    >>> # Per-tensor fake quantize
    >>> fq = AffineFakeQuantize(
    ...     observer=AffineQuantizedMinMaxObserver,
    ...     mapping_type=MappingType.ASYMMETRIC,
    ...     target_dtype=torch.uint8,
    ...     granularity=PerTensor(),
    ... )
    >>> x = torch.randn(10, 20)
    >>> y = fq(x)

    >>> # Groupwise fake quantize
    >>> fq = AffineFakeQuantize(
    ...     observer=AffineQuantizedMinMaxObserver,
    ...     mapping_type=MappingType.SYMMETRIC,
    ...     target_dtype=torch.int8,
    ...     granularity=PerGroup(128),
    ... )
    >>> x = torch.randn(10, 256)
    >>> y = fq(x)
r   r   Fr   c                    [         R                  U 5        X#S'   U" S0 UD6U l        U R                  R                  U l        U R                  R                  U l        U R                  R
                  U l        U R                  R                  U l        U R                  R                  U l        U R                  R                  U l        X l	        U R                  [        R                  :X  a  [        R                  O[        R                  nU R                  S[        R                   " S/[        R                  S95        U R                  S[        R                   " S/US95        S U l        SU l        g )	Nr   r   r   rO   r   r   FrZ   )r   rR   r   target_dtyper   r   zero_point_domainmapping_typegranularityr   r   FLOATr9   r   r   rS   rT   
block_size_initialized)rV   r   r   r   r   s        r>   rR   AffineFakeQuantize.__init__  s)    	!!$'(2%DL E
E
$ !88EE55??55??!%!=!=!O!O 88EE77CC$ %%)>)>> KK 	 	WellC5&LM\5<<CS+TU59!r@   r6   c                 6    U R                   R                  5       $ )z=Calculate the quantization parameters (scale and zero_point).r   rj   s    r>   ra   $AffineFakeQuantize.calculate_qparams  s     ++==??r@   r   c           
      D   U R                   (       dA  U R                  UR                  5       5        U R                  R                  U l        SU l         U R                  S   S:X  Ga:  U R                  UR                  5       5        U R                  5       u  p#UR                  U R                  R                  5      nUR                  U R                  R                  5      nU R                  R                  UR                  :w  aJ  U R                  R                  UR                  5        U R                  R                  UR                  5        U R                  R                  U5        U R                  R                  U5        U R                  R                  U l        U R                  S   S:X  al  U R                  c   S5       e[        UU R                  U R                  U R                  U R                  U R                   U R"                  U R$                  5      nU$ )NTr   rN   zblock_size must be set before fake quantization. Ensure the model is run at least one forward pass with both observer and fake_quant disabled.)r   r   r   r   rL   ra   r   r   r   r   r   r   r   rK   r   r   r   r   r   r   s       r>   r\   AffineFakeQuantize.forward$  s     ((4"::EEDO $D  #q(((4"&"8"8":FYYtzz001F%..)?)?@Kzz6<</

""6<<0''(9(9:JJV$OO!!+."::EEDO""1%*??. >.
 &

!!&&	A r@   c                 $   SU R                    SU R                   SU R                   SU R                   SU R                   SU R
                   SU R                   SU R                   S	U R                   S
U R                   SU R                   3$ )Nr   r   r   r   z, target_dtype=z, granularity=z, mapping_type=z, zero_point_domain=r   r   z, block_size=)rK   rL   r   r   r   r   r   r   r   r   r   rj   s    r>   r   AffineFakeQuantize.extra_reprJ  s     "$"9"9!: ;  $ 5 56 7(T^^4D E --.nT=M=M<N O --. /!!%!7!7 8 9ZZLdoo-> ?//*,		
r@   modelobserver_nodec                 :    U R                   R                  X5        g)a  
Converts the fake quantize node in the graph into its quantized representation.

This method delegates to the underlying activation_post_process (observer)'s
convert method, which handles the creation of quantize_affine/dequantize_affine
operations in the graph.

Args:
    model: graph module to convert the fake quantize node in
    observer_node: the fake quantize node to convert
N)r   convert)rV   r  r  s      r>   r  AffineFakeQuantize.convertW  s     	$$,,UBr@   )
r   r   r   r   r   r   r   r   r   r   N)rv   rq   rw   rx   ry   r9   rz   r{   r   r~   rR   r|   r}   r   ra   r\   r   r   fxGraphModuler   r  r   rZ   r@   r>   r   r     s    4l << / "" ""H YY@5u||)C#D @ @$ $%,, $L YY

C 

 

CUXX11 C$ Cr@   r   r   T)r   r   r   rP   r5   r   i   FrN   )r   r   r   r   rP   r   r   )r   r   r   rP   r5   r   r   )r   r5   rP   r   r   r   r   )r   r5   r   rP   r   )r   r   r   rP   )r   r   r   rP   r5   ig      0?)r   r   r   rP   r5   eps)r   r   r   r      c                     [        U [        R                  R                  5      (       aR  U R                  R
                  R                  SS5      S   n[        R                  " SSU5      nUS:H  =(       d    US:H  $ g)zFReturn true if given mod is an instance of FakeQuantize script module..rN   z\.___torch_mangle_\d+ z4torchao.quantization.pt2e.fake_quantize.FakeQuantizezEtorchao.quantization.pt2e.fake_quantize.FusedMovingAvgObsFakeQuantizeF)	r   r9   r|   RecursiveScriptModule_cqualified_namesplitresub)modsuffixr   s      r>   _is_fake_quant_script_moduler  &  sr    #uyy6677&&,,S!4Q7vv.F;JJ WVW	

 r@   c                 p    [        U [        5      (       d  [        U 5      (       a  U R                  5         gg)zDisable fake quantization for the module.

Disable fake quantization for this module, if applicable. Example usage::

  # model is any PyTorch model
  model.apply(torchao.quantization.pt2e.disable_fake_quant)

N)r   r   r  r   r  s    r>   r   r   4  s/     #'((,H,M,M  -Nr@   c                 p    [        U [        5      (       d  [        U 5      (       a  U R                  5         gg)zEnable fake quantization for the module.

Enable fake quantization for this module, if applicable. Example usage::

  # model is any PyTorch model
  model.apply(torchao.quantization.pt2e.enable_fake_quant)

N)r   r   r  r    r  s    r>   r    r    A  s/     #'((,H,M,M -Nr@   c                 p    [        U [        5      (       d  [        U 5      (       a  U R                  5         gg)zDisable observation for this module.

Disable observation for this module, if applicable. Example usage::

  # model is any PyTorch model
  model.apply(torchao.quantization.pt2e.disable_observer)

N)r   r   r  r   r  s    r>   r   r   N  s/     #'((,H,M,M -Nr@   c                 p    [        U [        5      (       d  [        U 5      (       a  U R                  5         gg)zEnable observation for this module.

Enable observation for this module, if applicable. Example usage::

  # model is any PyTorch model
  model.apply(torchao.quantization.pt2e.enable_observer)

N)r   r   r  r!   r  s    r>   r!   r!   [  s/     #'((,H,M,M -Nr@   )Pry   r  abcr   r   typingr   r   r   r9   torch.fxr   torch.nnr	   torchao.quantizationr
   r   r   .torchao.quantization.pt2e._affine_quantizationr   "torchao.quantization.pt2e.observerr   r   r   r   r   r   r   r   r   r   %torchao.quantization.quant_primitivesr   __all__r~   r?   rD   rF   rH   r   r   r   r   r   rt   r   rC   r"   qint8rB   r#   r$   r%   r&   r'   r(   r:   r)   r<   r*   quint4x2r+   r,   r-   r.   r/   r0   r1   
ASYMMETRICrU   r2   	SYMMETRICint8r3   r4   r  r   r    r   r!   rZ   r@   r>   <module>r*     s   = 	 # ' '    = =  @_  LO L LP PT P 4 7&sF 7&t|
# |
~#
| #
LB
L B
JbC bCJ "++(
,,## ,   )22(
++&& 3  
 *33(
,, 4   2J1S1S9 2T 2 . /G.P.P6 /Q / +
 3 + +V '(4(>(>2
++'' )? ) %  ,55222
,,  6   
 %1$:$:222
.. %; % !  ,55
,,##  6   
  =FF(
,,	  G   
 <EE(
++&& F   +H*Q*Q2
++'' +R + ' ,I+R+R(
++&& ,S , (
 "++6kk++ ,  5 /88*''	 9    2;;*&&	  <   
 &8%A%A*&&
	 &B & "

!
 

r@   