
    h                     `   S SK r S SK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  \" SSS	9 " S
 S5      5       r\ R                  \\   S4   rS\l         " S S\5      rS\\   4S jrS\\   4S jrS\\   4S jrS\\   4S jrS\S\4S jrS\4S jrS\4S jrS\S\4S jrg)    N)	dataclass)Callable
NamedTupleOptional)Node)Q_ANNOTATION_KEY   )QuantizationAnnotationQuantizationSpecT)eqfrozenc                   d    \ rS rSr% \\   \S'   \\   \S'   \\   \S'   \\   \S'   Sr\\S'   Sr	g	)
QuantizationConfig   input_activationoutput_activationweightbiasFis_qat N)
__name__
__module____qualname____firstlineno__r   r   __annotations__r   bool__static_attributes__r       c/home/james-whalen/.local/lib/python3.13/site-packages/torchao/quantization/pt2e/quantizer/utils.pyr   r      s<    /00 011%&&
#
$$FDr   r   z)torchao.quantization.pt2e.quantizer.utilsc                   0    \ rS rSr% \\S'   \\   \S'   Srg)OperatorConfig%   config	operatorsr   N)	r   r   r   r   r   r   listOperatorPatternTyper   r   r   r   r!   r!   %   s     '((r   r!   quantization_configc                     U c  g U R                   c  g U R                   nUR                  [        R                  [        R                  4;   d   eU$ N)r   qschemetorchper_tensor_affineper_tensor_symmetricr'   quantization_specs     r   get_input_act_qspecr0   2   s]    "++3*=*N*N$$"")    r   c                     U c  g U R                   c  g U R                   nUR                  [        R                  [        R                  4;   d   eU$ r)   )r   r*   r+   r,   r-   r.   s     r   get_output_act_qspecr2   ?   s]    ",,4*=*O*O$$"")    r   c                     U c  g U c   eU R                   c  g U R                   nUR                  [        R                  [        R                  S 4;  a  [        SU S35      eU$ )NzUnsupported quantization_spec z for weight)r   r*   r+   r-   per_channel_symmetric
ValueErrorr.   s     r   get_weight_qspecr6   L   s    "***!!)*=*D*D  ""##) 
 ,->,?{K
 	
 r   c                     U c  g U c   eU R                   c  g U R                   nUR                  [        R                  :X  d   S5       eU$ )Nz9Only float dtype for bias is supported for bias right now)r   dtyper+   floatr.   s     r   get_bias_qspecr:   ^   s\    "***'*=*B*B""ekk1 C1 r   node
input_nodec                     U R                   R                  [        [        5       5      nUR                  c  0 Ul        X#R                  U'   X0R                   [        '   g r)   )metagetr   r
   input_qspec_map)r;   r<   qspecquantization_annotations       r   annotate_input_qspec_maprC   k   sL    "iimm,<>T>VW..624/:?++J7"9IIr   c                     U R                   R                  [        [        5       5      nXl        X R                   [        '   g r)   )r>   r?   r   r
   output_qspec)r;   rA   rB   s      r   annotate_output_qspecrF   s   s/    "iimm,<>T>VW+0("9IIr   module_namec                 0   ^  S[         S[        4U 4S jjnU$ )a  Get the module_name_filter function for a given module name, the filter accepts
a node and checks if the node comes from a module that has certain module name

For example:
    node: linear_op = call_function[...](...)  # comes from a module with name blocks.sub.linear1


>> module_name_filter = _get_module_name_filter("blocks.sub")
>> print(module_name_filter(node))
True  # the node is from "blocks.sub" based on the fully qualified name "blocks.sub.linear1"
nreturnc                    > U R                   R                  S0 5      nS nUR                  5        V Vs/ s H  u  pU" U 5      PM     nn nTU;   $ s  snn f )Nnn_module_stackc                 P    SnU R                  S5      (       a  [        S5      nXS  $ )Nr   z
L['self'].)
startswithlen)rI   prefixs     r   _normalize_pathKget_module_name_filter.<locals>.module_name_filter.<locals>._normalize_path   s*    F||L))\*W:r   )r>   r?   values)rI   rL   rQ   _namesrG   s        r   module_name_filter2get_module_name_filter.<locals>.module_name_filter   sY     &&**%6;	 1@0F0F0HI0H#0HIe## Js   A)r   r   )rG   rV   s   ` r   get_module_name_filterrX   y   s    $d $t $$ r   
annotationrJ   c                 b    U c  gU R                   nU R                  n[        U5      S:X  a  Uc  gg)NFr   T)r@   rE   rO   )rY   r@   rE   s      r   is_valid_annotationr[      s9     00O**L
?q \%9r   )typingdataclassesr   r   r   r   r+   torch.fxr   -torchao.quantization.pt2e.quantizer.quantizerr   	quantizerr
   r   r   	Annotatedr%   r&   r   r!   r0   r2   r6   r:   rC   rF   strrX   r   r[   r   r   r   <module>rc      s     ! 1 1   J ? d4   ! &&tH~t';< !L  
)Z 
)
X6H-I 

h7I.J 
(3E*F $
1C(D 
:4 :T :: : D$: t r   