
    h                        S SK r S SKJr  S SKJr  S SKJr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  S SKJr  S S	KJrJr  S S
KJr  S SKJrJrJrJr  S SKJr  S SKJ r   S SK!J"r"   S SK#J$r$  \
RL                  RO                  SS5      r(\"" \(5      r)S/r*S r+S r,S r-S r.S r/\)S\
R`                  S\1S\
R`                  S\
R`                  S\
R`                  S\	\
R`                     S\\2   S\
R`                  4S  j5       r3S! r4S\54S" jr6S#\4S$ jr7S% r8S& r9S' r:S( r;S) r<S* r=S+ r>S, r?S- r@S. rAS/ rBS0 rCS1 rDS2 rES3 rFS4 rGS5\
R                  R                   4S6 jrI\ " S7 S85      5       rJS9\S\4S: jrKg!   \ RJ                  r$ GN= f);    N)	dataclass)partial)AnyCallableListOptional)	out_dtype)quantized_decomposed_lib)GraphModule)InternalMatch)ReplacedPatternsreplace_pattern_with_filters)WrapperModule)"_get_aten_graph_module_for_pattern,_replace_literals_with_existing_placeholders'_replace_literals_with_new_placeholders"remove_tensor_overload_for_qdq_ops)MappingType)_get_per_token_block_size)_register_custom_op)$_disable_aten_to_metadata_assertionstorchaoFRAGMENT reference_representation_rewritec                    [         R                  R                  R                  XX#U[         R                  5      n[         R                  R                  R                  UUUUU	[         R                  5      n[         R                  R
                  R                  R                  UUU
5      n[         R                  R                  R                  UXX[         R                  5      nU$ N)	torchopsquantized_decomposeddequantize_per_tensorint8atenlineardefaultquantize_per_tensor)x_i8x_scalex_zero_pointx_quant_minx_quant_max	weight_i8weight_scaleweight_zero_pointweight_quant_minweight_quant_max	bias_fp32	out_scaleout_zero_pointout_quant_minout_quant_maxx_fp32weight_fp32out_fp32out_i8s                      t/home/james-whalen/.local/lib/python3.13/site-packages/torchao/quantization/pt2e/reference_representation_rewrite.py_qdq_quantized_linearr:   ,   s    " YY++AA|+uzzF ))00FF

K yy~~$$,,V[)LHYY++??)]5::F M    c                    [         R                  R                  R                  XU5      n [         R                  R                  R                  XXU	5      nU R	                  [         R
                  5      nUR	                  [         R
                  5      n[        [         R                  R                  R                  R                  [         R                  X-
  UU-
  S 5      nX-  n[        [         R                  R                  R                  R                  [         R                  U
U5      nUU-   n[        [         R                  R                  R                  R                  [         R                  UX-  U-  5      U-   n[         R                  R                  R                  UX5      R	                  [         R                  5      nU$ r   )r   r   r"   clamptoint16r	   r#   r$   int32divTensormulr!   )r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   x_i16
weight_i16acc_i32
bias_scalebias_i32r8   s                        r9   _reference_quantized_linearrI   O   sJ   ( 99>>;?D		$$YBRSIGGEKK Eekk*J 		%%&&G 'J++22EKKJWH G 	IINN%%KK"Y.		
 	  YY^^!!'=HKKEJJWFMr;   c
                 D   [         R                  R                  R                  XX#[         R                  5      u  p[         R                  R                  R                  X
XU[         R                  5      n[         R                  R                  R                  XXU[         R                  5      n [         R                  R                  R                  UUUUU[         R                  5      n[         R                  R                  R                  R                  XU	5      nU$ r   )
r   r   r   choose_qparamsr!   r%   r    r"   r#   r$   )r5   r)   r*   x_epsr+   r,   r-   r.   r/   r0   r'   r(   r&   r6   r7   s                  r9   _qdq_dynamic_quantized_linearrM      s     "II::II[G 99))==KD YY++AA|+uzzF ))00FF

K yy~~$$,,V)LHOr;   c
                 t   [         R                  R                  R                  XX#[         R                  5      u  pX
-  n [         R
                  " U 5      n U R                  [         R                  S9nX-   n[         R                  " XU5      nUR                  [         R                  S9n[         R                  R                  R                  XGU5      nUR                  [         R                  5      nUR                  [         R                  5      n[        [         R                  R                  R                  R                  [         R                  X-
  X-
  S 5      nX-  n[        [         R                  R                  R                  R                  [         R                  U	U5      nUU-   nUX-  -  nU$ Ndtype)r   r   r   rK   r!   roundr>   r@   r=   r"   r?   r	   r#   r$   rA   rB   )r5   r)   r*   rL   r+   r,   r-   r.   r/   r0   r'   r(   x_i32r&   rD   rE   rF   rG   rH   r7   s                       r9   #_reference_dynamic_quantized_linearrT      sL    "II::II[G
 F [[ FIIEKKI(E EKKK8E88%**8%D		$$YBRSIGGEKK Eekk*J 		%%&G 'J++22EKKJWH G'01HOr;   c                    [         R                  n[        U 5      nSn	Sn
[        R                  R
                  R                  U UR                  U[        R                  U	U
U[        R                  [        R                  5	      u  p[        R                  R
                  R                  U UUU[        R                  U	U
5      n[        R                  R
                  R                  UUUU[        R                  U	U
[        R                  5      n US:  d   S5       eUR                  S   U-  S:X  d   S5       eUR                  5       S:X  d   S5       eSU4n[        R                  R
                  R                  UUUU[        R                  S	S
5      n[        R                  R                  R                   R#                  XU5      nU$ )N   r   zGroup size must be positive   z&Weight must be divisible by group_size   zWeight must be 2D tensor   )r   
ASYMMETRICr   r   r   r   choose_qparams_affinenamer!   float32r@   quantize_affinedequantize_affineshapedimr"   r#   r$   )r5   rL   	weight_i4r,   r-   r0   
group_sizex_mapping_typeper_token_block_sizer)   r*   r'   r(   r&   
block_sizer6   r7   s                    r9   ,_qdq_dynamic_quantized_linear_4bit_groupwiseri      s    !++N4V<KK!II--CC


G 99,,

D YY00

	F >888>??1
*a/ 0/ ==?a;!;;ZJ))##55


	K yy~~$$,,V)LHOr;   r5   rL   rd   r,   r-   r0   re   returnc                    US   n[         R                  n[        U 5      nSn	Sn
[        R                  R
                  R                  U UR                  U[        R                  U	U
U[        R                  [        R                  5	      u  p[        R                  R
                  R                  U UUU[        R                  U	U
5      nUR                  u  pX-  nUR                  [        R                  5      R                  [        R                  5      nUR                  nUR                  S   nUR                  SU5      nUR                  S   nUR                  UUU5      nUR                  UUU5      nUR                  [        R                  5      nUR                  [        R                  5      n[        R                   " UU[        R                  U R"                  S9n[%        U5      nUUS'   UR&                  S:X  a  UR)                  S5      n[+        U5       GH  nUSS2USS24   nUSS2USS24   nUR-                  SS9nUSS2U4   n[/        [        R                  R0                  R2                  R4                  [        R                  UUS5      nUUR                  [        R                  5      UR                  SS5      -  -   nUR                  [        R                  5      R                  SS5      UR                  SS5      -  UR                  SS5      -  n UU -
  nGM     UR                  SS5      n!UU!-  n"Ub  U"U-   n"U"R                  U5      $ )	av  
Reference implementation for dynamically quantized linear 4-bit groupwise operation.
This implementation emulates actual numerics of on-device integer compute.

Args:
    x_fp32: Input activation tensor in fp32
    x_eps: Epsilon for quantization parameter computation
    weight_i4: 4-bit quantized weight (stored as int8 with values in [-8, 7])
    weight_scale: Groupwise scales for weight dequantization
    weight_zero_point: Groupwise zero points for weight (unused for symmetric)
    bias_fp32: Optional bias tensor in fp32
    group_size: Size of each group for groupwise quantization

Returns:
    Output tensor in fp32
rX   rV   rW   r   )rQ   deviceN)rc   )r   r\   r   r   r   r   r]   r^   r!   r_   r@   r`   rb   r>   bfloat16viewzerosrm   listndim	unsqueezerangesumr	   r"   r#   r$   )#r5   rL   rd   r,   r-   r0   re   rf   rg   r)   r*   r'   r(   r&   out_featuresin_features
num_groupsx_orig_shapek_dim
batch_sizex_i8_groupedweight_i4_groupedx_i32_groupedweight_i32_groupedacc_fp32	out_shape	group_idxx_groupweight_groupweight_group_col_sumweight_scale_group	group_accweights_col_sum_adjustedx_scale_multiplierr7   s#                                      r9   _reference_dqlinear_int4r     s   6 AJ ++N4V<KK!II--CC


G 99,,

D !*L*J  ??5>>255emmDL ::LJJrNE99RDAJ99ZZ@L "|ZL !OOEKK0M*--ekk: {{LfmmH \"I IbMA#--a0:&	9a0)!Y/:+//B/7 *!Y,7 IINN!!))KK
	 ill5==9<N<S<Sr=
 
 
 !##EMM2772>A&' %%a,- 	!
 66C 'D !b!,,,Hi'==##r;   c           
      d    [         R                  R                  R                  U UUUUUSU45      $ )z
Reference implementation for dynamically quantized linear 4-bit groupwise operation.
This function now delegates to the custom op implementation.
rX   )r   r   r   reference_dqlinear_int4)r5   rL   rd   r,   r-   r0   re   s          r9   2_reference_dynamic_quantized_linear_4bit_groupwiser     s:     9944	
J r;   c                    SnSnU R                   R                  5        GH[  n[        U[        R                  R
                  5      (       a~  UR                  S:X  an  UR                  [        R                  R                  R                  R                  :X  a2  UR                  n[        U5      S:  a  US   S:H  =(       a    US   S:H  n[        U[        R                  R
                  5      (       d  M  UR                  S:X  d  M  UR                  [        R                  R                  R                  R                  :X  d  GM'  UR                  n[        U5      S:  d  GME  US   [        R                  :H  nGM^     U=(       a    U$ )NFcall_functionr[      rZ         )	nodes_mapvalues
isinstancer   fxNodeoptargetr   r   ra   r$   argslenr`   r!   )matchoriginal_graphpattern_graphweight_is_int4act_quant_is_int8noder   s          r9   6_filter_fn_for_dynamic_quantized_linear_4bit_groupwiser     s   
 N&&(tUXX]]++?*uyy00BBJJJ99D4yA~!%aB!?47a<tUXX]]++?*uyy00@@HHH99D4yA~$(Guzz$9!! )" ///r;   replacement_patternc                    SSK JnJn  SnSnU R                  R	                  5        HE  u  pVUR
                  [        R                  R                  R                  R                  :X  d  MC  Un  O   [        U R                  5      S:  a  U R                  S   nUbF  UbB  UR                  R                  5       Ul        U" USUR                  5      /UR                  S'   ggg)z
Port metadata for dynamically quantized linear 4-bit groupwise operation.
It custom_op node's metadata with corresponding linear node's metadata.
r   )
NodeSourceNodeSourceActionNrl   #ReplaceInt4DynamicQuantWithCustomOp	from_node)torch.fx.tracebackr   r   r   itemsr   r   r   r"   r#   r$   r   replacementsmetacopyREPLACE)r   r   r   linear_nodeint4_custom_op_node_g_ns          r9   :_port_metadata_for_dynamic_quantized_linear_4bit_groupwiser     s     @K%//557::..666K 8 ++,q01>>rB#6#B#.#3#3#8#8#: 5 ((1
  - $Cr;   c                    SS/nSS/nSS/nSnSS/nSn[         R                  R                  R                  XX#U[         R                  5      n[         R                  R                  R                  UUUUU	[         R                  5      n[         R                  R
                  R                  R                  UUU
UUUUUU5	      n[         R                  R                  R                  UXX[         R                  5      nU$ NrX   r   F)	r   r   r   r    r!   r"   convolutionr$   r%   )r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   stridepaddingdilation
transposedoutput_paddinggroupsr5   r6   r7   r8   s                            r9   _qdq_quantized_conv2dr     s    " VF!fG1vHJVNFYY++AA|+uzzF ))00FF

K yy~~))11
H YY++??)]5::F Mr;   c                    SS/nSS/nSS/nSnSS/nSn[         R                  R                  R                  XU5      n [         R                  R                  R                  XXU	5      nU R	                  [         R
                  5      nUR	                  [         R
                  5      n[        [         R                  R                  R                  R                  [         R                  UU-
  UU-
  S UUUUUU5      nX-  n[        [         R                  R                  R                  R                  [         R                  U
U5      nUR                  S5      nUR                  S5      nUU-   n[        [         R                  R                  R                  R                  [         R                  UX-  U-  5      U-   n[         R                  R                  R                  UX5      R	                  [         R                  5      nU$ )NrX   r   Frl   )r   r   r"   r=   r>   r?   r	   r   r$   r@   rA   rB   rs   rC   r!   )r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r   r   r   r   r   r   rD   rE   rF   rG   rH   r8   s                              r9   _reference_quantized_conv2dr     s   " VF!fG1vHJVNF 99>>;?D		$$YBRSIGGEKK Eekk*J 		""**&&G 'J ++22EKKJWH !!"%H!!"%H G 	IINN%%KK"Y.		
 	  YY^^!!'=HKKEJJWFMr;   c
                    [         R                  R                  R                  XX(U	[         R                  5      n
[         R                  R                  R                  X4XXU	[         R                  5      nX-   n[         R                  R
                  R                  U5      n[         R                  R                  R                  XXxU	[         R                  5      nU$ r   )r   r   r   r    r!   r"   relur%   r&   r'   r(   y_i8y_scaley_zero_pointr1   r2   	quant_min	quant_maxr5   y_fp32r7   r8   s                 r9   _qdq_quantized_add_relur   k  s     YY++AA|	5::F YY++AA|	5::F Hyy~~""8,HYY++??^	5::F Mr;   c
                 N   U R                  [        R                  5      n
UR                  [        R                  5      n[        [        R                  R
                  R                  R                  [        R                  X-
  X-  5      n
[        [        R                  R
                  R                  R                  [        R                  X-
  XF-  5      nX-   U-   n[        R                  R
                  R                  XU	5      R                  [        R                  5      nU$ )z
See comments for `_reference_quantized_add` for more information on
how to derive the formula for out_i8 based on x_i8 and y_i8
)
r>   r   r@   r	   r   r"   rC   rB   r=   r!   r&   r'   r(   r   r   r   r1   r2   r   r   rS   y_i32out_i32r8   s                 r9   _reference_quantized_add_relur     s      GGEKK EGGEKK E		!!					E 		!!					E mn,GYY^^!!'9EHHTFMr;   c
                 j   [         R                  R                  R                  XX(U	[         R                  5      n
[         R                  R                  R                  X4XXU	[         R                  5      nX-   n[         R                  R                  R                  XXxU	[         R                  5      nU$ r   )r   r   r   r    r!   r%   r   s                 r9   _qdq_quantized_addr     s     YY++AA|	5::F YY++AA|	5::F HYY++??^	5::F Mr;   c
                    U R                  [        R                  5      n
UR                  [        R                  5      n[        R                  " X-  X-
  -  5      R                  [        R                  5      n
[        R                  " XF-  X-
  -  5      R                  [        R                  5      nX-   U-   nSnSn	[        R                  R
                  R                  XU	5      R                  [        R                  5      nU$ )a  
    # How to Derive the formula for out_i8 based on x_i8 and y_i8
    # (since quantized add takes x_i8, y_i8 and their quantization parameters, and produce an out_i8)

    # out_i8 is quantized output, we can write down the formula for it first:
out_i8 = out_f32 / out_scale + out_zero_point           (1)

    # then out_fp32 is computed from x_f32 + y_f32, and the x_fp32 and y_fp32 are the dequantized x_i8 and y_i8
    out_f32 = x_f32 + y_f32           (2)
    x_fp32 = (x_i8 - x_zero_point) * x_scale         (3)
    y_fp32 = (y_i8 - y_zero_point) * y_scale         (4)

    # applying the above fomula to the out_i8 equation we can get the following:
    out_i8 = out_fp32 / out_scale + out_zero_point             # (1)
       = (x_f32 + y_f32) / out_scale + out_zero_point      # applying (2) to substitute out_fp32 with x_fp32 + y_fp32
       = ((x_i8 - x_zero_point) * x_scale + (y_i8 - y_zero_point) * y_scale) / out_scale + out_zero_point  # apply (3) and (4)
rV   rW   )r>   r   r@   rR   r   r"   r=   r!   r   s                 r9   _reference_quantized_addr     s    : GGEKK EGGEKK EKK,1EFGJJ5;;WEKK,1EFGJJ5;;WEmn,GIIYY^^!!'i@CCEJJOFMr;   c	                 r   Sn	Sn
SnSnSn[         R                  R                  R                  XX#U[         R                  5      n[         R                  R
                  R                  R                  XXX5      u  nn[         R                  R                  R                  XXgU[         R                  5      nU$ r   )	r   r   r   r    r!   r"   max_pool2d_with_indicesr$   r%   )r&   r'   r(   r)   r*   r1   r2   r3   r4   kernel_sizer   r   r   	ceil_moder5   r7   r   r8   s                     r9   _qdq_quantized_max_pool2dr     s     KFGHIYY++AA|+uzzF ))..88@@VhKHa YY++??^M5::F Mr;   c	                 |   Sn	Sn
SnSnSn[         R                  " XU5      n U R                  [         R                  5      n[         R                  R
                  R                  R                  X-
  XXU5      u  nnXU-  -  U-   n[         R                  " UXx5      nUR                  [         R                  5      nU$ r   )	r   r=   r>   r@   r   r"   r   r$   r!   )r&   r'   r(   r)   r*   r1   r2   r3   r4   r   r   r   r   r   rS   r   r   r7   r8   s                      r9   _reference_quantized_max_pool2dr     s     KFGHI;;t+6DGGEKK E77??k7iJGQ I-.?H{{8]BH[[$FMr;   c                 z    [         R                  R                  R                  XX#U[         R                  5      nU$ r   )r   r   r   r%   r!   r5   scale
zero_pointr   r   xs         r9   _quantize_per_tensor_int8r   $  s0    		&&::zi	A Hr;   c                     X-  n[         R                  " U5      nUR                  [         R                  S9nXR-   n[         R                  " XSU5      nUR                  [         R
                  S9nU$ rO   )r   rR   r>   r@   r=   r!   r   s         r9   #_reference_quantize_per_tensor_int8r   +  s^     	A 	AA	5;;A	AA),A	5::AHr;   c                 z    [         R                  R                  R                  XX#U[         R                  5      nU$ r   )r   r   r   r    r!   )r&   r   r   r   r   r5   s         r9   _dequantize_per_tensor_int8r   ;  s0    YY++AAZIuzzF Mr;   c                     [         R                  R                  R                  XU5      n U R	                  [         R
                  5      U-
  U-  R	                  [         R
                  S9$ rO   )r   r   r"   r=   r>   r_   )r&   r   r   r   r   s        r9   %_reference_dequantize_per_tensor_int8r   B  sO     99>>;D WWU]]#j0E9==EMM=RRr;   c           	      z    [         R                  R                  R                  XX#XE[         R                  5      nU$ r   )r   r   r   quantize_per_channelr!   )r5   scaleszero_pointsch_axisr   r   r8   s          r9   _quantize_per_channel_int8r   O  s2     YY++@@iEJJF Mr;   c                 \   [         R                  " XS5      n [         R                  R                  R	                  [         R
                  " X-  5      R                  [         R                  5      U-   XE5      n[         R                  " XcS5      nUR                  [         R                  5      $ Nrl   )	r   	transposer   r"   r=   rR   r>   r@   r!   )r5   r   r   r   r   r   r   s          r9   $_reference_quantize_per_channel_int8r   X  su     __Vb1Fiinn""FO$''4{BIG oog3G::ejj!!r;   c           	      z    [         R                  R                  R                  XX#XE[         R                  5      nU$ r   )r   r   r   dequantize_per_channelr!   )r&   r   r   r   r   r   r7   s          r9   _dequantize_per_channel_int8r   c  s2     yy--DDkI%**H Or;   c                 <   [         R                  R                  R                  XU5      n [         R                  " XS5      n U R                  [         R                  5      nXb-
  R                  [         R                  5      U-  n[         R                  " XsS5      nU$ r   )r   r   r"   r=   r   r>   r@   float)r&   r   r   r   r   r   rS   r7   s           r9   &_reference_dequantize_per_channel_int8r   m  sq     99>>;D??4"-DGGEKK E#''4v=Hx"5HOr;   gmc                 "    [        U S/SSSS.S9$ )Nrl      r   r   )rX   rV   rW   )exclude_literalsliteral_to_ph_idx)r   )r   s    r9   '_replace_ph_qdq_per_channel_replacementr   {  s    7
bT!!5L r;   c                   *   \ rS rSr% Sr\\S4   \S'   \\S'   \\S'   Sr	\
\\/\4      \S'   Sr\
\\/\4      \S	'   Sr\
\\S
\R                   R"                  \R                   R"                  /\4         \S'   Sr\\S'   Sr\
\S/S4      \S'   Srg)_RewriteInfoi  zData needed for rewrite, this includes example inputs, pattern and replacement functions
and post transformation functions for the exported pattern and replacement GraphModule
.example_inputspatternreplacementNpattern_post_transreplacement_post_transr   	filter_fnFignore_literalsr   port_metadata_fn )__name__
__module____qualname____firstlineno____doc__tupler   __annotations__r   r  r   r   r  r  rq   r   r   Graphboolr  r  __static_attributes__r  r;   r9   r   r     s    
 #s(O#IM;-*D!EFMMQHX{m[.H%IJQ 	 xXGMNO  "OT!GKhx);(<d(BCDKr;   r   modelc                 !   [         R                  " SSS[         R                  S9[         R                  " S[         R                  S9[         R
                  " S[         R                  S9[         R                  " S/[         R                  S9[         R                  " S/[         R                  S9[         R                  " SSS[         R                  S9[         R                  " S[         R                  S9[         R
                  " S[         R                  S9[         R                  " S/[         R                  S9[         R                  " S/[         R                  S9[         R                  " S[         R                  S9[         R                  " S[         R                  S9[         R
                  " S[         R                  S9[         R                  " S/[         R                  S9[         R                  " S/[         R                  S94n[         R                  " S[         R                  S9SS[         R                  " [         R                  5      R                  [         R                  " SSS[         R                  S9[         R                  " S[         R                  S9[         R
                  " S[         R                  S9[         R                  " S/[         R                  S9[         R                  " S/[         R                  S9[         R                  " S[         R                  S94
n[         R                  " SSS[         R                  S9[         R                  " S[         R                  S9[         R
                  " S[         R                  S9[         R                  " S/[         R                  S9[         R                  " S/[         R                  S9[         R                  " SSS[         R                  S9[         R                  " S[         R                  S9[         R
                  " S[         R                  S9[         R                  " S/[         R                  S9[         R                  " S/[         R                  S9[         R                  " S[         R                  S9[         R                  " S[         R                  S9[         R
                  " S[         R                  S9[         R                  " S/[         R                  S9[         R                  " S/[         R                  S94n[         R                  " SSS[         R                  S9[         R                  " S[         R                  S9[         R
                  " S[         R                  S9[         R                  " SSS[         R                  S9[         R                  " S[         R                  S9[         R
                  " S[         R                  S9[         R                  " S[         R                  S9[         R
                  " S[         R                  S9[         R                  " S/[         R                  S9[         R                  " S/[         R                  S94
n[         R                  " SSS[         R                  S9[         R                  " S[         R                  S9[         R
                  " S[         R                  S9[         R                  " S/[         R                  S9[         R                  " S/[         R                  S9[         R                  " S[         R                  S9[         R
                  " S[         R                  S9[         R                  " S/[         R                  S9[         R                  " S/[         R                  S94	n[         R                  " SS	S	S	[         R                  S9[         R                  " S[         R                  S9[         R
                  " S[         R                  S9[         R                  " S/[         R                  S9[         R                  " S/[         R                  S94n[         R                  " SSS[         R                  S9[         R                  " S[         R                  S9[         R
                  " S[         R                  S9[         R                  " S/[         R                  S9[         R                  " S/[         R                  S94n[         R                  " SS	S	S	[         R                  S9[         R                  " S	[         R                  S9[         R
                  " S	[         R                  S9SSS4n[         R                  " SSS[         R                  S9[         R                  " S	[         R                  S9[         R
                  " S	[         R                  S9SSS4n	[         R                  " S
[         R                  S9[         R                  " [         R                  5      R                  [         R                  " SSS[         R                  S9[         R                  " SS[         R                  S9[         R
                  " SS[         R                  S9[         R                  " S[         R                  S9S4n
[         R                  " S[         R                  S9[         R                  " [         R                  5      R                  [         R                  " SSS[         R                  S9[         R                  " SS[         R                  S9[         R
                  " SS[         R                  S9[         R                  " S[         R                  S9S4n[        U[        [        5      [        [        5      [        [         SSSS[         R                  " [         R                  5      R                  S	0S9[        [         SSSS[         R                  " [         R                  5      R                  S	0S95      [        U
[        ["        5      [        [$        5      [        [         [         R                  " [         R                  5      R                  SSS0S9[        [         [         R                  " [         R                  5      R                  SSS0S9[&        /S[(        S9[        U[        ["        5      [        [$        5      [        [         [         R                  " [         R                  5      R                  SSS0S9[        [         [         R                  " [         R                  5      R                  SSS0S9[&        /S[(        S9[        U[        [*        5      [        [,        5      [.        [.        5      [        U[        [0        5      [        [2        5      [        [.        S/S9[        [.        S/S95      [        U[        [4        5      [        [6        5      5      [        U[        [8        5      [        [:        5      5      [        U[        [<        5      [        [>        5      [.        [.        5      [        U[        [@        5      [        [B        5      5      [        U[        [D        5      [        [F        5      5      [        U[        [H        5      [        [J        5      [L        [L        5      [        U	[        [N        5      [        [P        5      [L        [L        5      /n[S        U 5        [U        5          U H  nURV                  nURX                  nURZ                  nUR\                  nUR^                  n[a        X5      n[S        U5        [a        UU5      n[S        U5        U(       a  U" U5      nU(       a  U" U5      nURc                  5         URc                  5         [e        U UUURf                  URh                  S9nURj                  (       d  M  U H  nURk                  U5        M     M     S S S 5        U $ ! , (       d  f       U $ = f)NrV   rW   )rY   r   rP   rX   )r   r   i)rX   r   r   r   r   )rX       rZ   r[   )   r  r  r   )rX   rX   r  rY   )r   )rX   r  r   T)r  r  r  rl   )r   )match_filtersr  )6r   randintr!   randnr   rp   inttensorfinfor_   epsr   r   rM   rT   r   r   ri   r   r   r   r:   rI   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r   	recompiler   r  r  r  )r   _QUANTIZED_LINEAR_EXAMPLE_INPUTS(_DYNAMIC_QUANTIZED_LINEAR_EXAMPLE_INPUTS _QUANTIZED_CONV2d_EXAMPLE_INPUTS)_QUANTIZED_ADD_OR_ADD_RELU_EXAMPLE_INPUTS$_QUANTIZED_MAX_POOL2D_EXAMPLE_INPUTS(_QUANTIZE_PER_TENSOR_INT8_EXAMPLE_INPUTS*_DEQUANTIZE_PER_TENSOR_INT8_EXAMPLE_INPUTS)_QUANTIZE_PER_CHANNEL_INT8_EXAMPLE_INPUTS+_DEQUANTIZE_PER_CHANNEL_INT8_EXAMPLE_INPUTS9_DYNAMIC_QUANTIZED_LINEAR_4BIT_GROUPWISE_EXAMPLE_INPUTS_19_DYNAMIC_QUANTIZED_LINEAR_4BIT_GROUPWISE_EXAMPLE_INPUTS_2_REWRITE_INFO_LISTrewrite_infor   r   r   r  r  matchesms                        r9   r   r     s   dCuzz:AU[[)AUYY'dV599-cU%)),dCuzz:AU[[)AUYY'dV599-cU%)),AU[[)AU[[)AUYY'dV599-cU%)),($& 	F%++.EMM"&&dCuzz:AU[[)AUYY'dV599-cU%)),AU[[)0, 	dCUZZ@AU[[)AUYY'dV599-cU%)),dCUZZ@AU[[)AUYY'dV599-cU%)),AU[[)AU[[)AUYY'dV599-cU%)),($& 	dCUZZ@AU[[)AUYY'dCUZZ@AU[[)AUYY'AU[[)AUYY'dV599-cU%)),1- 	dCUZZ@AU[[)AUYY'dV599-cU%)),AU[[)AUYY'dV599-cU%)),
,( 	Aq!Qekk2AU[[)AUYY'dV599-cU%)),0, 	dCUZZ@AU[[)AUYY'dV599-cU%)),2. 	Aq!Qekk2AU[[)AUYY'	1- 	dCUZZ@AU[[)AUYY'	3/ 	G5;;/EMM"&&b!WEJJ7Aq,q			
 	AU[[)	
A= 	Jekk2EMM"&&b!WEJJ7Aq,q			
 	AU[[)	
A= 	478=><#'CEKK4N4R4RTU"V <#'CEKK4N4R4RTU"V	
 	EFGLM<KK.22AA# <KK.22AA# NN W)	
, 	EFGLM<KK.22AA# <KK.22AA# NN W)	
, 	,/05633	
 	,/056;rdS;rdS	
 	51278	

 	5,-23	

 	0349:33	
 	434=>	

 	656?@	

 	545>?33	
 	767@A33	
Uqf 'u-	-	/.L)88N"**G&22K!-!@!@%1%H%H"8QG.w7<^K /{;!,W5%4[A!!#2*44 , < <G ,,, A 11!4 !5 / 
0< L= 
0	/< Ls   /CAA8AAA8A8
AB)L
contextlibdataclassesr   	functoolsr   typingr   r   r   r   r   !torch._higher_order_ops.out_dtyper	   $torch.ao.quantization.fx._decomposedr
   torch.fxr   6torch.fx.passes.utils.matcher_with_name_node_map_utilsr   torch.fx.subgraph_rewriterr   r   &torchao.quantization.pt2e.export_utilsr   torchao.quantization.pt2e.utilsr   r   r   r   %torchao.quantization.quant_primitivesr   torchao.quantization.utilsr   torchao.utilsr   torch._export.utilsr   nullcontextlibraryLibrary	quant_libregister_custom_op__all__r:   rI   rM   rT   ri   rB   r   r  r   r   r  r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r;   r9   <module>rA     s    !  0 0  7 I   P U @  > @ -BH MM!!)Z8	(3  '
 F2jB,^>B ~$LL~$~$ ||~$ ,,	~$
 ||~$ %~$ S	~$ \\~$ ~$B00 
	06
)
80fOd4"J2&R88 
S"0D0D  L L L&YK YK YiB+5+A+A(s   &E3 3F