
    ia                     D   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  S SKJr   SS\\   S\S	\4S
 jjrS\S\R                   R"                  S	\4S jrS\R                   R"                  S	\4S jrS\R*                  S\\   S\\   S\R0                  S\\\\4      4
S jrS\R*                  S\\   S\\   S\R0                  S\\\\4      S\\   4S jr  SS\R*                  S\\   S\\   S\R0                  S\\\\4      S\\   S	\R*                  4S jjrg)    )ListOptionalTupleN)is_param_node)CompileSpec)ops)ExportedProgramcompile_specs	spec_namereturnc                 `    U  H  nXR                   :X  d  M  Us  $    U(       a   SU S35       eg )NzRequire z but it doesn't exist.)key)r
   r   requiredspecs       f/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/executorch/backends/samsung/utils/utils.pyget_compile_specr      s8      K  E8I;.DEE<x    exported_programnodec                 N    UR                   S:H  =(       a    [        X5      (       + $ )Nplaceholder)opr   )r   r   s     r   is_graph_inputr      s    77m#QM:J,Q(QQr   c                     U R                   R                  5        HA  nUR                  S:X  d.  UR                  R                  S:X  d  M/  [        U5      (       d  MA    g   g)NoutputgetitemTF)userskeysr   target__name__is_graph_output)r   users     r   r!   r!      sG    

!77hKK  I-/$2G2G	 "
 r   	in_tensorscales
zeropointsdtypeqrangec                     [        U5      S:X  d   S5       e[        R                  R                  R                  R                  U [        R                  " U5      [        R                  " U5      US   US   U5      $ )N   zEFor per-tensor quantization, there should be only one scale/zeropointr   )lenexir_opsedgequantized_decomposedquantize_per_tensordefaulttorchTensor)r#   r$   r%   r&   r'   s        r   _quantize_per_tensorr2   )   sq     	FqONO==--AAIIVZ q	q	 r   axisc           	         [        U5      U R                  U   :X  d   S5       e[        R                  R                  R
                  R                  U [        R                  " U5      [        R                  " U5      UUS   US   U5      $ )Nz1Shape not match for quant params and input tensorr   r)   )	r*   shaper+   r,   r-   quantize_per_channelr/   r0   r1   r#   r$   r%   r&   r'   r3   s         r   _quantize_per_channelr8   =   s{     	Fyt,,;:;,==--BBJJVZ q	q	 r   c                    [        U5      [        U5      :X  d   S5       eU(       d@  [        R                  " U5      R                  [        R                  " U5      R                  4nUb  [        XX#XE5      $ [        U UUUU5      $ )ao  
To quantize constant tensor by executorch OPs. If `axis` not set, we quantize the tensor by per tensor.
If `axis` was set, we do per-channel quantize.

:param in_tensor: The tensor to be quantized
:param scales: List of scales. For per-tensor quantization, it should contain only one element
:param zeropoints: List of zeropoints. For per-tensor quantization, it should contain only one element
:param dtype: The output dtype
:param qrange: The quantization range (qmin, qmax).
    If not set, we will get the maximum range of the dtype by `torch.iinfo`
:param axis: We do per-channel quantize by which axis.
    Only when this parameter set, we do per-channel quantization
:type in_tensor: torch.Tensor
:type scalse: List[float]
:type zeropoints: List[int]
:type dtype: torch.dtype
:type qrange: Optional[Tuple[int,int]]
:type axis: Optional[int]
:return: The quantized tensor
z-scales should have same shape with zeropoints)r*   r0   iinfominmaxr8   r2   r7   s         r   quantize_tensorr=   S   s    8 v;#  767  ++e$((%++e*<*@*@A$Y
6XX r   )F)NN)typingr   r   r   r0   $executorch.backends.transforms.utilsr   'executorch.exir.backend.backend_detailsr   executorch.exir.dialects._opsr   r+   torch.export.exported_programr	   strr   fxNodeboolr   r!   r1   floatintr&   r2   r8   r=    r   r   <module>rJ      s   ) (  > ? 9 9 @EF$F14FFR_ REHHMM Rd R%((-- D ||K S	 ;;	
 U38_%(||K S	 ;;	
 U38_% 3-6 )-*||*K* S	* ;;	*
 U38_%* 3-* \\*r   