
    i              	           d dl 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gZ
ee	z  Zeeeedf   f   Zdefd	Zd
ededee   dee   fdZdedefdZddededz  defdZdededee   defdZy)    N)
Collection)dill_available)IterDataPipeMapDataPipetraversetraverse_dpsDataPipeGraphreturnc                       y)NSTUB r       P/var/www/html/engine/venv/lib/python3.12/site-packages/torch/utils/data/graph.py_stub_unpicklerr      s    r   scan_objonly_datapipecachec                     t        j                         }t        j                  |      }t	               rddlm}  ||      }nd }g d } fd}t        t        f}		 |	D ]'  }
|
j                  |       |s|
j                  |       ) 	 |j                          |	D ]'  }
|
j                  d        |s|
j                  d        ) t	               rddlm}  |d       S # t        j                  t        t        f$ r  t	               r|j                          n Y w xY w# |	D ]'  }
|
j                  d        |s|
j                  d        ) t	               rddlm}  |d       w w xY w)Nr   )Picklerc                 z   d }t        | t              r=i }| j                         D ]&  \  }}t        |t        t        t
        f      s"|||<   ( |S t        | t        t        f      r8g }| D ]/  }t        |t        t        t
        f      s|j                  |       1 |S t        | t        t        t
        f      r| }|S N)	
isinstancedictitemsr   r   r   tuplelistappend)	ori_statestatekvs       r   getstate_hookz0_list_connected_datapipes.<locals>.getstate_hook&   s    i&E!) !1a,Z!HI E!H!  	E4=1E $a,Z!HILLO$
  	L+z#JKEr   c                     | k(  st        |       v rt        j                  |        j                  t        |              t        dfS )Nr   )idNotImplementedErrorr   addr   )objr   captured_connectionsr   s    r   reduce_hookz._list_connected_datapipes.<locals>.reduce_hook6   sD    (?bg.%% '',IIbg"B&&r   )extendF)ioBytesIOpickler   r   dillr   r   set_reduce_ex_hookset_getstate_hookdumpPickleErrorAttributeError	TypeErrorr*   )r   r   r   fpdill_Picklerdr"   r)   datapipe_classesclsdill_extendr(   s   ` `         @r   _list_connected_datapipesr<      se    	

A		A 0O ' 0<[.I# 	5C"";/%%m4	5	FF8 $ 	,C""4(%%d+	, 2 ""NI> 	x  !	 $ 	,C""4(%%d+	, 2 s6   !D& :D& C% %;D# D& "D##D& &E- -E-datapipec                 2    t               }t        | 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)r=   r   s     r   r   r   Z   s     eEHDFFr   c                     d}|s|dz  }t        j                  |t        d       |d}t               }t	        | ||      S )a6  
    Traverse the DataPipes and their attributes to extract the DataPipe graph.

    [Deprecated]
    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`.   )
stacklevelF)warningswarnFutureWarningr?   r@   )r=   r   msgr   s       r   r   r   l   sM    *	-  ^^MM#}3eEHmU;;r   c           	      V   t        | t        t        f      st        dt	        |        d      t        |       }||v ri S |j                  |       t        | ||j                               }|| i fi}|D ]2  }||   d   j                  t        |||j                                      4 |S )Nz.Expected `IterDataPipe` or `MapDataPipe`, but z	 is found   )r   r   r   RuntimeErrortyper$   r&   r<   copyupdater@   )r=   r   r   dp_idr   r8   items          r   r@   r@      s     h{ ;<<T(^<LIV
 	
 xLE~		IIe%huzz|LE"~.A P 	
%+D-NOP Hr   r   )r+   r-   rD   collections.abcr   torch.utils._import_utilsr   #torch.utils.data.datapipes.datapiper   r   __all__DataPiper   intr   r	   strr   boolr?   r   r<   r   r   r@   r   r   r   <module>rX      s    	   & 4 I ~
&+%S%/ 9::; 
A A '+A 47HA 	(^A HG8 G G$<x <t <} <D'+47Hr   