o
    h7                     @   s  U d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZmZmZmZ ddlmZmZmZmZ ddlmZ ddlmZmZmZmZmZmZmZmZmZ ddl m!Z!m"Z" g dZ#ed	Z$ed
Z%edZ&edZ'dZ(dZ)G dd deZ*G dd dej+Z,eZ-eZ.ee.ge/e0e e-f f Z1eee e-ge.f Z2eZ3ee-ge3f Z4ee3ge-f Z5ede0e6 ge6f Z7ee6gee/ee-e6f  f Z8e/e*df Z9ee.ge/e0e/e*ef  ef f Z:G dd de"Z;e< Z=i Z>e?e@e e;f eAd< G dd de"ZBi ZCe?e@e eBf eAd< i ZDe?e6e@e f eAd< zejEFdZGW n ejEjHy6   d ZIZJY nw ddlKmLZL eLeGeLdk rKd ZIZJnd  ZIZJdZMg ZNe0e eAd!< ddddd"d#e@e d$e1d%e2d&ee6 d'ee4 d(ee5 d)ee: d*dfd+d,ZOd#e@e d*dfd-d.ZPeQ ZReQe@ eAd/< d#e@e d*dfd0d1ZSd#e@e d*eTfd2d3ZUejVd d4G d5d6 d6ZWd7dd*eTfd8d9ZXd7dd*efd:d;ZYd#e@e d&e6d*dfd<d=ZZe!d>e[d?		dddddd"d#e@e d$e1d%e2d@ee7 dAee8 d&ee6 d'ee4 d(ee5 d)ee: d*dfdBdCZ\d#e@e d*dfdDdEZ]ddddd"d#e@e d$e1d%e2d&ee6 d'ee4 d(ee5 d)ee: d*dfdFdGZ^ejVd d4G dHdI dIee$ Z_edJedKZ`ejVd d4G dLdM dMee`e$f ZaejVd d4G dNdO dOZbdPe/e$df d*e/e0e$ e-f fdQdRZcdPe/e$df d*e/e0e/e*e$f  e-f fdSdTZddUee$ dVe-d*e/e$df fdWdXZedPe0e$ d*e/e0e$ e-f fdYdZZfdPe0e$ d*e/e0e/e*e$f  e-f fd[d\ZgdUee$ dVe-d*e0e$ fd]d^ZhdPe?ee$f d*e/e0e$ e-f fd_d`ZidPe?ee$f d*e/e0e/e*e$f  e-f fdadbZjdUee$ dVe-d*e?ee$f fdcddZkdPe"d*e/e0e e-f fdedfZldPe"d*e/e0e/e*ef  e-f fdgdhZmdUee$ dVe-d*e"fdidjZndVe-d*e3fdkdlZodme3d*e-fdndoZpdPeee$f d*e/e0e$ e-f fdpdqZqdPeee$f d*e/e0e/e*e$f  e-f fdrdsZrdUee$ dVe-d*eee$f fdtduZseqZtesZudPeee$f d*e/e0e$ e-f fdvdwZvdPeee$f d*e/e0e/e*e$f  e-f fdxdyZwdUee$ dVe-d*eee$f fdzd{ZxdVe-d*e3fd|d}Zydme3d*e-fd~dZzdPee$ d*e/e0e$ e-f fddZ{dPee$ d*e/e0e/e*e$f  e-f fddZ|dUee$ dVe-d*ee$ fddZ}e^e/eceededd e^e0efehdegd e^e?eiekdejd e^eelendeoepemd" e^eeqesderd e^eevexdeyezewd" e^ee{e}de|d e~e?eehZe~e@ eAd< e~e/e0e?eeeehZe~e@ eAd< ded*eTfddZded*efddZdde.deee.geTf  d*eTfddZejVd d d ddG dd dZejVd d dddG dd deZe Z	dde.deee.geTf  d*e/e0e ef fddZdee ded*e.fddZ	dde.deee.geTf  d*ee fddZ	dde.deee.geTf  d*e0e fddZ	dde.deee.geTf  d*efddZdddedef de.de.deee.geTf  d*e.f
ddZdddedef de.de.deee.geTf  d*e.f
ddZe/e@e$ e@e% f Ze/e@e$ e@e% e@e& f Zejdkree@e e/e@e df ejf Znee@e e/e@e df f Zeee$e%f ge'f Zeee$e%e&f ge'f Zee$ge'f Zeege'f Zee$geegef f Zede@e$ d*eee$ef  fddZedee$e%f d*eee$e%ef  fddZedee$e%e&f d*eee$e%e&ef  fddZeded*eee  fddZedeegeTf d*eee  fddZdeeeegeTf f d*eee  fddZe	ddee$ef de.deee.geTf  de@e$ d*e.f
ddZe	ddee$e%ef de.deee.geTf  dee$e%f d*e.f
ddZe	ddee$e%e&ef de.deee.geTf  dee$e%e&f d*e.f
ddZe	ddee de.deee.geTf  ded*e.f
ddZe	ddee de.deee.geTf  deegeTf d*e.f
ddZ	ddee de.deee.geTf  deeeegeTf f d*e.f
ddZe	ddee$ef de.deee.geTf  de@e$ d*e.f
ddZe	ddee$e%ef de.deee.geTf  dee$e%f d*e.f
ddZe	ddee$e%e&ef de.deee.geTf  dee$e%e&f d*e.f
ddZe	ddee de.deee.geTf  ded*e.f
ddZe	ddee de.deee.geTf  deegeTf d*e.f
ddZ	ddee de.deee.geTf  deeeegeTf f d*e.f
ddZ	ddeegeTf de.deee.geTf  d*eTfddȄZ	ddeegeTf de.deee.geTf  d*eTfddʄZe	ddee$eTf de.deee.geTf  de@e$ d*eTf
dd̈́Ze	ddee$e%eTf de.deee.geTf  dee$e%f d*eTf
dd̈́Ze	ddee$e%e&eTf de.deee.geTf  dee$e%e&f d*eTf
dd̈́Z	ddeeT de.deee.geTf  ded*eTf
dd̈́Ze	ddee$eTf de.deee.geTf  de@e$ d*eTf
dd҄Ze	ddee$e%eTf de.deee.geTf  dee$e%f d*eTf
dd҄Ze	ddee$e%e&eTf de.deee.geTf  dee$e%e&f d*eTf
dd҄Z	ddeeT de.deee.geTf  ded*eTf
dd҄Z	dde.dedeee.geTf  d*ee0e  fddׄZejVG ddل dكZG ddۄ de"Zi Ze?eef eAd< ded*efddބZde3d*efddZeeeed< ddedee d*e6fddZejde6d*efddZG dd dZded*e6fddZe!de[d?ded*e6fddZe!de[d?de6d*efddZde.de.d*e0e fddZ	dde.deee.geTf  d*e/e0e/e9ef  ef fddZ	dde.deee.geTf  d*e0e/e9ef  fddZ	dde9de.deee.geTf  d*ee/e9ef  fddZdddedef de.de.deee.geTf  d*e.f
ddZd e9d*e6fddZded e9d*efddZdS (  a  
Contains utility functions for working with nested python data structures.

A *pytree* is Python nested data structure. It is a tree in the sense that
nodes are Python collections (e.g., list, tuple, dict) and the leaves are
Python values. Furthermore, a pytree should not contain reference cycles.

pytrees are useful for working with nested collections of Tensors. For example,
one can use `tree_map` to map a function over all Tensors inside some nested
collection of Tensors and `tree_leaves` to get a flat list of all Tensors
inside some nested collection. pytrees are helpful for implementing nested
collection support for PyTorch APIs.

This pytree implementation is not very performant due to Python overhead
To improve the performance we can move parts of the implementation to C++.
    N)defaultdictdeque
