
    Pi                        d dl Z d dlmZ d dlmZ d dlmZmZmZm	Z	 d dl
Z
d dlmZ d dlmZ d dlmZ d dlmZ d d	lmZmZ d d
lmZ d dlmZmZmZmZ d dlmZ d dlm Z  d dl!m"Z" 	 d dl#m$Z$ n#  e j%        Z$Y nxY we
j&        '                    dd          Z( e"e(          Z)dgZ*d Z+d Z,d Z-d Z.d Z/e)de
j0        de1de
j0        de
j0        de
j0        de	e
j0                 dee2         de
j0        fd             Z3d! Z4de5fd"Z6d#efd$Z7d% Z8d& Z9d' Z:d( Z;d) Z<d* Z=d+ Z>d, Z?d- Z@d. ZAd/ ZBd0 ZCd1 ZDd2 ZEd3 ZFd4 ZGd5e
jH        j        fd6ZIe G d7 d8                      ZJd9edefd:ZKdS );    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                    t           j        j                            | ||||t           j                  }t           j        j                            |||||	t           j                  }t           j        j        j                            |||
          }t           j        j                            |||||t           j                  }|S 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                      /home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/torchao/quantization/pt2e/reference_representation_rewrite.py_qdq_quantized_linearr:   ,   s    " Y+AAg|[+uz F )0FF
 K y~$,,V[)LLHY+??)^]M5: F M    c                    t           j        j                            | ||          } t           j        j                            |||	          }|                     t           j                  }|                    t           j                  }t          t           j        j        j        j        t           j	        ||z
  ||z
  d           }||z  }t          t           j        j        j
        j        t           j	        |
|          }||z   }t          t           j        j        j        j        t           j	        |||z  |z            |z   }t           j        j                            |||                              t           j                  }|S 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   s@   ( 9>k;??D	$$Y0@BRSSIGGEK  Eek**J 	%&& G <'J+2EKJWWH G 	IN%Kl"Y.		
 	
 	  Y^!!'=-HHKKEJWWFMr;   c
                    t           j        j                            | |||t           j                  \  }
}t           j        j                            | |
|||t           j                  }t           j        j                            ||
|||t           j                  } t           j        j                            |||||t           j                  }t           j        j        j        	                    | ||	          }|S 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     "I:II[% G\ 9)=={K D Y+AAg|[+uz F )0FF
 K y~$,,V[)LLHOr;   c
                 &   t           j        j                            | |||t           j                  \  }
}| |
z  } t          j        |           } |                     t           j                  }||z   }t          j        |||          }|                    t           j                  }t           j        j	                            |||          }|                    t           j
                  }|                    t           j
                  }t          t           j        j	        j        j        t           j        ||z
  ||z
  d           }|
|z  }t          t           j        j	        j        j        t           j        |	|          }||z   }||
|z  z  }|S 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      sW    "I:II[% G\
 gF [  FIIEKI((EL EK{K88E88%*8%%D	$$Y0@BRSSIGGEK  Eek**J 	%&& G <'J+2EKJWWH G'L01HOr;   c                 4   t           j        }t          |           }d}	d}
t          j        j                            | |j        |t          j        |	|
|t          j	        t          j
        	  	        \  }}t          j        j                            | |||t          j        |	|
          }t          j        j                            ||||t          j        |	|
t          j	                  } |dk    s
J d            |j        d         |z  dk    s
J d            |                                dk    s
J d            d|f}t          j        j                            ||||t          j        d	d
          }t          j        j        j                            | ||          }|S )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!I-CC

 
G\ 9,,
 D Y00
	 	F >>>8>>>?1
*a///0 0// ==??a!;ZJ)#55

	 K y~$,,V[)LLHOr;   r5   rL   rd   r,   r-   r0   re   returnc                    |d         }t           j        }t          |           }d}	d}
t          j        j                            | |j        |t          j        |	|
|t          j	        t          j
        	  	        \  }}t          j        j                            | |||t          j        |	|
          }|j        \  }}||z  }|                    t          j                                      t          j	                  }|j        }|j        d         }|                    d|          }|j        d         }|                    |||          }|                    |||          }|                    t          j
                  }|                    t          j
                  }t          j        ||t          j	        | j                  }t%          |          }||d<   |j        dk    r|                    d          }t+          |          D ]}|dd|ddf         }|dd|ddf         }|                    d          }|dd|f         }t/          t          j        j        j        j        t          j
        ||d          }||                    t          j	                  |                    dd          z  z   }|                    t          j	                                      dd          |                    dd          z  |                    dd          z  } || z
  }|                    dd          }!||!z  }"||"|z   }"|"                    |          S )	a  
    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     sJ   6 AJ +N4V<<KK!I-CC

 
G\ 9,,
 D !*L+
