o
    i                  	   @   s  d dl Z d dlZd dlZd dlmZ d dlmZmZmZm	Z	m
Z
mZmZ d dlmZmZ d dlmZ ddgZeeef Zeee
edf f Zd	d
 Zdedede	e dee fddZdedefddZddedee defddZdedede	e defddZdS )    N)
Collection)DictListOptionalSetTupleTypeUnion)IterDataPipeMapDataPipe)DILL_AVAILABLEtraversetraverse_dpsDataPipeGraphc                   C   s   dS )NZSTUB r   r   r   e/var/www/html/eduruby.in/lip-sync/lip-sync-env/lib/python3.10/site-packages/torch/utils/data/graph.py_stub_unpickler   s   r   scan_objonly_datapipecachereturnc              
      s2  t  }t|}trddlm} ||}nd }g dd } fdd}ttf}	zO|	D ]}
|
| |r;|
	| q-z|
 W n tjttfyY   trV|
 n Y nw W |	D ]}
|
d  |rk|
	d  q]trxddlm} |d S |	D ]}
|
d  |r|
	d  q|trddlm} |d w w )	Nr   )Picklerc                 S   s   d }t | tr i }|  D ]\}}t |tttfr|||< q|S t | ttfr=g }| D ]}t |tttfr:|| q+|S t | tttfrG| }|S N)	
isinstancedictitemsr
   r   r   tuplelistappend)Z	ori_statestatekvr   r   r   getstate_hook"   s$   

z0_list_connected_datapipes.<locals>.getstate_hookc                    s8   | ks
t |  v rt|   t |  tdfS )Nr   )idNotImplementedErrorr   addr   )objr   Zcaptured_connectionsr   r   r   reduce_hook2   s
   
z._list_connected_datapipes.<locals>.reduce_hook)extendF)ioBytesIOpickler   r   Zdillr
   r   Zset_reduce_ex_hookZset_getstate_hookdumpPickleErrorAttributeError	TypeErrorr)   )r   r   r   fpZdill_Picklerdr"   r(   Zdatapipe_classesclsZdill_extendr   r'   r   _list_connected_datapipes   sV   

	






r5   datapipec                 C   s   t  }t| d|dS )a  
    Traverse the DataPipes and their attributes to extract the DataPipe graph.
    This only looks into the attribute from each DataPipe that is either a
    DataPipe and a Python collection object such as ``list``, ``tuple``,
    ``set`` and ``dict``.

    Args:
        datapipe: the end DataPipe of the graph
    Returns:
        A graph represented as a nested dictionary, where keys are ids of DataPipe instances
        and values are tuples of DataPipe instance and the sub-graph
    T)r   r   )set_traverse_helper)r6   r   r   r   r   r   T   s   c                 C   s:   d}|s|d7 }t |t |du rd}t }t| ||S )a1  
    [Deprecated] Traverse the DataPipes and their attributes to extract the DataPipe graph. When
    ``only_dataPipe`` is specified as ``True``, it would only look into the attribute
    from each DataPipe that is either a DataPipe and a Python collection object such as
    ``list``, ``tuple``, ``set`` and ``dict``.

    Note:
        This function is deprecated. Please use `traverse_dps` instead.

    Args:
        datapipe: the end DataPipe of the graph
        only_datapipe: If ``False`` (default), all attributes of each DataPipe are traversed.
          This argument is deprecating and will be removed after the next release.
    Returns:
        A graph represented as a nested dictionary, where keys are ids of DataPipe instances
        and values are tuples of DataPipe instance and the sub-graph
    zV`traverse` function and will be removed after 1.13. Please use `traverse_dps` instead.zM And, the behavior will be changed to the equivalent of `only_datapipe=True`.NF)warningswarnFutureWarningr7   r8   )r6   r   msgr   r   r   r   r   e   s   c                 C   s   t | ttfstdt|  dt| }||v ri S || t| || }|| i fi}|D ]}|| d 	t
|||  q0|S )Nz.Expected `IterDataPipe` or `MapDataPipe`, but z	 is found   )r   r
   r   RuntimeErrortyper#   r%   r5   copyupdater8   )r6   r   r   Zdp_idr   r3   itemr   r   r   r8      s   
 r8   r   )r*   r,   r9   collections.abcr   typingr   r   r   r   r   r   r	   Ztorch.utils.datar
   r   Z%torch.utils.data._utils.serializationr   __all__ZDataPipeintr   r   boolr5   r   r   r8   r   r   r   r   <module>   s    $"="