namedtupleOrderedDict)HashableIterableMappingSequence)Enum)	AnyCallablecastGenericOptionaloverloadProtocolTypeVarUnion)
deprecated
NamedTuple)PyTreeContextFlattenFuncUnflattenFuncDumpableContextToDumpableContextFnFromDumpableContextFnTreeSpecLeafSpeckeystrkey_getregister_pytree_nodetree_flattentree_flatten_with_pathtree_unflatten	tree_itertree_leavestree_leaves_with_pathtree_structuretree_maptree_map_with_path	tree_map_tree_map_onlytree_map_only_tree_alltree_anytree_all_onlytree_any_onlytreespec_dumpstreespec_loadstreespec_pprintTSUR   NO_SERIALIZED_TYPE_NAME_FOUNDc                   @   sL   e Zd ZdefddZdedefddZdefddZ	d	e
de
fd
dZdS )KeyEntryreturnc                 C      d S N selfr?   r?   g/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/torch/utils/_pytree.py__hash__Z      zKeyEntry.__hash__otherc                 C   r=   r>   r?   rA   rE   r?   r?   rB   __eq__]   rD   zKeyEntry.__eq__c                 C   r=   r>   r?   r@   r?   r?   rB   __str__`   rD   zKeyEntry.__str__parentc                 C   r=   r>   r?   )rA   rI   r?   r?   rB   getc   rD   zKeyEntry.getN)__name__
__module____qualname__intrC   objectboolrG   strrH   r   rJ   r?   r?   r?   rB   r;   Y   s
    r;   c                       s&   e Zd Zdedef fddZ  ZS )EnumEncoderobjr<   c                    s   t |tr|jS t |S r>   )
isinstancer
   valuesuperdefaultrA   rS   	__class__r?   rB   rW   h   s   
zEnumEncoder.default)rK   rL   rM   rO   rQ   rW   __classcell__r?   r?   rY   rB   rR   g   s    rR   r   .c                   @   s6   e Zd ZU ee ed< eed< eed< ee	 ed< dS )NodeDeftype
flatten_fnunflatten_fnflatten_with_keys_fnN)
rK   rL   rM   r]   r   __annotations__r   r   r   FlattenWithKeysFuncr?   r?   r?   rB   r\      s
   
 r\   SUPPORTED_NODESc                   @   s:   e Zd ZU ee ed< eed< ee ed< ee	 ed< dS )_SerializeNodeDeftypserialized_type_nameto_dumpable_contextfrom_dumpable_contextN)
rK   rL   rM   r]   r   ra   rQ   r   r   r   r?   r?   r?   rB   rd      s
   
 rd   SUPPORTED_SERIALIZED_TYPESSERIALIZED_TYPE_TO_PYTHON_TYPEoptreeF)Versionz0.13.0T_cxx_pytree_pending_importsrf   rg   rh   r`   clsr^   r_   rf   rg   rh   r`   r<   c          
   	   C   s   t  | tv rt|  dW d   n1 sw   Y  t| ||||||d ts,dS trAddlm} |j| |||||d dS | ||f}|||d}	t	||	f dS )a  Register a container-like type as pytree node.

    Args:
        cls: the type to register
        flatten_fn: A callable that takes a pytree and returns a flattened
            representation of the pytree and additional context to represent the
            flattened pytree.
        unflatten_fn: A callable that takes a flattened version of the pytree,
            additional context, and returns an unflattened pytree.
        serialized_type_name: A keyword argument used to specify the fully qualified
            name used when serializing the tree spec.
        to_dumpable_context: An optional keyword argument to custom specify how
            to convert the context of the pytree to a custom json dumpable
            representation. This is used for json serialization, which is being
            used in torch.export right now.
        from_dumpable_context: An optional keyword argument to custom specify how
            to convert the custom json dumpable representation of the context
            back to the original context. This is used for json deserialization,
            which is being used in torch.export right now.
        flatten_with_keys_fn: An optional keyword argument to specify how to
            access each pytree leaf's keypath when flattening and tree-mapping.
            Like ``flatten_fn``, but in place of a List[leaf], it should return
            a List[(keypath, leaf)].
    z& is already registered as pytree node.Nrn   r9   )_cxx_pytree)rf   rg   rh   )
_NODE_REGISTRY_LOCKrc   
ValueError_private_register_pytree_node_cxx_pytree_exists_cxx_pytree_imported rp   rm   append)
ro   r^   r_   rf   rg   rh   r`   cxxargskwargsr?   r?   rB   r!      s@   "


	r!   c                 C   s   ddl }|j|  dS )a  Registers a ``dataclasses.dataclass`` type as a pytree node.

    This is a simpler API than :func:`register_pytree_node` for registering
    a dataclass.

    Args:
        cls: the dataclass type to register

    Example:

        >>> from torch import Tensor
        >>> from dataclasses import dataclass
        >>> import torch.utils._pytree as pytree
        >>>
        >>> @dataclass
        >>> class Point:
        >>>     x: Tensor
        >>>     y: Tensor
        >>>
        >>> pytree.register_dataclass(Point)
        >>>
        >>> point = Point(torch.tensor(0), torch.tensor(1))
        >>> point = pytree.tree_map(lambda x: x + 1, point)
        >>> assert torch.allclose(point.x, torch.tensor(1))
        >>> assert torch.allclose(point.y, torch.tensor(2))

    r   N)torch.exportexportregister_dataclass)ro   torchr?   r?   rB   r}     s   r}   CONSTANT_NODESc                 C   s   | j tj u r
