o
    wZh"                     @  s  U d dl mZ d dlZd dlZd dlmZmZ d dlZd dlm	Z	 d dl
Z
d dlZ
d dlmZ d dlmZ d dlmZmZ d dlmZmZ erKd dlZd	Zd
ed< dZe
jdeZdZddZejd[ddZ d[ddZ!e j"d\ddZ#e j"d]ddZ$e j"d^d d!Z%e j"d_d#d$Z&e j"d`d&d'Z'e j"dad)d*Z(e j"dbd,d-Z)e j"dcd.d/Z*e j"ddd1d2Z+e j"ded3d4Z,e j"dfd5d6Z-e j"dgd8d9Z.e j"dhd;d<Z/e j"did>d?Z0e j"djdAdBZ1e j"dkdDdEZ2e j"dldGdHZ3e j"dmdJdKZ4e j"dndMdNZ5dodQdRZ6ej7Z7ej8Z8ej9Z9ej:Z:ej;Z;ej<G dSdT dTej=Z=ej<G dUdV dVej>e= Z>ej?ej@e=e!dWZ@ej<G dXdY dYe=ZAdS )p    )annotationsN)AnyTYPE_CHECKING)graph_building)diagnostics)infra)	decorator	formatter)registration
type_utils
   int_CONTAINER_ITEM_LIMITZonnx_diagnosticsz
torch.onnxreturnboolc                   C  s   t jjjtS N)torch_logging	_internalZ	log_stateZis_artifact_enabled&_ONNX_DIAGNOSTICS_ARTIFACT_LOGGER_NAME r   r   R/var/www/auris/lib/python3.10/site-packages/torch/onnx/_internal/fx/diagnostics.py(is_onnx_diagnostics_log_artifact_enabled.   s   
r   objr   strc                 C  s
   t | S r   )r	   format_argumentr   r   r   r   _format_argument4   s   
