a
    h?	                     @   s   d dl mZ d dlmZ d dlmZmZmZ d dlm	Z	 ee
ee	e f ee dddZee
ee	e f e	e ddd	Zee
ee	e f ed
ddZdS )    )deque)Any)Graphmap_argNode)
OrderedSet)nodenode_to_additional_depsreturnc                 C   s8   t t  }t| j| jf|j | |v r4|||   |S N)listr   r   argskwargsappendextendr   r	   r    r   G/var/www/auris/lib/python3.9/site-packages/torch/_dynamo/graph_utils.py_get_flat_args   s
    
r   c                 C   s8   t t  }t| j| jf|j | |v r4|||   |S r   )r   r   r   r   r   addupdater   r   r   r   _get_flat_args_unique   s
    
r   )graphr	   r
   c           
         s  t   t t  }td d fdd}d d fdd}td fdd}| jd	d
D ]}     || t||D ]}|||f q|rZ| \}}	 r| |	kr|  qt|tsq|v r | d    S || t||D ]}|||f qqqZdS )N)r   r
   c                    s     |  |  d S r   )r   r   r   current_pathZcurrent_path_setr   r   add_to_current_path(   s    
z+_detect_cycles.<locals>.add_to_current_path)r
   c                     s      } |  d S r   )popremover   r   r   r   pop_current_path,   s    z(_detect_cycles.<locals>.pop_current_pathc                      s    d S )Nr   r   )r   r   r   current_path_head0   s    z)_detect_cycles.<locals>.current_path_headoutput)opzcycle detected in path: zno cycle detected)	r   setr   Z
find_nodesclearr   r   r   
isinstance)
r   r	   pendingr   r   r!   originchildZcur_nodeparentr   r   r   _detect_cycles!   s2    

r+   N)collectionsr   typingr   Ztorch.fxr   r   r   Ztorch.utils._ordered_setr   dictr   r   r   strr+   r   r   r   r   <module>   s   	