td| jdu rtddd }dd }dd	 }t t| |||d
 t|  W d   dS 1 s:w   Y  dS )a  Registers a type as a pytree node with no leaves.

    In a :func:`torch.compile` region, if instances of these types get passed to
    :func:`torch._dynamo.nonstrict_trace`-ed function, they treated as a
    constant (sometimes referred to as "static"):

    1. if the instance object existed before the :func:`torch.compile` region,
    we _assume_ no mutation will happen to it inside the :func:`torch.compile`
    region, require that it has non-default `__eq__` and `__hash__` methods, and
    we guard on the instance based on its `__eq__` method, i.e., if a new
    instance fails to match any instances from the previous compilations,
    :func:`torch.compile` will recompile the function using the new instance.

    2. else if the instance object is created inside the :func:`torch.compile`
    region, we currently don't support using it in a
    :func:`torch._dynamo.nonstrict_trace`-ed function.

    In general, if your class holds Tensors or dynamic int/float/bool (values that
    may change from run-to-run of a function being compiled), then you probably
    do not want to register it as a constant.

    Otherwise if you want to pass instance of a class to a
    :func:`torch._dynamo.nonstrict_trace`-ed function, but you either can't use
    :func:`register_pytree_node` on the class, or the class is "constant" enough
    that you don't want to bother using :func:`register_pytree_node`, you should
    consider using this function.

    Args:
        cls: the type to register as a constant. This type must be hashable.

    Example:

        >>> from dataclasses import dataclass
        >>> import torch.utils._pytree as pytree
        >>>
        >>> @dataclass(frozen=True)
        >>> class Config:
        >>>     norm: str
        >>>
        >>> pytree.register_constant(Config)
        >>>
        >>> config = Config("l2")
        >>> values, spec = pytree.tree_flatten(config)
        >>> assert len(values) == 0

    zSregister_constant(cls) expects `cls` to have a non-default `__eq__` implementation.NzUregister_constant(cls) expects `cls` to have a non-default `__hash__` implementation.c                 S      g t | fS r>   ConstantNodexr?   r?   rB   _flattenb     z#register_constant.<locals>._flattenc                 S   s   |j S r>   )rU   )_contextr?   r?   rB   
_unflattene  s   z%register_constant.<locals>._unflattenc                 S   r   r>   r   r   r?   r?   rB   _flatten_with_keysh  r   z-register_constant.<locals>._flatten_with_keys)r`   )rG   rO   	TypeErrorrC   rq   rs   r   add)ro   r   r   r   r?   r?   rB   register_constant'  s(   /
"r   c                 C   s   t | to| tv S r>   )rT   r]   r   ro   r?   r?   rB   is_constant_classu  s   r   )frozenc                   @   s   e Zd ZU eed< dS )r   rU   N)rK   rL   rM   r   ra   r?   r?   r?   rB   r   y  s   
 r   specc                 C   s   t | jtS )zEChecks if the spec is from a pytree registered with register_constant)rT   r   r   r   r?   r?   rB   _is_constant_holder~  s   r   c                 C   s   t | sJ tg | S )zTGiven a spec from a pytree registered with register_constant, retrieves the constant)r   r$   r   r?   r?   rB   _retrieve_constant  s   
r   c             	   C   s   t | tt|tttd dS )a  
    Registers a namedtuple as a valid pytree node. By default namedtuples are
    valid pytree nodes, but they are not serializable. This API provides the
    argument `serialized_type_name` which allows these namedtuples to be
    serialized.

    Args:
        cls: the dataclass type to register
        serialized_type_name: The serialized name for the dataclass. This is
        required if you want to serialize the pytree TreeSpec containing this
        namedtuple.
    rn   N)rs   _namedtuple_flatten_namedtuple_unflatten_namedtuple_serialize_namedtuple_deserialize_namedtuple_flatten_with_keys)ro   rf   r?   r?   rB   _register_namedtuple  s   
r   zy`torch.utils._pytree._register_pytree_node` is deprecated. Please use `torch.utils._pytree.register_pytree_node` instead.)category	to_str_fnmaybe_from_str_fnc          	   	   C   s:   |dus|durt jdtdd t| ||||||d dS )a  Register a container-like type as pytree node for the Python pytree only.

    Args:
        cls: the type to register
        flatten_fn: A callable that takes a pytree and returns a flattened
            representation of the pytree and additional context to represent the
            flattened pytree.
        unflatten_fn: A callable that takes a flattened version of the pytree,
            additional context, and returns an unflattened pytree.
        serialized_type_name: A keyword argument used to specify the fully qualified
            name used when serializing the tree spec.
        to_dumpable_context: An optional keyword argument to custom specify how
            to convert the context of the pytree to a custom json dumpable
            representation. This is used for json serialization, which is being
            used in torch.export right now.
        from_dumpable_context: An optional keyword argument to custom specify how
            to convert the custom json dumpable representation of the context
            back to the original context. This is used for json deserialization,
            which is being used in torch.export right now.
        flatten_with_keys_fn: An optional keyword argument to specify how to
            access each pytree leaf's keypath when flattening and tree-mapping.
            Like ``flatten_fn``, but in place of a List[leaf], it should return
            a List[(keypath, leaf)].
    Nzx`to_str_fn` and `maybe_from_str_fn` is deprecated. Please use `to_dumpable_context` and `from_dumpable_context` instead.   )
stacklevelrn   )warningswarnFutureWarningrs   )	ro   r^   r_   r   r   rf   rg   rh   r`   r?   r?   rB   _register_pytree_node  s   )
r   c                 C   sP   t  t| = t|  }t|j= t| = t|  W d   dS 1 s!w   Y  dS )zThis is an internal function that is used to deregister a pytree node type
    for the Python pytree only. This should be only used inside PyTorch.
    N)rq   rc   ri   rj   rf   r   discard)ro   node_defr?   r?   rB   _deregister_pytree_node  s   "r   c          	      C   s   t E | tv rt|  d t| |||}|t| < |du |du A r*td|  d|du r0t}t| |||}|t| < | t	|< W d   dS 1 sJw   Y  dS )zThis is an internal function that is used to register a pytree node type
    for the Python pytree only. End-users should use :func:`register_pytree_node`
    instead.
    zM is already registered as pytree node. Overwriting the previous registration.Nz7Both to_dumpable_context and from_dumpable_context for z must be None or registered.)