*J  ??5>2255emDDL :LJrNE99RDAJ99ZZ@@L "|ZLL !OOEK00M*--ek:: {Lfm  H \""I IbMA#--a00:&& !7 !7	9aaa0)!!!Y/:+//B/77 *!!!Y,7 IN!)K
 
	 ill5=99<N<S<Sr=
 =
 
 
 !##EM22772>>A&&' %%a,,- 	!
 66 b!,,,,Hi'==###r;   c           
      Z    t           j        j                            | |||||d|f          S )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:     944	
J  r;   c                 J   d}d}| j                                         D ]}t          |t          j        j                  ra|j        dk    rV|j        t          j        j	        j
        j        k    r2|j        }t          |          dk    r|d         dk    o|d         dk    }t          |t          j        j                  r_|j        dk    rT|j        t          j        j	        j        j        k    r0|j        }t          |          dk    r|d         t          j        k    }|o|S )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&&(( : :tUX]++	@?**uy0BJJJ9D4yyA~~!%aB!?47a<tUX]++	:?**uy0@HHH9D4yyA~~$(Guz$9!///r;   replacement_patternc                 x   ddl m}m} d}d}| j                                        D ]-\  }}|j        t          j        j        j	        j
        k    r|} n.t          | j                  dk    r| j        d         }|=|=|j                                        |_         ||d|j                  g|j        d<   dS dS dS )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7  3:.666KE 7 +,,q001>rB#6#B#.#3#8#8#:#: J5 ( 1
 --- #B#Br;   c                    ddg}ddg}ddg}d}ddg}d}t           j        j                            | ||||t           j                  }t           j        j                            |||||	t           j                  }t           j        j        j                            |||
||||||	  	        }t           j        j                            |||||t           j                  }|S 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Y+AAg|[+uz F )0FF
 K y~)11
 
H Y+??)^]M5: F Mr;   c                    ddg}ddg}ddg}d}ddg}d}t           j        j                            | ||          } t           j        j                            |||	          }|                     t           j                  }|                    t           j                  }t          t           j        j        j        j        t           j	        ||z
  ||z
  d ||||||          }||z  }t          t           j        j        j
        j        t           j	        |
|          }|                    d          }|                    d          }||z   }t          t           j        j        j        j        t           j	        |||z  |z            |z   }t           j        j                            |||                              t           j                  }|S )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 9>k;??D	$$Y0@BRSSIGGEK  Eek**J 	"*&& G <'J +2EKJWWH !!"%%H!!"%%H G 	IN%Kl"Y.		
 	
 	  Y^!!'=-HHKKEJWWFMr;   c
                    t           j        j                            | ||||	t           j                  }
t           j        j                            |||||	t           j                  }|
|z   }t           j        j                            |          }t           j        j                            |||||	t           j                  }|S 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     Y+AAg|Y	5: F Y+AAg|Y	5: F Hy~""8,,HY+??)^Y	5: F Mr;   c
                    |                      t          j                  }
|                     t          j                  }t          t          j        j        j        j        t          j        |
|z
  ||z            }
t          t          j        j        j        j        t          j        ||z
  ||z            }|
|z   |z   }t          j        j                            |||	                               t          j	                  }|S )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      GGEK  EGGEK  E	!			9		 E 	!			9		 E emn,GY^!!'>9EEHHTTFMr;   c
                 B   t           j        j                            | ||||	t           j                  }
t           j        j                            |||||	t           j                  }|
|z   }t           j        j                            |||||	t           j                  }|S r   )r   r   r   r    r!   r%   r   s                 r9   _qdq_quantized_addr     s     Y+AAg|Y	5: F Y+AAg|Y	5: F HY+??)^Y	5: F Mr;   c
                    |                      t          j                  }
|                     t          j                  }t          j        ||z  |
|z
  z                                 t          j                  }
t          j        ||z  ||z
  z                                 t          j                  }|
|z   |z   }d}d}	t          j        j                            |||	                               t          j                  }|S )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    : GGEK  EGGEK  EK9,1EFGGJJ5;WWEK9,1EFGGJJ5;WWEemn,GIIY^!!'9i@@CCEJOOFMr;   c	                 H   d}	d}
d}d}d}t           j        j                            | ||||t           j                  }t           j        j        j                            ||	|
|||          \  }}t           j        j                            |||||t           j                  }|S 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Y+AAg|[+uz F ).8@@VWh	 KHa Y+??)^]M5: F Mr;   c	                 l   d}	d}
d}d}d}t          j        | ||          } |                     t           j                  }t           j        j        j                            ||z
  |	|
