
    sg              	       
   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 d dlmZmZ ddgZeeef   Zeee
edf   f   Z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e   defdZdedede	e   defdZy)    N)
Collection)DictListOptionalSetTupleTypeUnion)dill_available)IterDataPipeMapDataPipetraversetraverse_dpsDataPipeGraphc                       y)NSTUB r       I/var/www/html/venv/lib/python3.12/site-packages/torch/utils/data/graph.py_stub_unpicklerr      s    r   scan_objonly_datapipecachereturnc                     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_hook7   sD    (?bg.%% '',IIbg"B&&r   )extendF)ioBytesIOpickler   r   dillr   r   set_reduce_ex_hookset_getstate_hookdumpPickleErrorAttributeError	TypeErrorr1   )r   r   r   fpdill_Picklerdr)   r0   datapipe_classesclsdill_extendr/   s   ` `         @r   _list_connected_datapipesrC      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)rD   r   s     r   r   r   Z   s     eEHDFFr   c                 ~    d}|s|dz  }t        j                  |t               |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`.F)warningswarnFutureWarningrF   rG   )rD   r   msgr   s       r   r   r   l   sK    *	-  ^^MM#}%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-   rC   copyupdaterG   )rD   r   r   dp_idr!   r?   items          r   rG   rG      s     h{ ;<<T(^<LIV
 	
 xLE~		IIe%huzz|LE"~.A P 	
%+D-NOP Hr   r   )r2   r4   rI   collections.abcr   typingr   r   r   r   r   r	   r
   torch.utils._import_utilsr   #torch.utils.data.datapipes.datapiper   r   __all__DataPipeintr   r   boolrC   r   r   rG   r   r   r   <module>r]      s    	   & @ @ @ 4 I ~
&{*+S%/ 9::;
@ @ '+@ 47H@ 	(^@ FG8 G G$<x < <- <D'+47Hr   