rq   rc   r   r   r\   rr   r:   rd   ri   rj   )	ro   r^   r_   rf   rg   rh   r`   r   serialize_node_defr?   r?   rB   rs     s,   

"rs   c                   @   s:   e Zd ZU eed< defddZdee defddZ	dS )	SequenceKeyidxr<   c                 C      d| j dS N[]r   r@   r?   r?   rB   rH        zSequenceKey.__str__sequencec                 C   
   || j  S r>   r   )rA   r   r?   r?   rB   rJ   "     
zSequenceKey.getN)
rK   rL   rM   rN   ra   rQ   rH   r	   r5   rJ   r?   r?   r?   rB   r     s   
 r   K)boundc                   @   s>   e Zd ZU eed< defddZdeeef defddZ	dS )	
MappingKeykeyr<   c                 C   r   r   r   r@   r?   r?   rB   rH   -  r   zMappingKey.__str__mappingc                 C   r   r>   r   )rA   r   r?   r?   rB   rJ   0  r   zMappingKey.getN)
rK   rL   rM   r   ra   rQ   rH   r   r5   rJ   r?   r?   r?   rB   r   )  s   
 r   c                   @   s6   e Zd ZU eed< defddZdedefddZdS )	
GetAttrKeynamer<   c                 C   s   d| j  S )N.)r   r@   r?   r?   rB   rH   8  r   zGetAttrKey.__str__rS   c                 C   s   t || jS r>   )getattrr   rX   r?   r?   rB   rJ   ;  r   zGetAttrKey.getN)rK   rL   rM   rQ   ra   rH   r   rJ   r?   r?   r?   rB   r   4  s   
 r   dc                 C   s   t | d fS r>   listr   r?   r?   rB   _tuple_flatten?  r   r   c                 C   "   t | \}}dd t|D |fS )Nc                 S      g | ]
\}}t ||fqS r?   r   .0ivr?   r?   rB   
<listcomp>G      z,_tuple_flatten_with_keys.<locals>.<listcomp>)r   	enumerater   valuesr   r?   r?   rB   _tuple_flatten_with_keysC     r   r   r   c                 C      t | S r>   )tupler   r   r?   r?   rB   _tuple_unflattenJ     r   c                 C   s   | d fS r>   r?   r   r?   r?   rB   _list_flattenN  r   r   c                 C   r   )Nc                 S   r   r?   r   r   r?   r?   rB   r   T  r   z+_list_flatten_with_keys.<locals>.<listcomp>)r   r   r   r?   r?   rB   _list_flatten_with_keysR  s   r   c                 C   r   r>   r   r   r?   r?   rB   _list_unflattenW  r   r   c                 C      t |  t |  fS r>   r   r   keysr   r?   r?   rB   _dict_flatten[     r   c                 C   $   t | \}}dd t||D |fS )Nc                 S   r   r?   r   r   kr   r?   r?   rB   r   c  r   z+_dict_flatten_with_keys.<locals>.<listcomp>)r   zipr   r?   r?   rB   _dict_flatten_with_keys_     r   c                 C   s   t t|| S r>   )dictr   r   r?   r?   rB   _dict_unflattenf  r   r   c                 C   s   t | t| fS r>   )r   r]   r   r?   r?   rB   r   j  s   r   c                 C   s&   t | \}}dd t|j|D |fS )Nc                 S   r   r?   )r   )r   fieldr   r?   r?   rB   r   s  r   z1_namedtuple_flatten_with_keys.<locals>.<listcomp>)r   r   _fieldsr   r?   r?   rB   r   n  s   r   c                 C   s   t t||  S r>   )r   r   r   r?   r?   rB   r   x  r   r   c                 C   sB   | t vrtd|  dt |  }|j}|tkrtd|  d|S )Nz-Can't serialize TreeSpec of namedtuple class zc because we didn't register a serializated_type_name. Please register using `_register_namedtuple`.za because we couldn't find a serializated_type_name. Please register using `_register_namedtuple`.)ri   NotImplementedErrorrf   r:   )r   r   rf   r?   r?   rB   r   |  s   

r   dumpable_contextc                 C   s$   | t vrtd|  dt |  }|S )Nz/Can't deserialize TreeSpec of namedtuple class z. because we couldn't find a serializated name.)rj   r   )r   re   r?   r?   rB   r     s   
r   c                 C   r   r>   r   r   r?   r?   rB   _ordereddict_flatten  r   r   c                 C   r   )Nc                 S   r   r?   r   r   r?   r?   rB   r     r   z2_ordereddict_flatten_with_keys.<locals>.<listcomp>)r   r   r   r?   r?   rB   _ordereddict_flatten_with_keys  r   r   c                 C   s   t dd t|| D S )Nc                 s   s    | ]	\}}||fV  qd S r>   r?   )r   r   rU   r?   r?   rB   	<genexpr>      z)_ordereddict_unflatten.<locals>.<genexpr>)r   r   r   r?   r?   rB   _ordereddict_unflatten  s   r   c                 C   s   t | \}}|| j|gfS r>   )r   default_factory)r   r   dict_contextr?   r?   rB   _defaultdict_flatten  s   r   c                 C   s,   t | \}}|\}}dd t||D |fS )Nc                 S   r   r?   r   r   r?   r?   rB   r     r   z2_defaultdict_flatten_with_keys.<locals>.<listcomp>)r   r   )r   r   r   r   r   r?   r?   rB   _defaultdict_flatten_with_keys  s   r   c                 C   s   |\}}t |t| |S r>   )r   r   )r   r   r   r   r?   r?   rB   _defaultdict_unflatten  s   r   c                 C   s   | \}}|j |j|d}|S )N)default_factory_moduledefault_factory_namer   )rL   rM   )r   r   r   json_defaultdictr?   r?   rB   _defaultdict_serialize  s   r   c                 C   sr   t | tsJ t| h dksJ | d }| d }t |ts J t |ts'J t|}t||}| d }||gS )N>   r   r   r   r   r   r   )rT   r   setrQ   	importlibimport_moduler   )r   r   r   moduler   r   r?   r?   rB   _defaultdict_deserialize  s   

r   c                 C   s   t | | jfS r>   )r   maxlenr   r?   r?   rB   _deque_flatten  r   r   c                 C   r   )Nc                 S   r   r?   r   r   r?   r?   rB   r     r   z,_deque_flatten_with_keys.<locals>.<listcomp>)r   r   r   r?   r?   rB   _deque_flatten_with_keys  r   r   c                 C   s   t | |dS )Nr   )r   r   r?   r?   rB   _deque_unflatten  r   r  zbuiltins.tuple)rf   r`   zbuiltins.listzbuiltins.dictzcollections.namedtuplezcollections.OrderedDictzcollections.defaultdictzcollections.dequeSTANDARD_DICT_TYPESBUILTIN_TYPEStreec                 C   sV   t | }|j}t|dks|d tkrdS t|dd }t|ts"dS tdd |D S )Nr9   r   Fr   c                 s   s    | ]	}t |tkV  qd S r>   )r]   rQ   )r   entryr?   r?   rB   r   :  r   z*_is_namedtuple_instance.<locals>.<genexpr>)r]   	__bases__lenr   r   rT   all)r  re   basesfieldsr?   r?   rB   _is_namedtuple_instance2  s   
r  c                 C   s   t | rtS t| S r>   )r  r   r]   r  r?   r?   rB   _get_node_type=  s   r  is_leafc                 C   s   |d ur|| pt | tvS r>   )r  rc   r  r  r?   r?   rB   _is_leafD  s
   r  )initr   eqreprc                   @   s   e Zd ZU eed< eed< ed  ed< ejddZ	e