|||          \  }}|||z  z  |z   }t          j        |||          }|                    t           j                  }|S 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[+66DGGEK  E7??k67Hi JGQ 'I-.?H{8]MBBH[[$$FMr;   c                 l    t           j        j                            | ||||t           j                  }|S r   )r   r   r   r%   r!   r5   scale
zero_pointr   r   xs         r9   _quantize_per_tensor_int8r   $  s2    	&::z9i	 	A Hr;   c                     | |z  }t          j        |          }|                    t           j                  }||z   }t          j        |||          }|                    t           j                  }|S rO   )r   rR   r>   r@   r=   r!   r   s         r9   #_reference_quantize_per_tensor_int8r   +  sg     	A 	AA	5;A	JAAy),,A	5:AHr;   c                 l    t           j        j                            | ||||t           j                  }|S r   )r   r   r   r    r!   )r&   r   r   r   r   r5   s         r9   _dequantize_per_tensor_int8r   ;  s2    Y+AAeZIuz F Mr;   c                     t           j        j                            | ||          } |                     t           j                  |z
  |z                      t           j                  S rO   )r   r   r"   r=   r>   r_   )r&   r   r   r   r   s        r9   %_reference_dequantize_per_tensor_int8r   B  sR     9>i;;D WWU]##j0E9==EM=RRRr;   c           	      n    t           j        j                            | |||||t           j                  }|S r   )r   r   r   quantize_per_channelr!   )r5   scaleszero_pointsch_axisr   r   r8   s          r9   _quantize_per_channel_int8r   O  s6     Y+@@WiEJ F Mr;   c                 N   t          j        | |d          } t           j        j                            t          j        | |z                                t           j                  |z   ||          }t          j        ||d          }|                    t           j                  S Nrl   )	r   	transposer   r"   r=   rR   r>   r@   r!   )r5   r   r   r   r   r   r   s          r9   $_reference_quantize_per_channel_int8r   X  s     _VWb11Fin""FVO$$''44{BIy G ogw33G::ej!!!r;   c           	      n    t           j        j                            | |||||t           j                  }|S r   )r   r   r   dequantize_per_channelr!   )r&   r   r   r   r   r   r7   s          r9   _dequantize_per_channel_int8r   c  s6     y-DDfk7Iy%* H Or;   c                 2   t           j        j                            | ||          } t          j        | |d          } |                     t           j                  }||z
                      t           j                  |z  }t          j        ||d          }|S 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  s|     9>i;;D?4"--DGGEK  E#''44v=Hx"55HOr;   gmc                 0    t          | dgdddd          S )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!!5L5L   r;   c                   8   e Zd ZU dZeedf         ed<   eed<   eed<   dZe	ee
ge
f                  ed<   dZe	ee
ge
f                  ed<   dZe	eed	ej        j        ej        j        gef                           ed
<   dZeed<   dZe	edgdf                  ed<   dS )_RewriteInfozData 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____doc__tupler   __annotations__r   r  r   r   r  r  rq   r   r   Graphboolr  r   r;   r9   r   r     s         
 #s(O###IM;-*D!EFMMMMQHX{m[.H%IJQQQ 	 xXGMNO    "OT!!!GKhx);(<d(BCDKKKKKr;   r   modelc                 4    t          j        dddt           j                  t          j        dt           j                  t          j        dt           j                  t          j        dgt           j                  t          j        dgt           j                  t          j        dddt           j                  t          j        dt           j                  t          j        dt           j                  t          j        dgt           j                  t          j        dgt           j                  t          j        dt           j                  t          j        dt           j                  t          j        dt           j                  t          j        dgt           j                  t          j        dgt           j                  f}t          j        dt           j                  ddt          j        t           j	                  j
        t          j        dddt           j                  t          j        dt           j                  t          j        dt           j                  t          j        dgt           j                  t          j        dgt           j                  t          j        dt           j                  f
}t          j        dddt           j                  t          j        dt           j                  t          j        dt           j                  t          j        dgt           j                  t          j        dgt           j                  t          j        dddt           j                  t          j        dt           j                  t          j        dt           j                  t          j        dgt           j                  t          j        dgt           j                  t          j        dt           j                  t          j        dt           j                  t          j        dt           j                  t          j        dgt           j                  t          j        dgt           j                  f}t          j        dddt           j                  t          j        dt           j                  t          j        dt           j                  t          j        dddt           j                  t          j        dt           j                  t          j        dt           j                  t          j        dt           j                  t          j        dt           j                  t          j        dgt           j                  t          j        dgt           j                  f
}t          j        dddt           j                  t          j        dt           j                  t          j        dt           j                  t          j        dgt           j                  t          j        dgt           j                  t          j        dt           j                  t          j        dt           j                  t          j        dgt           j                  t          j        dgt           j                  f	}t          j        dd	d	d	t           j                  t          j        dt           j                  t          j        dt           j                  t          j        dgt           j                  t          j        dgt           j                  f}t          j        dddt           j                  t          j        dt           j                  t          j        dt           j                  t          j        dgt           j                  t          j        dgt           j                  f}t          j        dd	d	d	t           j                  t          j        d	t           j                  t          j        d	t           j                  dddf}t          j        dddt           j                  t          j        d	t           j                  t          j        d	t           j                  dddf}	t          j        d
t           j                  t          j        t           j	                  j
        t          j        dddt           j                  t          j        ddt           j                  t          j        ddt           j                  t          j        dt           j                  df}
