U
    Ç9%eT  ã                   @   sp   d dl mZ d dlZd dlmZ d dlmZ eedœdd„Zedœd	d
„Zedœdd„Z	eee dœdd„Z
dS )é    )ÚListN)ÚQuantizationAnnotation)ÚNode)ÚnodeÚ
input_nodec                 C   s8   | j  dtƒ ¡}|jd kr i |_||j|< || j d< d S ©NÚquantization_annotation)ÚmetaÚgetr   Zinput_qspec_map)r   r   Úqspecr   © r   úd/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/torch/ao/quantization/quantizer/utils.pyÚ_annotate_input_qspec_map   s     ÿ

r   ©r   c                 C   s$   | j  dtƒ ¡}||_|| j d< d S r   )r	   r
   r   Zoutput_qspec)r   r   r   r   r   r   Ú_annotate_output_qspec   s     ÿr   c                 C   sN   | j dkr| jtjjjjkpL| jtjjjjkpL| jtjjjkpL| jtjjjkS )NZcall_function)ÚopÚtargetÚtorchZopsZatenZsym_sizeÚdefaultZ	sym_numelr   r   r   r   Ú_is_sym_size_node   s    
ÿþýûr   ©r   Úpartition_nodesc                    s$   t | ƒrdS t‡ fdd„| jD ƒƒS )aÓ  
    This utility is used to handle cases when dynami_shape=True tracing leads
    to symint nodes in the pattern of linear module. In those cases, we need to
    distinguish between the nodes that are in input for just extracting value of
    some dimentions (and symint nodes) vs. the one that is activation.
    For example:
    graph(x, y, weight):
       size_0 = torch.ops.aten.sym_size([x], [0])
       size_1 = torch.ops.aten.sym_size([y], [1])
       view_size = size_0 * size_1
       size_3 = torch.ops.aten.sym_size([x], [2])
       vie_out = torch.ops.aten.view(x, [view_size, size_3])
       return mm(view_out, weight)
    In the example above y node is not actual input. It exist only to extract size_1
    Tc                 3   s   | ]}|ˆ kpt |ƒV  qd S )N)r   )Ú.0Úuser©r   r   r   Ú	<genexpr>7   s   ÿz/_node_only_used_for_sym_size.<locals>.<genexpr>)r   ÚallZusersr   r   r   r   Ú_node_only_used_for_sym_size$   s
    þr   )Útypingr   r   Z)torch.ao.quantization.quantizer.quantizerr   Ztorch.fxr   r   r   r   r   r   r   r   r   Ú<module>   s   