ed< ejddZe
ed< ejddZe
ed< dddZdde
d	efddZded	efddZd	efddZded	ee fddZdee d	efddZd
S )r   r]   r   children_specsF)r  	num_nodes
num_leavesnum_childrenr<   Nc                 C   sd   t dd | jD dd}t dd | jD }t| j}t| d| t| d| t| d| d S )	Nc                 s       | ]}|j V  qd S r>   )r  r   r   r?   r?   rB   r   Z      z)TreeSpec.__post_init__.<locals>.<genexpr>r9   )startc                 s   r  r>   )r  r  r?   r?   rB   r   [  r  r  r  r  )sumr  r  rO   __setattr__)rA   r  r  r  r?   r?   rB   __post_init__Y  s   
zTreeSpec.__post_init__r   indentc                    s   d| j j d| j d}d}| jdkr? d7  || jd  7 }|| jdkr)dnd7 }|d fd	d
| jdd  D 7 }| d}|| S )Nz	TreeSpec(z, z, [rv   r   r   r9   ,c                    s"   g | ]}d d   |   qS )
 )__repr__r   childr  r?   rB   r   i  s    z%TreeSpec.__repr__.<locals>.<listcomp>z]))r]   rK   r   r  r  r#  join)rA   r  repr_prefixchildren_specs_strrepr_suffixr?   r&  rB   r#  a  s   


zTreeSpec.__repr__rE   c                 C   sX   | |u rdS |j | j u r*t| jt|jkrdS | j|jkr dS | j|jkr(dS dS tS )NTF)rZ   rQ   r]   r   r  NotImplementedrF   r?   r?   rB   rG   q  s   zTreeSpec.__eq__c                 C   s   | j dko	| jdkS )Nr9   )r  r  r@   r?   r?   rB   r  ~  s   zTreeSpec.is_leafr  c                    s6   dt dtdtt dd f fdd g } | || |S )Ntreespecr  subtreesr<   c                    s  |   r|  d S t }| jtvrT|| jkr%td| jd|dt| j}| \}}t|| j	krEtd| j	 dt| d|| j
krStd| jdn| jtv o\|tv }|sp|| jkrptd| jd|dt | j	krtd| j	 dt  d|r| jtur| j
n| j
d }|}	t }
t|	}|
|kr||
}|
|}d}|r|d	| 7 }|r|d
| 7 }td| d fdd|	D }n$t| j}| \}}|tur|| j
krtd| jd| j
d|dt|| jD ]
\}}||| qd S )NzType mismatch; expected z
, but got r   zNode arity mismatch; expected z+Node context mismatch for custom node type zNode type mismatch; expected r9   rv   z; missing key(s): z; extra key(s): zNode keys mismatchc                    s   g | ]} | qS r?   r?   )r   r   r  r?   rB   r         z:TreeSpec.flatten_up_to.<locals>.helper.<locals>.<listcomp>z$Node context mismatch for node type z; expected )r  rw   r  r]   r  rr   rc   r^   r  r  r   r  r   r   
differencer   r   r  )r,  r  r-  	node_typer^   childrenr   both_standard_dictr   expected_keysgot_key_setexpected_key_setmissing_keys
extra_keysmessagesubtreesubspechelperr  rB   r<    s   











z&TreeSpec.flatten_up_to.<locals>.helper)r   r   r   )rA   r  r-  r?   r;  rB   flatten_up_to  s   "NzTreeSpec.flatten_up_toleavesc                 C   s   t |ttfst|}t|| jkr#tdt| d| j d|  d|  r+|d S t| j j	}d}d}g }| j
D ]}||j7 }|||||  |}q:||| jS )Nz0treespec.unflatten(leaves): `leaves` has length z, but the spec refers to a pytree that holds z items (z).r   )rT   r   r   r  r  rr   r  rc   r]   r_   r  rw   	unflattenr   )rA   r>  r_   r  endchild_pytrees
child_specr?   r?   rB   r?    s*   

zTreeSpec.unflattenr<   Nr   )rK   rL   rM   r   ra   r   r   dataclassesr   r  rN   r  r  r  rQ   r#  r   rP   rG   r  r=  r   r?  r?   r?   r?   rB   r   O  s   
 
Sc                   @   sr   e Zd ZU ejdddZeed< ejdddZe	ed< eje
ddZe
d ed< dd
dZdded	efddZdS )r   NF)rW   r  r]   r   )r   r  r   r  r<   c                 C   s.   t | dd t | dd t | dd d S )Nr  r9   r  r  r   )rO   r  r@   r?   r?   rB   r    s   zLeafSpec.__post_init__r   r  c                 C      dS N*r?   )rA   r  r?   r?   rB   r#     rD   zLeafSpec.__repr__rC  rD  )rK   rL   rM   rE  r   r]   r   ra   r   r   r   r  r  rN   rQ   r#  r?   r?   r?   rB   r     s   
 
r   c                    s6   dt dtt dtf fdd g } | |}||fS )zkFlattens a pytree into a list of values and a TreeSpec that can be used
    to reconstruct the pytree.
    noder>  r<   c                    sX   t | dr |  tS t| }t| j}|| \}} fdd|D }t|||S )Nr  c                    s   g | ]} |qS r?   r?   r$  )r<  r>  r?   rB   r         z0tree_flatten.<locals>.helper.<locals>.<listcomp>)r  rw   