t          j        dt           j                  t          j        t           j	                  j
        t          j        dddt           j                  t          j        ddt           j                  t          j        ddt           j                  t          j        dt           j                  df}t          |t          t                    t          t                    t          t           ddddt          j        t           j	                  j
        d	i          t          t           ddddt          j        t           j	                  j
        d	i                    t          |
t          t"                    t          t$                    t          t           t          j        t           j	                  j
        dddi          t          t           t          j        t           j	                  j
        dddi          t&          gdt(                    t          |t          t"                    t          t$                    t          t           t          j        t           j	                  j
        dddi          t          t           t          j        t           j	                  j
        dddi          t&          gdt(                    t          |t          t*                    t          t,                    t.          t.                    t          |t          t0                    t          t2                    t          t.          dg          t          t.          dg                    t          |t          t4                    t          t6                              t          |t          t8                    t          t:                              t          |t          t<                    t          t>                    t.          t.                    t          |t          t@                    t          tB                              t          |t          tD                    t          tF                              t          |t          tH                    t          tJ                    tL          tL                    t          |	t          tN                    t          tP                    tL          tL                    g}tS          |            tU                      5  |D ]}|j+        }|j,        }|j-        }|j.        }|j/        }ta          ||          }tS          |           ta          ||          }tS          |           |r ||          }|r ||          }|1                                 |1                                 te          | |||j3        |j4                  }|j5        r|D ]}|5                    |           	 d d d            n# 1 swxY w Y   | S )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uz:::AU[)))AUY'''dV59---cU%),,,dCuz:::AU[)))AUY'''dV59---cU%),,,AU[)))AU[)))AUY'''dV59---cU%),,,($& 	F%+...EM""&dCuz:::AU[)))AUY'''dV59---cU%),,,AU[)))0, 	dCUZ@@@AU[)))AUY'''dV59---cU%),,,dCUZ@@@AU[)))AUY'''dV59---cU%),,,AU[)))AU[)))AUY'''dV59---cU%),,,($& 	dCUZ@@@AU[)))AUY'''dCUZ@@@AU[)))AUY'''AU[)))AUY'''dV59---cU%),,,1- 	dCUZ@@@AU[)))AUY'''dV59---cU%),,,AU[)))AUY'''dV59---cU%),,,
,( 	Aq!Qek222AU[)))AUY'''dV59---cU%),,,0, 	dCUZ@@@AU[)))AUY'''dV59---cU%),,,2. 	Aq!Qek222AU[)))AUY'''	1- 	dCUZ@@@AU[)))AUY'''	3/ 	G5;///EM""&b!WEJ777Aq,,,q		
 	
 	
 	AU[)))	
A= 	Jek222EM""&b!WEJ777Aq,,,q		
 	
 	
 	AU[)))	
A= 	4788=>><#'CEK4N4N4RTU"V   <#'CEK4N4N4RTU"V  	
 	
 	EFGGLMM<K..2AA#   <K..2AA#   NN W)	
 	
 	
, 	EFGGLMM<K..2AA#   <K..2AA#   NN W)	
 	
 	
, 	,/0056633	
 	
 	,/00566;rdSSS;rdSSS	
 	
 	5122788	
 	

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

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

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

 	5455>??33	
 	
 	7677@AA33	
 	
Uqf 'u---	-	/	/ 5 5. 	5 	5L)8N"*G&2K!-!@%1%H"8.QQG.w777<^ K /{;;;! 6,,W55% B44[AA!!###2*4 , <  G , 5  5 5A 11!44447	55 5 5 5 5 5 5 5 5 5 5 5 5 5 5< Ls   C(A@@A@@A@)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>r?     sd       ! ! ! ! ! !       0 0 0 0 0 0 0 0 0 0 0 0  7 7 7 7 7 7 I I I I I I             P P P P P P U U U U U U U U @ @ @ @ @ @            > = = = = = @ @ @ @ @ @ - - - - - -BHHHHHHHB+5+A(((M!!)Z88	((33  '
     F2 2 2j  B, , ,^> > >B ~$L~$~$ |~$ ,	~$
 |~$ %~$ S	~$ \~$ ~$ ~$ ~$B  00 
	0 0 0 06
)
 
 
 
80 0 0fO O Od  4" " "J  2& & &R  8  8       
S 
S 
S  " " "    0D     L L L L L L L L&YK YK Y Y Y Y Y Ys   &A- -	A8