r   c                 C  s   t t| }|| S r   )r   dispatchtype)r   r	   r   r   r   r   9   s   r   torch.nn.Modulec                 C     d| j j dS )Nztorch.nn.Module()	__class____name__r   r   r   r   _torch_nn_moduleG      r&   torch.fx.GraphModulec                 C  r!   )Nztorch.fx.GraphModule(r"   r#   r   r   r   r   _torch_fx_graph_moduleL   r'   r)   torch.fx.Nodec                 C  s:   d| j  d| j d}d| jvr|d S |t| jd  S )Nzfx.Node(z)[z]:valNone)targetopmetar   )r   Znode_stringr   r   r   _torch_fx_nodeQ   s   
r0   torch.SymBoolc                 C     d|  dS )NzSymBool(r"   r   r   r   r   r   _torch_fx_symbolic_boolY      r3   torch.SymIntc                 C  r2   )NzSymInt(r"   r   r   r   r   r   _torch_fx_symbolic_int^   r4   r6   torch.SymFloatc                 C  r2   )Nz	SymFloat(r"   r   r   r   r   r   _torch_fx_symbolic_floatc   r4   r8   torch.Tensorc                 C     dt | j t| j dS )NzTensor(r"   fx_type_utilsZfrom_torch_dtype_to_abbrZdtype_stringify_shapeshaper   r   r   r   _torch_tensorh      r?   c                 C     t | S r   r   r   r   r   r   _intm      rC   floatc                 C  rA   r   rB   r   r   r   r   _floatr   rD   rF   c                 C  rA   r   rB   r   r   r   r   _boolw   rD   rG   c                 C  s   | S r   r   r   r   r   r   _str|   s   rH   registration.ONNXFunctionc                 C  s   d| j  d| j d| j dS )Nzregistration.ONNXFunction(z, is_custom=z, is_complex=r"   )Zop_full_nameZ	is_customZ
is_complexr   r   r   r   _registration_onnx_function   s   rJ   listc                 C  b   dt |  d}| s|d S t| D ]\}}|tkr#|d7 } |d S |t| d7 }q|d S )NzList[length=](
None)...,
,
r"   len	enumerater   r   )r   Zlist_stringiitemr   r   r   _list      rV   tuplec                 C  rL   )NzTuple[length=rM   rN   rO   rP   r"   rQ   )r   Ztuple_stringrT   rU   r   r   r   _tuple   rW   rY   dictc                 C  sp   dt |  d}| s|d S t|  D ]\}\}}|tkr'|d7 } |d S || dt| d7 }q|d S )NzDict[length=rM   rN   z...
z: rP   r"   )rR   rS   itemsr   r   )r   Zdict_stringrT   keyvaluer   r   r   _dict   s   r^   torch.nn.Parameterc                 C  s   dt | j dS )Nz
Parameter(r"   )r   datar   r   r   r   _torch_nn_parameter   s   ra    graph_building.TorchScriptTensorc                 C  r:   )Nz`TorchScriptTensor()`r;   r   r   r   r   _onnxscript_torch_script_tensor   r@   rd   onnxscript.OnnxFunctionc                 C     d| j  dS )Nz`OnnxFunction(rc   namer   r   r   r   _onnxscript_onnx_function      ri   onnxscript.TracedOnnxFunctionc                 C  rf   )Nz`TracedOnnxFunction(rc   rg   r   r   r   r    _onnxscript_traced_onnx_function   rj   rl   r>   torch.Size | Nonec                 C  s(   | d u rdS dd dd | D  dS )N [z, c                 s  s    | ]}t |V  qd S r   rB   ).0xr   r   r   	<genexpr>   s    z#_stringify_shape.<locals>.<genexpr>])join)r>   r   r   r   r=      s   r=   c                   @  s.   e Zd ZU ejdedZded< dddZdS )
DiagnosticFinitdefaultlogging.Loggerloggerlevelr   messager   r   r,   c                 O  sD   | j |r || }t r| j j||fi | | j| d S d S r   )rz   isEnabledForr   logZadditional_messagesappend)selfr{   r|   argskwargsZformatted_messager   r   r   r~      s   zDiagnostic.logN)r{   r   r|   r   r   r,   )	r%   
__module____qualname__dataclassesfielddiagnostic_loggerrz   __annotations__r~   r   r   r   r   ru      s   
 ru   c                      sJ   e Zd ZU ejdedZded< ejdedZ	ded<  fddZ
  ZS )	DiagnosticContextFrv   ry   rz   ztype[Diagnostic]_bound_diagnostic_typec                   s   | j j| _t st  S | S r   )rz   r{   Z_previous_log_levelr   super	__enter__r   r$   r   r   r      s   

zDiagnosticContext.__enter__)r%   r   r   r   r   r   rz   r   ru   r   r   __classcell__r   r   r   r   r      s   
 r   )Zdiagnostic_typer   c                      s,   e Zd ZU dZded< d fddZ  ZS )	UnsupportedFxNodeDiagnosticNztorch.fx.Node | Noneunsupported_fx_noder   r,   c                   s    t    | jd u rtdd S )Nz&unsupported_fx_node must be specified.)r   __post_init__r   
ValueErrorr   r   r   r   r      s   

z)UnsupportedFxNodeDiagnostic.__post_init__)r   r,   )r%   r   r   r   r   r   r   r   r   r   r   r      s   
 r   )r   r   )r   r   r   r   )r   r    r   r   )r   r(   r   r   )r   r*   r   r   )r   r1   r   r   )r   r5   r   r   )r   r7   r   r   )r   r9   r   r   )r   r   r   r   )r   rE   r   r   )r   r   r   r   )r   r   r   r   )r   rI   r   r   )r   rK   r   r   )r   rX   r   r   )r   rZ   r   r   )r   r_   r   r   )r   rb   r   r   )r   re   r   r   )r   rk   r   r   )r>   rm   r   r   )B
__future__r   r   	functoolstypingr   r   Z
onnxscriptZ"onnxscript.function_libs.torch_libr   r   Ztorch.fxZtorch.onnx._internalr   Z torch.onnx._internal.diagnosticsr   Z&torch.onnx._internal.diagnostics.infrar   r	   Ztorch.onnx._internal.fxr
   r   r<   loggingr   r   r   r   ZgetArtifactLoggerr   r   singledispatchr   r   registerr&   r)   r0   r3   r6   r8   r?   rC   rF   rG   rH   rJ   rV   rY   r^   ra   rd   ri   rl   r=   rulesZlevelsZRuntimeErrorWithDiagnosticZ
LazyStringZDiagnosticOptions	dataclassru   r   partialZdiagnose_callr   r   r   r   r   <module>   s   