_LEAF_SPECr  rc   r^   r   )rI  r>  r0  r^   r1  r   subspecsr<  r  )r>  rB   r<    s   

ztree_flatten.<locals>.helper)r   r   r   r   )r  r  r>  r,  r?   rN  rB   r"   	  s    
r"   r>  r,  c                 C   s(   t |tstdt| d|| S )zqGiven a list of values and a TreeSpec, builds a pytree.
    This is the inverse operation of `tree_flatten`.
    zftree_unflatten(leaves, treespec): Expected `treespec` to be instance of TreeSpec but got item of type r   )rT   r   r   r]   r?  )r>  r,  r?   r?   rB   r$   #  s   

r$   c                 c   sV    t | |dr| V  dS t| }t| j}|| \}}|D ]}t||dE dH  qdS )z,Get an iterator over the leaves of a pytree.rJ  N)r  r  rc   r^   r%   )r  r  r0  r^   rA  r   r%  r?   r?   rB   r%   /  s   

r%   c                 C   s   t t| |dS )z!Get a list of leaves of a pytree.rJ  )r   r%   r  r?   r?   rB   r&   @     r&   c                 C   s   t | |dd S )zGet the TreeSpec for a pytree.rJ  r9   )r"   r  r?   r?   rB   r(   H  rO  r(   rJ  funcrestsc                   s>   t ||d\} |g fdd|D  } t| g|R  S )a  Map a multi-input function over pytree args to produce a new pytree.

    See also :func:`tree_map_`.

    >>> tree_map(lambda x: x + 1, {'x': 7, 'y': (42, 64)})
    {'x': 8, 'y': (43, 65)}
    >>> tree_map(lambda x: x is None, {'x': 7, 'y': (42, 64), 'z': None})
    {'x': False, 'y': (False, False), 'z': True}

    If multiple inputs are given, the structure of the tree is taken from the first input;
    subsequent inputs need only have ``tree`` as a prefix:

    >>> tree_map(lambda x, y: [x] + y, [5, 6], [[7, 9], [1, 2]])
    [[5, 7, 9], [6, 1, 2]]

    Args:
        func (callable): A function that takes ``1 + len(rests)`` arguments, to be applied at the
            corresponding leaves of the pytrees.
        tree (pytree): A pytree to be mapped over, with each leaf providing the first positional
            argument to function ``func``.
        rests (tuple of pytree): A tuple of pytrees, each of which has the same structure as
            ``tree`` or has ``tree`` as a prefix.
        is_leaf (callable, optional): An extra leaf predicate function that will be called at each
            flattening step. The function should have a single argument with signature
            ``is_leaf(node) -> bool``. If it returns :data:`True`, the whole subtree being treated
            as a leaf. Otherwise, the default pytree registry will be used to determine a node is a
            leaf or not. If the function is not specified, the default pytree registry will be used.

    Returns:
        A new pytree with the same structure as ``tree`` but with the value at each leaf given by
        ``func(x, *xs)`` where ``x`` is the value at the corresponding leaf in ``tree`` and ``xs``
        is the tuple of values at corresponding nodes in ``rests``.
    rJ  c                       g | ]}  |qS r?   r=  r   rr,  r?   rB   r   x  rK  ztree_map.<locals>.<listcomp>)r"   r?  maprP  r  r  rQ  r>  	flat_argsr?   rV  rB   r)   P  s   'r)   c                   sD   t ||d\} |g fdd|D  }tt| g|R  dd |S )aT  Like :func:`tree_map`, but do an inplace call on each leaf and return the original tree.

    See also :func:`tree_map`.

    Args:
        func (callable): A function that takes ``1 + len(rests)`` arguments, to be applied at the
            corresponding leaves of the pytrees.
        tree (pytree): A pytree to be mapped over, with each leaf providing the first positional
            argument to function ``func``.
        rests (tuple of pytree): A tuple of pytrees, each of which has the same structure as
            ``tree`` or has ``tree`` as a prefix.
        is_leaf (callable, optional): An extra leaf predicate function that will be called at each
            flattening step. The function should have a single argument with signature
            ``is_leaf(node) -> bool``. If it returns :data:`True`, the whole subtree being treated
            as a leaf. Otherwise, the default pytree registry will be used to determine a node is a
            leaf or not. If the function is not specified, the default pytree registry will be used.

    Returns:
        The original ``tree`` with the value at each leaf is given by the side-effect of function
        ``func(x, *xs)`` (not the return value) where ``x`` is the value at the corresponding leaf
        in ``tree`` and ``xs`` is the tuple of values at values at corresponding nodes in ``rests``.
    rJ  c                    rR  r?   rS  rT  rV  r?   rB   r     rK  ztree_map_.<locals>.<listcomp>r   r   )r"   r   rW  rX  r?   rV  rB   r+   |  s   r+      
   type_or_types_or_predc                C   r=   r>   r?   r]  r?   r?   rB   map_only     r_  c                C   r=   r>   r?   r^  r?   r?   rB   r_    r`  c                C   r=   r>   r?   r^  r?   r?   rB   r_    r`  c                C   r=   r>   r?   r^  r?   r?   rB   r_    r`  c                C   r=   r>   r?   r^  r?   r?   rB   r_    r`  c                   s   t ttfstjdkrt tjrdtdtffdd nt	r% nt
ddttgtf dttgtf f fdd	}|S )
a  
    Suppose you are writing a tree_map over tensors, leaving everything
    else unchanged.  Ordinarily you would have to write:

        def go(t):
            if isinstance(t, Tensor):
                return ...
            else:
                return t

    With this function, you only need to write:

        @map_only(Tensor)
        def go(t):
            return ...

    You can also directly use 'tree_map_only'
    rZ  r   r<   c                    s
   t |  S r>   rT   r   r^  r?   rB   pred  r   zmap_only.<locals>.predz9Argument must be a type, a tuple of types, or a callable.rP  c                    s&   t  dtdtf fdd}|S )Nr   r<   c                    s   | r | S | S r>   r?   r   )rP  rb  r?   rB   wrapped  s   z*map_only.<locals>.wrapper.<locals>.wrapped)	functoolswrapsr5   r   )rP  rc  )rb  rP  rB   wrapper  s   zmap_only.<locals>.wrapper)rT   r]   r   sysversion_infotypes	UnionTyper   rP   callabler   r   r5   )r]  rg  r?   )rb  r]  rB   r_    s   

*	c                C   r=   r>   r?   r]  rP  r  r  r?   r?   rB   r,        r,   c                C   r=   r>   r?   rm  r?   r?   rB   r,     rn  c                C   r=   r>   r?   rm  r?   r?   rB   r,     rn  c                C   r=   r>   r?   rm  r?   r?   rB   r,     rn  c                C   r=   r>   r?   rm  r?   r?   rB   r,   #  rn  c                C      t t| |||dS NrJ  )r)   r_  rm  r?   r?   rB   r,   .     c                C   r=   r>   r?   rm  r?   r?   rB   r-   8  rn  r-   c                C   r=   r>   r?   rm  r?   r?   rB   r-   C  rn  c                C   r=   r>   r?   rm  r?   r?   rB   r-   N  rn  c                C   r=   r>   r?   rm  r?   r?   rB   r-   Y  rn  c                C   r=   r>   r?   rm  r?   r?   rB   r-   d  rn  c                C   ro  rp  )r+   r_  rm  r?   r?   rB   r-   o  rq  rb  c                 C      t ||d}tt| |S rp  )r%   r  rW  rb  r  r  rY  r?   r?   rB   r.   y     r.   c                 C   rr  rp  )r%   anyrW  rs  r?   r?   rB   r/     rt  r/   type_or_typesc                C   r=   r>   r?   rv  rb  r  r  r?   r?   rB   r0     rn  r0   c                C   r=   r>   r?   rw  r?   r?   rB   r0     rn  c                C   r=   r>   r?   rw  r?   r?   rB   r0     rn  c                   $   t ||d}t fdd|D S )NrJ  c                 3   "    | ]}t |r |V  qd S r>   ra  r   r   rb  rv  r?   rB   r          z tree_all_only.<locals>.<genexpr>)r%   r  rv  rb  r  r  rY  r?   r{  rB   r0        c                C   r=   r>   r?   rw  r?   r?   rB   r1     rn  r1   c                C   r=   r>   r?   rw  r?   r?   rB   r1     rn  c                C   r=   r>   r?   rw  r?   r?   rB   r1     rn  c                   rx  )NrJ  c                 3   ry  r>   ra  rz  r{  r?   rB   r     r|  z tree_any_only.<locals>.<genexpr>)r%   ru  r}  r?   r{  rB   r1     r~  c                 C   s   t |tsJ t| |dr| g|j S | rd S t| }||jkr$d S t| j}|| \}}t	||j
ks;||jkr=d S g }t||jD ]\}}	t||	|d}
|
d urY||
7 }qE d S |S rp  )rT   r   r  r  r  r  r]   rc   r^   r  r  r   r   r  _broadcast_to_and_flatten)r  r,  r  r0  r^   rA  ctxresultr%  rB  flatr?   r?   rB   r    s&   


r  c                   @   s2   e Zd ZU dZee ed< eed< ed  ed< dS )_TreeSpecSchemaa  
    _TreeSpecSchema is the schema used to serialize the TreeSpec
    It contains the following fields:
    - type: A string name of the type. null for the case of a LeafSpec.
    - context: Any format which is json dumpable
    - children_spec: A list of children serialized specs.
    r]   r   children_specN)	rK   rL   rM   __doc__r   rQ   ra   r   r   r?   r?   r?   rB   r    s
   
 r  c                   @   s2   e Zd ZU eegef ed< eegef ed< dS )_ProtocolFntreespec_to_jsonjson_to_treespecN)rK   rL   rM   r   r   r   ra   r?   r?   r?   rB   r    s   
 r  _SUPPORTED_PROTOCOLSc              
   C   s   |   r
td d g S | jtvrtd| j dt| j }|j}|tkr-td| j d|jd u rNz
tj	| j
td}W n tyM } ztd|d }~ww || j
}dd | jD }t|||S )	NzSerializing  in pytree is not registered.z%No registered serialization name for zZ found. Please update your _register_pytree_node call with a `serialized_type_name` kwarg.r   zUnable to serialize context. Please make the context json dump-able, or register a custom serializer using _register_pytree_node.c                 S      g | ]}t |qS r?   )_treespec_to_jsonr$  r?   r?   rB   r   C  r.  z%_treespec_to_json.<locals>.<listcomp>)r  r  r]   ri   r   rf   r:   rg   jsondumpsr   rR   r   r  )r,  r   rf   serialized_contextechild_schemasr?   r?   rB   r  $  s4   


r  json_schemac              
   C   s   | d d u r| d d u rt | d dkrtS | d tvr&td| d  dt| d  }t| }|jd u rPz	t| d }W n tyO } ztd|d }~ww || d }dd	 | d D }t	|||S )
Nr]   r   r  r   zDeserializing r  zUnable to deserialize context. Please make the context json load-able, or register a custom serializer using _register_pytree_node.c                 S   r  r?   )_json_to_treespec)r   child_stringr?   r?   rB   r   d  s    z%_json_to_treespec.<locals>.<listcomp>)
r  rL  rj   r   ri   rh   r  loadsr   r   )r  re   r   r   exr  r?   r?   rB   r  H  s4   
r  protocolc                 C   sz   t | tstdt|  d|d u rt}|tv r!t| | }ntd| dtt	  t
j|t|ftd}|S )Nzhtreespec_dumps(treespec, protocol): Expected `treespec` to be instance of TreeSpec but got item of type r   Unknown protocol . Available protocols: r   )rT   r   r   r]   'DEFAULT_TREESPEC_SERIALIZATION_PROTOCOLr  r  rr   r   r   r  r  rE  asdictrR   )r,  r  	json_specstr_specr?   r?   rB   r2   n  s"   

r2   
serializedc                 C   s@   t | \}}|tv rt| |S td| dtt  )Nr  r  )r  r  r  r  rr   r   r   )r  r  r  r?   r?   rB   r3     s   
r3   c                   @   s   e Zd ZdefddZdS )
_DummyLeafr<   c                 C   rF  rG  r?   r@   r?   r?   rB   r#    rD   z_DummyLeaf.__repr__N)rK   rL   rM   rQ   r#  r?   r?   r?   rB   r    s    r  c                 C   s"   t dd t| jD | }t|S )Nc                 S   s   g | ]}t  qS r?   )r  )r   r   r?   r?   rB   r     s    z#treespec_pprint.<locals>.<listcomp>)r$   ranger  r  )r,  
dummy_treer?   r?   rB   r4     s
   r4   zC`pytree_to_str` is deprecated. Please use `treespec_dumps` instead.c                 C   r   r>   )r2   rV  r?   r?   rB   pytree_to_str     r  zC`str_to_pytree` is deprecated. Please use `treespec_loads` instead.r  c                 C   r   r>   )r3   )r  r?   r?   rB   str_to_pytree  r  r  ry   rz   c                  O   s<   g }| D ]	}| t| q| D ]	}| t| q|S )zpGet a flat list of arguments to this function

    A slightly faster version of tree_leaves((args, kwargs))
    )extendr%   r   )ry   rz   r>  ar?   r?   rB   arg_tree_leaves  s   r  c                 C   s"   t | |\}}ttd| ||fS )a  Flattens a pytree like :func:`tree_flatten`, but also returns each leaf's key path.

    Args:
        tree: a pytree to flatten. If it contains a custom type, that type must be
            registered with an appropriate `tree_flatten_with_path_fn` when registered
            with :func:`register_pytree_node`.
        is_leaf: An extra leaf predicate function that will be called at each
            flattening step. The function should have a single argument with signature
            ``is_leaf(node) -> bool``. If it returns :data:`True`, the whole subtree being treated
            as a leaf. Otherwise, the default pytree registry will be used to determine a node is a
            leaf or not. If the function is not specified, the default pytree registry will be used.
    Returns:
        A tuple where the first element is a list of (key path, leaf) pairs, and the
        second element is a :class:`TreeSpec` representing the structure of the flattened
        tree.
    r?   )r"   r   _generate_key_paths)r  r  r   r,  r?   r?   rB   r#     s   r#   c                 C   s   t td| |S )a8  Gets the leaves of a pytree like ``tree_leaves`` and returns each leaf's key path.

    Args:
        tree: a pytree. If it contains a custom type, that type must be
            registered with an appropriate `tree_flatten_with_path_fn` when registered
            with :func:`register_pytree_node`.
        is_leaf: An extra leaf predicate function that will be called at each
            flattening step. The function should have a single argument with signature
            ``is_leaf(node) -> bool``. If it returns :data:`True`, the whole subtree being treated
            as a leaf. Otherwise, the default pytree registry will be used to determine a node is a
            leaf or not. If the function is not specified, the default pytree registry will be used.
    Returns:
        A list of (key path, leaf) pairs.
    r?   )r   r  r  r?   r?   rB   r'     s   r'   key_pathc           
      c   s    |r||r| |fV  d S t |}t|}|s | |fV  d S |j}|rB||\}}|D ]\}}	tg | |R |	|E d H  q-d S td| d)Nz.Did not find a flatten_with_keys_fn for type: zF. Please pass a flatten_with_keys_fn argument to register_pytree_node.)r  rc   rJ   r`   r  rr   )
r  r  r  r0  handlerflatten_with_keyskey_childrenr   r   cr?   r?   rB   r    s$   



r  c                   sL   t ||\}tt| }|fdd|D  } fddt| D S )a  Like :func:`tree_map`, but the provided callable takes an additional key path argument.

    Args:
        func: A function that takes ``2 + len(rests)`` arguments, to be applied at the
            corresponding leaves of the pytrees. The first positional argument
            to ``func`` is the key path of the leaf in question. The second
            positional argument is the value of the leaf.
        tree: A pytree to be mapped over, with each leaf providing the first positional
            argument to function ``func``.
        rests: A tuple of pytrees, each of which has the same structure as
            ``tree`` or has ``tree`` as a prefix.
        is_leaf: An extra leaf predicate function that will be called at each
            flattening step. The function should have a single argument with signature
            ``is_leaf(node) -> bool``. If it returns :data:`True`, the whole subtree being treated
            as a leaf. Otherwise, the default pytree registry will be used to determine a node is a
            leaf or not. If the function is not specified, the default pytree registry will be used.

    Returns
        A new pytree with the same structure as ``tree`` but with the value at each leaf given by
        ``func(keypath, x, *xs)`` where ``keypath`` is the key path at the
        corresponding leaf in ``tree``, ``x`` is the value at that leaf, and
        ``xs`` is the tuple of values at corresponding nodes in ``rests``.
    c                    rR  r?   rS  rT  rV  r?   rB   r   %  rK  z&tree_map_with_path.<locals>.<listcomp>c                 3   s    | ]} | V  qd S r>   r?   )r   xsrf  r?   rB   r   &  s    z%tree_map_with_path.<locals>.<genexpr>)r#   r   r   r?  )rP  r  r  rQ  keypath_leavesall_keypath_leavesr?   )rP  r,  rB   r*     s   r*   kpc                 C   s   d dd | D S )z9Given a key path, return a pretty-printed representation.rv   c                 S   r  r?   )rQ   )r   r   r?   r?   rB   r   +  r.  zkeystr.<locals>.<listcomp>)r'  )r  r?   r?   rB   r   )  s   r   rS   c                 C   s   |D ]}| | } q| S )zAGiven an object and a key path, return the value at the key path.)rJ   )rS   r  r   r?   r?   rB   r    .  s   r    )NNr>   )r  rE  rd  r   importlib.metadatar  rh  	threadingrj  r   collectionsr   r   r   r   collections.abcr   r   r   r	   enumr
   typingr   r   r   r   r   r   r   r   r   typing_extensionsr   r   __all__r5   r6   r7   r8   r  r:   r;   JSONEncoderrR   r   r   r   r   r   r   r   r   r   rQ   	ToStrFuncMaybeFromStrFuncKeyPathrb   r\   RLockrq   rc   r   r]   ra   rd   ri   rj   metadataversion_optree_versionPackageNotFoundError_cxx_pytree_dynamo_traceablert   torch._vendor.packaging.versionrl   ru   rm   r!   r}   r   r   r   rP   r   	dataclassr   r   r   r   r   r   r   rs   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   _odict_flatten_odict_unflattenr   r   r   r   r   r   r   r  	frozensetr  r  r  r  r  r   r   rL  r"   r$   r%   r&   r(   r)   r+   Type2Type3ri  rk  TypeAnyFn2Fn3FnFnAny	MapOnlyFnr_  r,   r-   r.   r/   r0   r1   r  r  r  r  rN   r  r  r2   	lru_cacher3   r  r4   r  r  r  r#   r'   r  r*   r   r    r?   r?   r?   rB   <module>   s   ,#"

	
H#N

		
7
	

,



&


""*&

"

&



&




"
			( #






0

""$*.&

.
















	











"$#	


!

#"