Ë
    [^(h7ó  ã                   ó<  — 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e«      Z* G d„ dejV                  «      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e"«      Z; ejx                  «       Z=i Z>e?e@e   e;f   eAd<    G d„ de"«      ZBi ZCe?e@e   eBf   eAd<   i ZDe?e6e@e   f   eAd<   	 ejŠ                  j�                  d«      ZGddlHmIZI  eIeG«       eId«      k  rdxZJZKnd xZJZK	 d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+„ZOd#e@e   d*dfd,„ZP eQ«       ZReQe@   eAd-<   d#e@e   d*dfd.„ZSd#e@e   d*eTfd/„ZU ej¬                  d ¬0«       G d1„ d2«      «       ZWd3dd*eTfd4„ZXd3dd*efd5„ZYd#e@e   d&e6d*dfd6„ZZ e!d7e[¬8«      	 	 dÃddddd"œd#e@e   d$e1d%e2d9ee7   d:ee8   d&ee6   d'ee4   d(ee5   d)ee:   d*dfd;„«       Z\d#e@e   d*dfd<„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d=„Z^ ej¬                  d ¬0«       G d>„ d?ee$   «      «       Z_ ed@e¬A«      Z` ej¬                  d ¬0«       G dB„ dCee`e$f   «      «       Za ej¬                  d ¬0«       G dD„ dE«      «       ZbdFe/e$df   d*e/e0e$   e-f   fdG„ZcdFe/e$df   d*e/e0e/e*e$f      e-f   fdH„ZddIee$   dJe-d*e/e$df   fdK„ZedFe0e$   d*e/e0e$   e-f   fdL„ZfdFe0e$   d*e/e0e/e*e$f      e-f   fdM„ZgdIee$   dJe-d*e0e$   fdN„ZhdFe?ee$f   d*e/e0e$   e-f   fdO„ZidFe?ee$f   d*e/e0e/e*e$f      e-f   fdP„ZjdIee$   dJe-d*e?ee$f   fdQ„ZkdFe"d*e/e0e   e-f   fdR„ZldFe"d*e/e0e/e*ef      e-f   fdS„ZmdIee$   dJe-d*e"fdT„ZndJe-d*e3fdU„ZodVe3d*e-fdW„ZpdFeee$f   d*e/e0e$   e-f   fdX„ZqdFeee$f   d*e/e0e/e*e$f      e-f   fdY„ZrdIee$   dJe-d*eee$f   fdZ„ZseqZtesZudFeee$f   d*e/e0e$   e-f   fd[„ZvdFeee$f   d*e/e0e/e*e$f      e-f   fd\„ZwdIee$   dJe-d*eee$f   fd]„ZxdJe-d*e3fd^„ZydVe3d*e-fd_„ZzdFee$   d*e/e0e$   e-f   fd`„Z{dFee$   d*e/e0e/e*e$f      e-f   fda„Z|dIee$   dJe-d*ee$   fdb„Z} e^e/eceedced¬d«        e^e0efehdeeg¬d«        e^e?eiekdfej¬d«        e^eelendgeoepem¬"«        e^eeqesdher¬d«        e^eevexdieyezew¬"«        e^ee{e}dje|¬d«        e~e?eeh«      Ze~e@   eAdk<    e~e/e0e?eeeeh«      Z€e~e@   eAdl<   dmed*eTfdn„Z�dmed*efdo„Z‚dÄdme.dpeee.geTf      d*eTfdq„Zƒ ej¬                  d d d d¬r«       G ds„ d«      «       Z„ ej¬                  d d dd¬r«       G dt„ due„«      «       Z… e…«       Z†	 dÄdme.dpeee.geTf      d*e/e0e   e„f   fdv„Z‡dwee   dxe„d*e.fdy„Zˆ	 dÄdme.dpeee.geTf      d*ee   fdz„Z‰	 dÄdme.dpeee.geTf      d*e0e   fd{„ZŠ	 dÄdme.dpeee.geTf      d*e„fd|„Z‹dd}œd~edef   dme.de.dpeee.geTf      d*e.f
d€„ZŒdd}œd~edef   dme.de.dpeee.geTf      d*e.f
d�„Z�e/e@e$   e@e%   f   ZŽe/e@e$   e@e%   e@e&   f   Z�e�j                   d‚k\  ree@e   e/e@e   df   e�j"                  f   Z’nee@e   e/e@e   df   f   Z’eee$e%f   ge'f   Z“eee$e%e&f   ge'f   Z”ee$ge'f   Z•eege'f   Z–ee$geegef   f   Z—edƒe@e$   d*e—e•e$ef      fd„„«       Z˜edƒeŽe$e%f   d*e—e“e$e%ef      fd…„«       Z˜edƒe�e$e%e&f   d*e—e”e$e%e&ef      fd†„«       Z˜edƒe’d*e—e–e      fd‡„«       Z˜edƒeegeTf   d*e—e–e      fdˆ„«       Z˜dƒee’eegeTf   f   d*e—e–e      fd‰„Z˜e	 dÄd~e•e$ef   dme.dpeee.geTf      dƒe@e$   d*e.f
dŠ„«       Z™e	 dÄd~e“e$e%ef   dme.dpeee.geTf      dƒeŽe$e%f   d*e.f
d‹„«       Z™e	 dÄd~e”e$e%e&ef   dme.dpeee.geTf      dƒe�e$e%e&f   d*e.f
dŒ„«       Z™e	 dÄd~e–e   dme.dpeee.geTf      dƒe’d*e.f
d�„«       Z™e	 dÄd~e–e   dme.dpeee.geTf      dƒeegeTf   d*e.f
dŽ„«       Z™	 dÄd~e–e   dme.dpeee.geTf      dƒee’eegeTf   f   d*e.f
d�„Z™e	 dÄd~e•e$ef   dme.dpeee.geTf      dƒe@e$   d*e.f
d�„«       Zše	 dÄd~e“e$e%ef   dme.dpeee.geTf      dƒeŽe$e%f   d*e.f
d‘„«       Zše	 dÄd~e”e$e%e&ef   dme.dpeee.geTf      dƒe�e$e%e&f   d*e.f
d’„«       Zše	 dÄd~e–e   dme.dpeee.geTf      dƒe’d*e.f
d“„«       Zše	 dÄd~e–e   dme.dpeee.geTf      dƒeegeTf   d*e.f
d”„«       Zš	 dÄd~e–e   dme.dpeee.geTf      dƒee’eegeTf   f   d*e.f
d•„Zš	 dÄd–eegeTf   dme.dpeee.geTf      d*eTfd—„Z›	 dÄd–eegeTf   dme.dpeee.geTf      d*eTfd˜„Zœe	 dÄd–e•e$eTf   dme.dpeee.geTf      d™e@e$   d*eTf
dš„«       Z�e	 dÄd–e“e$e%eTf   dme.dpeee.geTf      d™eŽe$e%f   d*eTf
d›„«       Z�e	 dÄd–e”e$e%e&eTf   dme.dpeee.geTf      d™e�e$e%e&f   d*eTf
dœ„«       Z�	 dÄd–e–eT   dme.dpeee.geTf      d™e’d*eTf
d�„Z�e	 dÄd–e•e$eTf   dme.dpeee.geTf      d™e@e$   d*eTf
dž„«       Zže	 dÄd–e“e$e%eTf   dme.dpeee.geTf      d™eŽe$e%f   d*eTf
dŸ„«       Zže	 dÄd–e”e$e%e&eTf   dme.dpeee.geTf      d™e�e$e%e&f   d*eTf
d „«       Zž	 dÄd–e–eT   dme.dpeee.geTf      d™e’d*eTf
d¡„Zž	 dÄdme.dxe„dpeee.geTf      d*ee0e      fd¢„ZŸej¬                   G d£„ d¤«      «       Z  G d¥„ d¦e"«      Z¡i Z¢e?e£e¡f   eAd§<   dxe„d*e fd¨„Z¤d©e3d*e„fdª„Z¥ e¡e¤e¥«      e¢d<   dÄdxe„d«ee£   d*e6fd¬„Z¦e�jN                  d­e6d*e„fd®„«       Z¨ G d¯„ d°«      Z©dxe„d*e6fd±„Zª e!d²e[¬8«      dxe„d*e6fd³„«       Z« e!d´e[¬8«      dµe6d*e„fd¶„«       Z¬d·e.d¸e.d*e0e   fd¹„Z­	 dÄdme.dpeee.geTf      d*e/e0e/e9ef      e„f   fdº„Z®	 dÄdme.dpeee.geTf      d*e0e/e9ef      fd»„Z¯	 dÄd¼e9dme.dpeee.geTf      d*ee/e9ef      fd½„Z°dd}œd~edef   dme.de.dpeee.geTf      d*e.f
d¾„Z±d¿e9d*e6fdÀ„Z²dÁed¿e9d*efdÂ„Z³y# ejŠ                  j˜                  $ r dxZJZKY �
Œòw xY w)Å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                   óD   — e Zd Zdefd„Zdedefd„Zdefd„Z	de
de
fd„Zy)	ÚKeyEntryÚreturnc                  ó   — y ©N© ©Úselfs    úQ/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/torch/utils/_pytree.pyÚ__hash__zKeyEntry.__hash__Z   ó   € Øó    Úotherc                  ó   — y r@   rA   ©rC   rH   s     rD   Ú__eq__zKeyEntry.__eq__]   rF   rG   c                  ó   — y r@   rA   rB   s    rD   Ú__str__zKeyEntry.__str__`   rF   rG   Úparentc                  ó   — y r@   rA   )rC   rN   s     rD   ÚgetzKeyEntry.getc   rF   rG   N)Ú__name__Ú
__module__Ú__qualname__ÚintrE   ÚobjectÚboolrK   ÚstrrM   r   rP   rA   rG   rD   r=   r=   Y   s@   „ ð˜#ó ð˜Fð  tó ð˜ó ð˜#ð  #ô rG   r=   c                   ó(   ‡ — e Zd Zdedefˆ fd„Zˆ xZS )ÚEnumEncoderÚobjr>   c                 óZ   •— t        |t        «      r|j                  S t        ‰| �  |«      S r@   )Ú
isinstancer   ÚvalueÚsuperÚdefault)rC   rZ   Ú	__class__s     €rD   r_   zEnumEncoder.defaulth   s&   ø€ Ü�cœ4Ô Ø—9‘9ÐÜ‰w‰˜sÓ#Ð#rG   )rQ   rR   rS   rU   rW   r_   Ú__classcell__)r`   s   @rD   rY   rY   g   s   ø„ ð$˜6ð $ c÷ $ñ $rG   rY   r   .c                   óB   — e Zd ZU ee   ed<   eed<   eed<   ee	   ed<   y)ÚNodeDefÚtypeÚ
flatten_fnÚunflatten_fnÚflatten_with_keys_fnN)
rQ   rR   rS   rd   r   Ú__annotations__r   r   r   ÚFlattenWithKeysFuncrA   rG   rD   rc   rc   „   s#   … Ø
ˆs‰)ƒOØÓØÓØ"Ð#6Ñ7Ô7rG   rc   ÚSUPPORTED_NODESc                   óH   — e Zd ZU ee   ed<   eed<   ee   ed<   ee	   ed<   y)Ú_SerializeNodeDefÚtypÚserialized_type_nameÚto_dumpable_contextÚfrom_dumpable_contextN)
rQ   rR   rS   rd   r   rh   rW   r   r   r   rA   rG   rD   rl   rl   –   s)   … Ø	ˆc‰ƒNØÓØ!Ð"5Ñ6Ó6Ø#Ð$9Ñ:Ô:rG   rl   ÚSUPPORTED_SERIALIZED_TYPESÚSERIALIZED_TYPE_TO_PYTHON_TYPEÚoptree)ÚVersionz0.13.0FTÚ_cxx_pytree_pending_imports©rn   ro   rp   rg   Úclsre   rf   rn   ro   rp   rg   r>   c          	      ó&  — t         5  | t        v rt        | › d�«      ‚	 ddd«       t        | ||||||¬«       t        syt
        rddlm} |j                  | |||||¬«       y| ||f}|||dœ}	t        j                  ||	f«       y# 1 sw Y   ŒixY w)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.Nrv   r:   )Ú_cxx_pytree)rn   ro   rp   )
Ú_NODE_REGISTRY_LOCKrj   Ú
ValueErrorÚ_private_register_pytree_nodeÚ_cxx_pytree_existsÚ_cxx_pytree_importedÚ ry   ru   Úappend)
rw   re   rf   rn   ro   rp   rg   ÚcxxÚargsÚkwargss
             rD   r"   r"   ¹   sÆ   € ôD 
ñ MØ”/Ñ!Ü ˜uÐ$JÐKÓLÐLð "÷Mô "ØØØØ1Ø/Ø3Ø1õõ ØåÝ(à×)Ñ)ØØØØ!5Ø 3Ø"7ð 	*õ 	
ð �Z Ð.ˆà$8Ø#6Ø%:ñ
ˆô
 	$×*Ñ*¨D°&¨>Õ:÷GMð Mús   ‡BÂBc                 óB   — ddl }|j                  j                  | «       y)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)rw   Útorchs     rD   r‡   r‡     s   € ó8 ð 
‡L�L×#Ñ# CÕ(rG   ÚCONSTANT_NODESc                 ó  — | j                   t        j                   u rt        d«      ‚| j                  €t        d«      ‚d„ }d„ }d„ }t        5  t        | |||¬«       t        j                  | «       ddd«       y# 1 sw Y   yxY w)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                 ó   — g t        | «      fS r@   ©ÚConstantNode©Úxs    rD   Ú_flattenz#register_constant.<locals>._flattenb  ó   € Ø”< “?Ð"Ð"rG   c                 ó   — |j                   S r@   )r]   )Ú_Úcontexts     rD   Ú
_unflattenz%register_constant.<locals>._unflattene  s   € Ø�}‰}ÐrG   c                 ó   — g t        | «      fS r@   rŒ   rŽ   s    rD   Ú_flatten_with_keysz-register_constant.<locals>._flatten_with_keysh  r‘   rG   )rg   )rK   rU   Ú	TypeErrorrE   rz   r|   r‰   Úadd)rw   r�   r•   r—   s       rD   Úregister_constantrš   '  sŽ   € ð^ ‡z�z”V—]‘]Ñ"ÜØaó
ð 	
ð ‡|�|ÐÜØcó
ð 	
ò#òò#ô 
ñ  Ü%ØØØØ!3õ		
ô 	×Ñ˜3Ô÷ ÷  ñ  ús   Á%A<Á<Bc                 ó6   — t        | t        «      xr | t        v S r@   )r\   rd   r‰   ©rw   s    rD   Úis_constant_classr�   u  s   € Ü�cœ4Ó Ò: S¬NÐ%:Ð:rG   )Úfrozenc                   ó   — e Zd ZU eed<   y)r�   r]   N)rQ   rR   rS   r   rh   rA   rG   rD   r�   r�   y  s   … à„JrG   r�   Úspecc                 ó6   — t        | j                  t        «      S )zEChecks if the spec is from a pytree registered with register_constant)r\   r”   r�   ©r    s    rD   Ú_is_constant_holderr£   ~  s   € ä�d—l‘l¤LÓ1Ð1rG   c                 ó4   — t        | «      sJ ‚t        g | «      S )zTGiven a spec from a pytree registered with register_constant, retrieves the constant)r£   r%   r¢   s    rD   Ú_retrieve_constantr¥   ƒ  s   € ä˜tÔ$Ð$Ð$Ü˜"˜dÓ#Ð#rG   c          	      óP   — t        | t        t        |t        t        t
        ¬«       y)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.
    rv   N)r|   Ú_namedtuple_flattenÚ_namedtuple_unflattenÚ_namedtuple_serializeÚ_namedtuple_deserializeÚ_namedtuple_flatten_with_keys)rw   rn   s     rD   Ú_register_namedtupler¬   ‰  s!   € ô" "ØÜÜØ1Ü1Ü5Ü:örG   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          	      óh   — |€|�t        j                  dt        d¬«       t        | ||||||¬«       y)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.é   )Ú
stacklevelrv   )ÚwarningsÚwarnÚFutureWarningr|   )	rw   re   rf   r®   r¯   rn   ro   rp   rg   s	            rD   Ú_register_pytree_noder¶   ¥  sH   € ðR ÐÐ 1Ð =Ü�‰ðTäØõ		
ô "ØØØØ1Ø/Ø3Ø1örG   c                 ó´   — t         5  t        | = t        |    }t        |j                  = t        | = t
        j                  | «       ddd«       y# 1 sw Y   yxY w)z˜This 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)rz   rj   rq   rr   rn   r‰   Údiscard)rw   Únode_defs     rD   Ú_deregister_pytree_noderº   á  sR   € ô 
ñ $Ü˜CÐ Ü-¨cÑ2ˆÜ*¨8×+HÑ+HÐIÜ& sÐ+Ü×Ñ˜sÔ#÷$÷ $ñ $ús   ‡>AÁAc                ó(  — t         5  | t        v rt        j                  | › d�«       t	        | |||«      }|t        | <   |du |du z  rt        d| › d�«      ‚|€t        }t        | |||«      }|t        | <   | t        |<   ddd«       y# 1 sw Y   yxY w)z¬This 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.)
rz   rj   r³   r´   rc   r{   r;   rl   rq   rr   )	rw   re   rf   rn   ro   rp   rg   r¹   Úserialize_node_defs	            rD   r|   r|   ï  sÐ   € ô 
ñ CØ”/Ñ!ä�M‰MØ�%ð 9ð 9ôô
 ˜3 
¨LÐ:NÓOˆØ'Œ˜Ñà 4Ð'Ð,AÀTÐ,IÒJÜØIÈ#Èð O)ð )óð ð
  Ð'Ü#@Ð ä.ØØ ØØ!ó	
Ðð +=Ô" 3Ñ'Ø?BÔ&Ð';Ñ<÷7C÷ Cñ Cús   ‡A8BÂBc                   ó:   — e Zd ZU eed<   defd„Zdee   defd„Z	y)ÚSequenceKeyÚidxr>   c                 ó"   — d| j                   ›d�S ©Nú[ú]©r¿   rB   s    rD   rM   zSequenceKey.__str__  ó   € Ø�4—8‘8�,˜aÐ Ð rG   Úsequencec                 ó    — || j                      S r@   rÄ   )rC   rÆ   s     rD   rP   zSequenceKey.get"  s   € Ø˜Ÿ™Ñ!Ð!rG   N)
rQ   rR   rS   rT   rh   rW   rM   r
   r6   rP   rA   rG   rD   r¾   r¾     s*   … à	ƒHð!˜ó !ð"˜H Q™Kð "¨Aô "rG   r¾   ÚK)Úboundc                   ó>   — e Zd ZU eed<   defd„Zdeeef   defd„Z	y)Ú
MappingKeyÚkeyr>   c                 ó"   — d| j                   ›d�S rÁ   ©rÌ   rB   s    rD   rM   zMappingKey.__str__-  rÅ   rG   Úmappingc                 ó    — || j                      S r@   rÎ   )rC   rÏ   s     rD   rP   zMappingKey.get0  s   € Ø�t—x‘xÑ Ð rG   N)
rQ   rR   rS   rÈ   rh   rW   rM   r	   r6   rP   rA   rG   rD   rË   rË   )  s.   … à	
ƒFð!˜ó !ð!˜7 1 a 4™=ð !¨Qô !rG   rË   c                   ó4   — e Zd ZU eed<   defd„Zdedefd„Zy)Ú
GetAttrKeyÚnamer>   c                 ó    — d| j                   › �S )Nú.)rÓ   rB   s    rD   rM   zGetAttrKey.__str__8  s   € Ø�4—9‘9�+ˆÐrG   rZ   c                 ó.   — t        || j                  «      S r@   )ÚgetattrrÓ   )rC   rZ   s     rD   rP   zGetAttrKey.get;  s   € Ü�s˜DŸI™IÓ&Ð&rG   N)rQ   rR   rS   rW   rh   rM   r   rP   rA   rG   rD   rÒ   rÒ   4  s&   … à
ƒIð˜ó ð'�sð '˜sô 'rG   rÒ   Údc                 ó   — t        | «      d fS r@   ©Úlist©rØ   s    rD   Ú_tuple_flattenrÝ   ?  s   € Ü�‹7�Dˆ=ÐrG   c                 ó€   — t        | «      \  }}t        |«      D ��cg c]  \  }}t        |«      |f‘Œ c}}|fS c c}}w r@   )rÝ   Ú	enumerater¾   ©rØ   Úvaluesr”   ÚiÚvs        rD   Ú_tuple_flatten_with_keysrä   C  ó=   € ô % QÓ'�O€FˆGÜ,5°fÓ,=×>¡D A qŒ[˜‹^˜QÒÓ>ÀÐGÐGùÓ>ó   �:rá   r”   c                 ó   — t        | «      S r@   )Útuple©rá   r”   s     rD   Ú_tuple_unflattenrê   J  s   € Ü�‹=ÐrG   c                 ó
   — | d fS r@   rA   rÜ   s    rD   Ú_list_flattenrì   N  s   € Øˆdˆ7€NrG   c                 ó€   — t        | «      \  }}t        |«      D ��cg c]  \  }}t        |«      |f‘Œ c}}|fS c c}}w r@   )rì   rß   r¾   rà   s        rD   Ú_list_flatten_with_keysrî   R  s;   € Ü# AÓ&�O€FˆGÜ,5°fÓ,=×>¡D A qŒ[˜‹^˜QÒÓ>ÀÐGÐGùÓ>ræ   c                 ó   — t        | «      S r@   rÚ   ré   s     rD   Ú_list_unflattenrð   W  s   € Ü�‹<ÐrG   c                 óf   — t        | j                  «       «      t        | j                  «       «      fS r@   ©rÛ   rá   ÚkeysrÜ   s    rD   Ú_dict_flattenrô   [  ó"   € Ü�—‘“
ÓœT !§&¡&£(›^Ð+Ð+rG   c                 ó‚   — t        | «      \  }}t        ||«      D ��cg c]  \  }}t        |«      |f‘Œ c}}|fS c c}}w r@   )rô   ÚziprË   ©rØ   rá   r”   Úkrã   s        rD   Ú_dict_flatten_with_keysrú   _  s?   € ô $ AÓ&�O€FˆGÜ+.¨w¸Ó+?×@¡4 1 aŒZ˜‹]˜AÒÓ@À'ÐIÐIùÓ@ó   ž;c                 ó,   — t        t        || «      «      S r@   )Údictr÷   ré   s     rD   Ú_dict_unflattenrþ   f  s   € Ü”�G˜VÓ$Ó%Ð%rG   c                 ó.   — t        | «      t        | «      fS r@   )rÛ   rd   rÜ   s    rD   r§   r§   j  s   € Ü�‹7”D˜“GÐÐrG   c                 ó–   — t        | «      \  }}t        |j                  |«      D ��cg c]  \  }}t        |«      |f‘Œ c}}|fS c c}}w r@   )r§   r÷   Ú_fieldsrÒ   )rØ   rá   r”   Úfieldrã   s        rD   r«   r«   n  sI   € ô *¨!Ó,�O€FˆGä03°G·O±OÀVÓ0L×M¡H E¨1Œ*�UÓ
˜QÒ	ÓMØðð ùÛMs   ¨Ac                 ó(   — t        t         || Ž «      S r@   )r   r   ré   s     rD   r¨   r¨   x  s   € Ü”
™G VÐ,Ó-Ð-rG   c                 óŽ   — | 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`.)rq   ÚNotImplementedErrorrn   r;   )r”   r¼   rn   s      rD   r©   r©   |  ss   € ØÔ0Ñ0Ü!Ø;¸G¸9ð E&ð &ó
ð 	
ô 4°GÑ<ÐØ-×BÑBÐàÔ<Ò<Ü!Ø;¸G¸9ð E&ð &ó
ð 	
ð
  ÐrG   Údumpable_contextc                 óF   — | 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.)rr   r  )r  rm   s     rD   rª   rª   �  s>   € ØÔ=Ñ=Ü!Ø=Ð>NÐ=Oð P<ð <ó
ð 	
ô
 )Ð)9Ñ
:€CØ€JrG   c                 óf   — t        | j                  «       «      t        | j                  «       «      fS r@   rò   rÜ   s    rD   Ú_ordereddict_flattenr	  ›  rõ   rG   c                 ó‚   — t        | «      \  }}t        ||«      D ��cg c]  \  }}t        |«      |f‘Œ c}}|fS c c}}w r@   )r	  r÷   rË   rø   s        rD   Ú_ordereddict_flatten_with_keysr  Ÿ  s?   € ô +¨1Ó-�O€FˆGÜ+.¨w¸Ó+?×@¡4 1 aŒZ˜‹]˜AÒÓ@À'ÐIÐIùÓ@rû   c                 ó:   — t        d„ t        || «      D «       «      S )Nc              3   ó*   K  — | ]  \  }}||f–— Œ y ­wr@   rA   )Ú.0rÌ   r]   s      rD   ú	<genexpr>z)_ordereddict_unflatten.<locals>.<genexpr>ª  s   è ø€ ÒK©
¨¨U˜˜U”|ÑKùs   ‚)r   r÷   ré   s     rD   Ú_ordereddict_unflattenr  ¦  s   € ô ÑK´c¸'À6Ó6JÔKÓKÐKrG   c                 ó>   — t        | «      \  }}|| j                  |gfS r@   )rô   Údefault_factory)rØ   rá   Údict_contexts      rD   Ú_defaultdict_flattenr  ±  s'   € Ü(¨Ó+Ñ€FˆLØ�A×%Ñ% |Ð4Ð4Ð4rG   c                 óŒ   — t        | «      \  }}|\  }}t        ||«      D ��cg c]  \  }}t        |«      |f‘Œ c}}|fS c c}}w r@   )r  r÷   rË   )rØ   rá   r”   r“   r  rù   rã   s          rD   Ú_defaultdict_flatten_with_keysr  ¶  sH   € ô +¨1Ó-�O€FˆGØ�O€A€|Ü+.¨|¸VÓ+D×E¡4 1 aŒZ˜‹]˜AÒÓEÀwÐNÐNùÓEs   £A c                 ó8   — |\  }}t        |t        | |«      «      S r@   )r   rþ   )rá   r”   r  r  s       rD   Ú_defaultdict_unflattenr  ¾  s"   € ð %,Ñ!€O�\Ü�¬¸ÀÓ(MÓNÐNrG   c                 óD   — | \  }}|j                   |j                  |dœ}|S )N)Údefault_factory_moduleÚdefault_factory_namer  )rR   rS   )r”   r  r  Újson_defaultdicts       rD   Ú_defaultdict_serializer  Æ  s1   € Ø$+Ñ!€O�\à"1×"<Ñ"<Ø /× <Ñ <Ø$ñÐð
 ÐrG   c                 óú   — t        | t        «      sJ ‚t        | «      h d£k(  sJ ‚| d   }| d   }t        |t        «      sJ ‚t        |t        «      sJ ‚t	        j
                  |«      }t        ||«      }| d   }||gS )N>   r  r  r  r  r  r  )r\   rý   ÚsetrW   Ú	importlibÚimport_moduler×   )r  r  r  Úmoduler  r  s         rD   Ú_defaultdict_deserializer#  Ð  sŸ   € ÜÐ&¬Ô-Ð-Ð-ÜÐÓ ò %ò ð ð ð .Ð.FÑGÐØ+Ð,BÑCÐÜÐ,¬cÔ2Ð2Ð2ÜÐ*¬CÔ0Ð0Ð0Ü×$Ñ$Ð%;Ó<€FÜ˜fÐ&:Ó;€Oà# NÑ3€LØ˜\Ð*Ð*rG   c                 ó0   — t        | «      | j                  fS r@   )rÛ   ÚmaxlenrÜ   s    rD   Ú_deque_flattenr&  ã  s   € Ü�‹7�A—H‘HÐÐrG   c                 ó€   — t        | «      \  }}t        |«      D ��cg c]  \  }}t        |«      |f‘Œ c}}|fS c c}}w r@   )r&  rß   r¾   rà   s        rD   Ú_deque_flatten_with_keysr(  ç  rå   ræ   c                 ó   — t        | |¬«      S )N©r%  )r   ré   s     rD   Ú_deque_unflattenr+  î  s   € Ü� Ô(Ð(rG   zbuiltins.tuple)rn   rg   zbuiltins.listzbuiltins.dictzcollections.namedtuplezcollections.OrderedDictzcollections.defaultdictzcollections.dequeÚSTANDARD_DICT_TYPESÚBUILTIN_TYPESÚtreec                 óÆ   — t        | «      }|j                  }t        |«      dk7  s|d   t        k7  ryt	        |dd «      }t        |t        «      syt        d„ |D «       «      S )Nr:   r   Fr  c              3   ó@   K  — | ]  }t        |«      t        k(  –— Œ y ­wr@   )rd   rW   )r  Úentrys     rD   r  z*_is_namedtuple_instance.<locals>.<genexpr>:  s   è ø€ Ò6 eŒt�E‹{œcÕ!Ñ6ùs   ‚)rd   Ú	__bases__Úlenrè   r×   r\   Úall)r.  rm   ÚbasesÚfieldss       rD   Ú_is_namedtuple_instancer7  2  sY   € Ü
ˆt‹*€CØ�M‰M€EÜ
ˆ5ƒz�Q‚˜% ™(¤eÒ+ØÜ�S˜) TÓ*€FÜ�fœeÔ$ØÜÑ6¨vÔ6Ó6Ð6rG   c                 ó:   — t        | «      rt        S t        | «      S r@   )r7  r   rd   )r.  s    rD   Ú_get_node_typer9  =  s   € Ü˜tÔ$ÜÐÜ�‹:ÐrG   Úis_leafc                 óD   — |d uxr  || «      xs t        | «      t        vS r@   )r9  rj   ©r.  r:  s     rD   Ú_is_leafr=  D  s/   € Ø˜4ÐÒ1¡G¨D£Mò ´nØó7äð7ð rG   )Úinitrž   ÚeqÚreprc                   ó$  — e Zd ZU eed<   eed<   ed    ed<    ej                  d¬«      Z	e
ed<    ej                  d¬«      Ze
ed<    ej                  d¬«      Ze
ed<   dd„Zdde
d	efd„Zded	efd„Zd	efd„Zded	ee   fd„Zdee   d	efd„Zy
)r   rd   r”   Úchildren_specsF)r>  Ú	num_nodesÚ
num_leavesÚnum_childrenr>   Nc                 ó,  — t        d„ | j                  D «       d¬«      }t        d„ | j                  D «       «      }t        | j                  «      }t        j	                  | d|«       t        j	                  | d|«       t        j	                  | d|«       y )Nc              3   ó4   K  — | ]  }|j                   –— Œ y ­wr@   )rC  ©r  r    s     rD   r  z)TreeSpec.__post_init__.<locals>.<genexpr>Z  s   è ø€ ÒH¨D˜Ÿ�ÑHùó   ‚r:   )Ústartc              3   ó4   K  — | ]  }|j                   –— Œ y ­wr@   )rD  rH  s     rD   r  z)TreeSpec.__post_init__.<locals>.<genexpr>[  s   è ø€ ÒI¨T˜Ÿ�ÑIùrI  rC  rD  rE  )ÚsumrB  r3  rU   Ú__setattr__)rC   rC  rD  rE  s       rD   Ú__post_init__zTreeSpec.__post_init__Y  sw   € ÜÑH°D×4GÑ4GÔHÐPQÔRˆ	ÜÑI°T×5HÑ5HÔIÓIˆ
Ü˜4×.Ñ.Ó/ˆÜ×Ñ˜4 ¨iÔ8Ü×Ñ˜4 ¨zÔ:Ü×Ñ˜4 °Õ>rG   Úindentc           
      ó–  — d| j                   j                  › d| j                  › d�}d}| j                  dkD  rƒ|dz  }|| j                  d   j                  |«      z  }|| j                  dkD  rdndz  }|dj                  | j                  dd  D �cg c]  }d	d
|z  z   |j                  |«      z   ‘Œ c}«      z  }|› d�}||z   S c c}w )Nz	TreeSpec(z, z, [r   r   r±   r:   ú,ú
ú z]))rd   rQ   r”   rE  rB  Ú__repr__Újoin)rC   rO  Úrepr_prefixÚchildren_specs_strÚchildÚrepr_suffixs         rD   rT  zTreeSpec.__repr__a  sî   € Ø& t§y¡y×'9Ñ'9Ð&:¸"¸T¿\¹\¸NÈ#ÐNˆØ"$ÐØ×Ñ˜qÒ Ø�a‰KˆFØ $×"5Ñ"5°aÑ"8×"AÑ"AÀ&Ó"IÑIÐØ¨×):Ñ):¸QÒ)>¡#ÀBÑFÐØ #§(¡(ð "&×!4Ñ!4°Q°RÐ!8öàð ˜3 ™<Ñ'¨%¯.©.¸Ó*@Ó@òó#ñ Ðð 1Ð1°Ð4ˆØ˜[Ñ(Ð(ùòs   Â!C
rH   c                 ó
  — | |u ry|j                   | j                   u rat        | j                  «      t        |j                  «      k7  ry| j                  |j                  k7  ry| j                  |j                  k7  ryyt
        S )NTF)r`   rW   rd   r”   rB  ÚNotImplementedrJ   s     rD   rK   zTreeSpec.__eq__q  sj   € Ø�5‰=ØØ�_‰_ §¡Ñ.Ü�4—9‘9‹~¤ U§Z¡Z£Ò0ØØ�|‰|˜uŸ}™}Ò,ØØ×$Ñ$¨×(<Ñ(<Ò<ØØÜÐrG   c                 óB   — | j                   dk(  xr | j                  dk(  S )Nr:   )rC  rD  rB   s    rD   r:  zTreeSpec.is_leaf~  s   € Ø�~‰~ Ñ"Ò; t§¡¸!Ñ';Ð;rG   r.  c                 ób   ‡— dt         dt        dt        t           dd fˆfd„Šg } ‰| ||«       |S )NÚtreespecr.  Úsubtreesr>   c           	      óP  •— | j                  «       r|j                  |«       y t        |«      }| j                  t        vr¯|| j                  k7  rt        d| j                  ›d|›d�«      ‚t        |   j                  } ||«      \  }}t        |«      | j                  k7  r%t        d| j                  › dt        |«      › d�«      ‚|| j                  k7  �r£t        d| j                  ›d�«      ‚| j                  t        v xr |t        v }|s+|| j                  k7  rt        d| j                  ›d|›d�«      ‚t        |«      | j                  k7  r%t        d| j                  › dt        |«      › d�«      ‚|r¤| j                  t        ur| j                  n| j                  d   }|}	t        |«      }
t        |	«      }|
|k7  rG|j                  |
«      }|
j                  |«      }d}|r|d	|› �z  }|r|d
|› �z  }t        d|› d�«      ‚|	D �cg c]  }||   ‘Œ	 }}n^t        |   j                  } ||«      \  }}|t        ur8|| j                  k7  r)t        d| j                  ›d| j                  ›d|›d�«      ‚t!        || j"                  «      D ]  \  }} ‰|||«       Œ y c c}w )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 r:   r   z; missing key(s): z; extra key(s): zNode keys mismatchz$Node context mismatch for node type z; expected )r:  r€   r9  rd   r-  r{   rj   re   r3  rE  r”   r,  r   r  Ú
differencer   r÷   rB  )r^  r.  r_  Ú	node_typere   Úchildrenr”   Úboth_standard_dictr  Úexpected_keysÚgot_key_setÚexpected_key_setÚmissing_keysÚ
extra_keysÚmessagerÌ   ÚsubtreeÚsubspecÚhelpers                     €rD   rm  z&TreeSpec.flatten_up_to.<locals>.helper‚  s  ø€ Ø×ÑÔ!Ø—‘ Ô%Øä& tÓ,ˆIØ�}‰}¤MÑ1à §¡Ò-Ü$ð$Ø$,§M¡MÐ#4°J¸y¸mÈ1ðNóð ô -¨YÑ7×BÑB�
Ù$.¨tÓ$4Ñ!�˜'Ü�x“= H×$9Ñ$9Ò9Ü$ð$Ø$,×$9Ñ$9Ð#:¸*ÄSÈÃ]ÀOÐSTðVóð ð ˜h×.Ñ.Ó.Ü$ØEÀhÇmÁmÐEVÐVWÐXóð ð —M‘MÔ%8Ð8ò 9Ø!Ô%8Ð8ð #ñ *¨i¸8¿=¹=Ò.HÜ$ð$Ø$,§M¡MÐ#4°J¸y¸mÈ1ðNóð ô �t“9 × 5Ñ 5Ò5Ü$ð$Ø$,×$9Ñ$9Ð#:¸*ÄSÈÃYÀKÈqðRóð ñ
 &ð $Ÿ=™=´Ñ;ð !×(Ò(ð &×-Ñ-¨aÑ0ð	 !ð %1�MÜ"% d£)�KÜ'*¨=Ó'9Ð$Ø"Ð&6Ò6Ø'7×'BÑ'BÀ;Ó'O˜Ø%0×%;Ñ%;Ð<LÓ%M˜
Ø"$˜Ù'Ø#Ð);¸L¸>Ð'JÑJ˜GÙ%Ø#Ð)9¸*¸Ð'FÑF˜GÜ(Ð+=¸g¸YÀaÐ)HÓIÐIØ5BÖC¨c  S£	ÐC�HÑCô "1°Ñ!;×!FÑ!F�JÙ(2°4Ó(8Ñ%�H˜gà!¬Ñ.Ø! X×%5Ñ%5Ò5Ü(ØBÀ8Ç=Á=ÐBSð T(Ø(0×(8Ñ(8Ð';¸:ÀgÀ[ÐPQðSóð ô
 %(¨°(×2IÑ2IÓ$Jò 3Ñ �˜Ù�w ¨Õ2ñ3ùò  Ds   ÈJ#)r   r   rÛ   )rC   r.  r_  rm  s      @rD   Úflatten_up_tozTreeSpec.flatten_up_to�  sG   ø€ ðL	3œXð L	3¬Vð L	3¼tÄF¹|ð L	3ÐPTõ L	3ð\ "$ˆÙˆt�T˜8Ô$ØˆrG   Úleavesc           	      óä  — t        |t        t        f«      st        |«      }t        |«      | j                  k7  r(t        dt        |«      › d| j                  › d| › d�«      ‚| j                  «       r|d   S t        | j                     j                  }d}d}g }| j                  D ]6  }||j                  z  }|j                  |j                  ||| «      «       |}Œ8  ||| j                  «      S )Nz0treespec.unflatten(leaves): `leaves` has length z, but the spec refers to a pytree that holds z items (z).r   )r\   rÛ   rè   r3  rD  r{   r:  rj   rd   rf   rB  r€   Ú	unflattenr”   )rC   ro  rf   rJ  ÚendÚchild_pytreesÚ
child_specs          rD   rq  zTreeSpec.unflattenÔ  sú   € Ü˜&¤4¬ -Ô0Ü˜&“\ˆFÜˆv‹;˜$Ÿ/™/Ò)ÜØBÄ3ÀvÃ;À-ð P>Ø>B¿o¹oÐ=Nð OØ˜˜rð#óð ð
 �<‰<Œ>Ø˜!‘9Ðä& t§y¡yÑ1×>Ñ>ˆð ˆØˆØˆØ×-Ñ-ò 	ˆJØ�:×(Ñ(Ñ(ˆCØ× Ñ  ×!5Ñ!5°f¸UÀ3Ð6GÓ!HÔIØ‰Eð	ñ
 ˜M¨4¯<©<Ó8Ð8rG   ©r>   N©r   )rQ   rR   rS   r   rh   r   rÛ   Údataclassesr  rC  rT   rD  rE  rN  rW   rT  r   rV   rK   r:  rn  r   rq  rA   rG   rD   r   r   O  sÆ   … à
ƒIØÓØ˜Ñ$Ó$à&�[×&Ñ&¨EÔ2€IˆsÓ2Ø'�k×'Ñ'¨UÔ3€J�Ó3Ø)˜×)Ñ)¨uÔ5€L�#Ó5ó?ñ)˜sð )¨3ó )ð ˜Fð  tó ð<˜ó <ðQ &ð Q¨T°&©\ó Qðf9 ¨¡ð 9°&ô 9rG   c                   óÄ   — e Zd ZU  ej                  dd¬«      Zeed<    ej                  dd¬«      Ze	ed<    ej                  e
d¬«      Ze
d   ed<   dd
„Zdded	efd„Zy)r   NF)r_   r>  rd   r”   )r  r>  r   rB  r>   c                 óŽ   — t         j                  | dd«       t         j                  | dd«       t         j                  | dd«       y )NrC  r:   rD  rE  r   )rU   rM  rB   s    rD   rN  zLeafSpec.__post_init__ú  s8   € ä×Ñ˜4 ¨aÔ0Ü×Ñ˜4 ¨qÔ1Ü×Ñ˜4 °Õ3rG   rO  c                  ó   — y©NÚ*rA   )rC   rO  s     rD   rT  zLeafSpec.__repr__   ó   € ØrG   ru  rv  )rQ   rR   rS   rw  r  rd   r   rh   r”   r   rÛ   rB  rN  rT   rW   rT  rA   rG   rD   r   r   ò  so   … à!�×!Ñ!¨$°UÔ;€Dˆ#Ó;Ø(�{×(Ñ(°¸EÔB€GˆWÓBØ'8 {×'8Ñ'8Ø 5ô(€N�D˜Ñ$ó ó4ñ˜sð ¨3ô rG   r   c                 ód   ‡‡— dt         dt        t           dt        fˆˆfd„Šg } ‰| |«      }||fS )zkFlattens a pytree into a list of values and a TreeSpec that can be used
    to reconstruct the pytree.
    Únodero  r>   c                 óî   •— t        | ‰	¬«      r|j                  | «       t        S t        | «      }t        |   j
                  } || «      \  }}|D �cg c]  } ‰||«      ‘Œ }}t        |||«      S c c}w ©N©r:  )r=  r€   Ú
_LEAF_SPECr9  rj   re   r   )
r  ro  rb  re   rc  r”   rX  Úsubspecsrm  r:  s
           €€rD   rm  ztree_flatten.<locals>.helper  sz   ø€ Ü�D 'Õ*Ø�M‰M˜$ÔÜÐä" 4Ó(ˆ	Ü$ YÑ/×:Ñ:ˆ
Ù& tÓ,Ñˆ�'ð 8@Ö@¨e‘F˜5 &Õ)Ð@ˆÐ@Ü˜	 7¨HÓ5Ð5ùò As   ÁA2)r   rÛ   r   r   )r.  r:  ro  r^  rm  s    `  @rD   r#   r#   	  s?   ù€ ð6”Vð 6¤T¬#¡Yð 6´8ö 6ð €FÙ�d˜FÓ#€HØ�8ÐÐrG   ro  r^  c                 ót   — t        |t        «      st        dt        |«      › d�«      ‚|j	                  | «      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Õ   )r\   r   r˜   rd   rq  )ro  r^  s     rD   r%   r%   #  sE   € ô �h¤Ô)Üð9Ü9=¸h»Ð8HÈðKó
ð 	
ð ×Ñ˜fÓ%Ð%rG   c              #   ó¾   K  — t        | |¬«      r| –— yt        | «      }t        |   j                  } || «      \  }}|D ]  }t	        ||¬«      E d{  –—†  Œ y7 Œ­w)z,Get an iterator over the leaves of a pytree.r‚  N)r=  r9  rj   re   r&   )r.  r:  rb  re   rs  r“   rX  s          rD   r&   r&   /  sd   è ø€ ô
 �˜gÕ&Ø‹
ä" 4Ó(ˆ	Ü$ YÑ/×:Ñ:ˆ
Ù% dÓ+Ñˆ�qð #ò 	9ˆEÜ  °Ô8×8Ñ8ñ	9Ø8ús   ‚AAÁAÁAc                 ó.   — t        t        | |¬«      «      S )z!Get a list of leaves of a pytree.r‚  )rÛ   r&   r<  s     rD   r'   r'   @  s   € ô
 ”	˜$¨Ô0Ó1Ð1rG   c                 ó"   — t        | |¬«      d   S )zGet the TreeSpec for a pytree.r‚  r:   )r#   r<  s     rD   r)   r)   H  s   € ô
 ˜ gÔ.¨qÑ1Ð1rG   r‚  ÚfuncÚrestsc                ó¨   — t        ||¬«      \  }}|g|D �cg c]  }|j                  |«      ‘Œ c}z   }|j                  t        | g|¢­Ž «      S c c}w )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``.
    r‚  )r#   rn  rq  Úmap©r‰  r.  r:  rŠ  ro  r^  ÚrÚ	flat_argss           rD   r*   r*   P  sY   € ôN $ D°'Ô:Ñ€FˆHØ�¸uÖE¸!˜H×2Ñ2°1Õ5ÒEÑE€IØ×Ñœc $Ð3¨Ò3Ó4Ð4ùò Fs   —Ac                ó¤   — t        ||¬«      \  }}|g|D �cg c]  }|j                  |«      ‘Œ c}z   }t        t        | g|¢­Ž d¬«       |S c c}w )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``.
    r‚  r   r*  )r#   rn  r   rŒ  r�  s           rD   r,   r,   |  sV   € ô8 $ D°'Ô:Ñ€FˆHØ�¸uÖE¸!˜H×2Ñ2°1Õ5ÒEÑE€IÜ	Œ#ˆdÐ
�YÒ
¨Õ*Ø€Kùò Fs   —A©é   é
   Útype_or_types_or_predc                 ó   — y r@   rA   ©r”  s    rD   Úmap_onlyr—  ¯  ó   € àrG   c                 ó   — y r@   rA   r–  s    rD   r—  r—  ´  r˜  rG   c                 ó   — y r@   rA   r–  s    rD   r—  r—  ¹  r˜  rG   c                 ó   — y r@   rA   r–  s    rD   r—  r—  ¿  r˜  rG   c                 ó   — y r@   rA   r–  s    rD   r—  r—  Ä  r˜  rG   c                óD  ‡ ‡— t        ‰ t        t        f«      s-t        j                  dk\  r-t        ‰ t
        j                  «      rdt        dt        fˆ fd„Šnt        ‰ «      r‰ Šnt        d«      ‚dt        t        gt        f   dt        t        gt        f   fˆf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'
    r‘  r�   r>   c                 ó   •— t        | ‰«      S r@   ©r\   )r�   r”  s    €rD   Úpredzmap_only.<locals>.predã  s   ø€ Ü˜aÐ!6Ó7Ð7rG   z9Argument must be a type, a tuple of types, or a callable.r‰  c                 ó`   •‡ — t        j                  ‰ «      dt        dt        fˆ ˆfd„«       }|S )Nr�   r>   c                 ó(   •—  ‰| «      r ‰| «      S | S r@   rA   )r�   r‰  r   s    €€rD   Úwrappedz*map_only.<locals>.wrapper.<locals>.wrappedì  s   ø€ á�AŒwÙ˜A“w�ØˆHrG   )Ú	functoolsÚwrapsr6   r   )r‰  r£  r   s   ` €rD   Úwrapperzmap_only.<locals>.wrapperë  s3   ù€ Ü	�‰˜Ó	ð	”qð 	œSõ 	ó 
ð	ð
 ˆrG   )r\   rd   rè   ÚsysÚversion_infoÚtypesÚ	UnionTyper   rV   Úcallabler˜   r   r6   )r”  r¦  r   s   ` @rD   r—  r—  É  s�   ù€ ô* Ð'¬$´¨Ô7Ü×Ñ˜GÒ#ÜÐ,¬e¯o©oÔ>ð	8”Cð 	8œDö 	8ô 
Ð'Ô	(Ø$‰äÐSÓTÐTð”h¤˜s¤C˜xÑ(ð ¬X´s°e¼S°jÑ-Aõ ð €NrG   c                 ó   — y r@   rA   ©r”  r‰  r.  r:  s       rD   r-   r-   ÷  ó   € ð rG   c                 ó   — y r@   rA   r­  s       rD   r-   r-     r®  rG   c                 ó   — y r@   rA   r­  s       rD   r-   r-     r®  rG   c                 ó   — y r@   rA   r­  s       rD   r-   r-     r®  rG   c                 ó   — y r@   rA   r­  s       rD   r-   r-   #  r®  rG   c                ó<   — t         t        | «      |«      ||¬«      S r�  )r*   r—  r­  s       rD   r-   r-   .  s!   € ô Ð3”HÐ2Ó3°DÓ9¸4ÈÔQÐQrG   c                 ó   — y r@   rA   r­  s       rD   r.   r.   8  r®  rG   c                 ó   — y r@   rA   r­  s       rD   r.   r.   C  r®  rG   c                 ó   — y r@   rA   r­  s       rD   r.   r.   N  r®  rG   c                 ó   — y r@   rA   r­  s       rD   r.   r.   Y  r®  rG   c                 ó   — y r@   rA   r­  s       rD   r.   r.   d  r®  rG   c                ó<   — t         t        | «      |«      ||¬«      S r�  )r,   r—  r­  s       rD   r.   r.   o  s!   € ô Ð4”XÐ3Ó4°TÓ:¸DÈ'ÔRÐRrG   r   c                 óF   — t        ||¬«      }t        t        | |«      «      S r�  )r&   r4  rŒ  ©r   r.  r:  r�  s       rD   r/   r/   y  ó"   € ô
 ˜$¨Ô0€IÜŒs�4˜Ó#Ó$Ð$rG   c                 óF   — t        ||¬«      }t        t        | |«      «      S r�  )r&   ÚanyrŒ  r»  s       rD   r0   r0   ‚  r¼  rG   Útype_or_typesc                 ó   — y r@   rA   ©r¿  r   r.  r:  s       rD   r1   r1   ‹  r®  rG   c                 ó   — y r@   rA   rÁ  s       rD   r1   r1   –  r®  rG   c                 ó   — y r@   rA   rÁ  s       rD   r1   r1   ¡  r®  rG   c                óJ   ‡ ‡— t        ||¬«      }t        ˆˆ fd„|D «       «      S )Nr‚  c              3   óH   •K  — | ]  }t        |‰«      sŒ ‰|«      –— Œ y ­wr@   rŸ  ©r  r�   r   r¿  s     €€rD   r  z tree_all_only.<locals>.<genexpr>´  ó   øè ø€ ÒJ˜1¬Z¸¸=Õ-I‰t�A�wÑJùó   ƒ"•")r&   r4  ©r¿  r   r.  r:  r�  s   ``   rD   r1   r1   ¬  ó"   ù€ ô ˜$¨Ô0€IÜÔJ 	ÔJÓJÐJrG   c                 ó   — y r@   rA   rÁ  s       rD   r2   r2   ·  r®  rG   c                 ó   — y r@   rA   rÁ  s       rD   r2   r2   Â  r®  rG   c                 ó   — y r@   rA   rÁ  s       rD   r2   r2   Í  r®  rG   c                óJ   ‡ ‡— t        ||¬«      }t        ˆˆ fd„|D «       «      S )Nr‚  c              3   óH   •K  — | ]  }t        |‰«      sŒ ‰|«      –— Œ y ­wr@   rŸ  rÆ  s     €€rD   r  z tree_any_only.<locals>.<genexpr>à  rÇ  rÈ  )r&   r¾  rÉ  s   ``   rD   r2   r2   Ø  rÊ  rG   c                 ó¶  — t        |t        «      sJ ‚t        | |¬«      r| g|j                  z  S |j	                  «       ry t        | «      }||j                  k7  ry t        |   j                  } || «      \  }}t        |«      |j                  k7  s||j                  k7  ry g }t        ||j                  «      D ]  \  }}	t        ||	|¬«      }
|
�||
z  }Œ y  |S r�  )r\   r   r=  rD  r:  r9  rd   rj   re   r3  rE  r”   r÷   rB  Ú_broadcast_to_and_flatten)r.  r^  r:  rb  re   rs  ÚctxÚresultrX  rt  Úflats              rD   rÑ  rÑ  ë  sì   € ô
 �h¤Ô)Ð)Ð)ä�˜gÕ&Øˆv˜×+Ñ+Ñ+Ð+Ø×ÑÔØÜ˜tÓ$€IØ�H—M‘MÒ!Øä  Ñ+×6Ñ6€JÙ# DÓ)Ñ€M�3ô ˆ=Ó˜X×2Ñ2Ò2°c¸X×=MÑ=MÒ6MØð €FÜ  °×0GÑ0GÓHò ÑˆˆzÜ(¨°
ÀGÔLˆØÐØ�d‰N‰Fáðð €MrG   c                   ó<   — e Zd ZU dZee   ed<   eed<   ed    ed<   y)Ú_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.
    rd   r”   Úchildren_specN)	rQ   rR   rS   Ú__doc__r   rW   rh   r   rÛ   rA   rG   rD   rÖ  rÖ    s%   … ñð �3‰-ÓØÓØÐ)Ñ*Ô*rG   rÖ  c                   ó:   — e Zd ZU eegef   ed<   eegef   ed<   y)Ú_ProtocolFnÚtreespec_to_jsonÚjson_to_treespecN)rQ   rR   rS   r   r   r   rh   rA   rG   rD   rÚ  rÚ    s'   … Ø ˜z¨?Ð:Ñ;Ó;Ø Ð0°(Ð:Ñ;Ô;rG   rÚ  Ú_SUPPORTED_PROTOCOLSc                 óR  — | j                  «       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                  €'	 t        j                  | j                  t        ¬«      }n|j                  | j                  «      }| j                  D �cg c]  }t        |«      ‘Œ }}t        |||«      S # t        $ r}t        d«      |‚d }~ww xY wc c}w )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œ   z�Unable to serialize context. Please make the context json dump-able, or register a custom serializer using _register_pytree_node.)r:  rÖ  rd   rq   r  rn   r;   ro   ÚjsonÚdumpsr”   rY   r˜   rB  Ú_treespec_to_json)r^  r¼   rn   Úserialized_contextÚerX  Úchild_schemass          rD   râ  râ  $  s5  € Ø×ÑÔÜ˜t T¨2Ó.Ð.à‡}�}Ô6Ñ6Ü!Ø˜8Ÿ=™=˜/Ð)FÐGó
ð 	
ô 4°H·M±MÑBÐà-×BÑBÐàÔ<Ò<Ü!Ø3°H·M±M°?ð Cað aó
ð 	
ð
 ×-Ñ-Ð5ð	Ü!%§¡¨H×,<Ñ,<Ä+Ô!NÑð 0×CÑCÀH×DTÑDTÓUÐà;C×;RÑ;RÖS°%Ô& uÕ-ÐS€MÐSäÐ/Ð1CÀ]ÓSÐSøô ò 	ÜðAóð ð	ûð	üò Ts   Â%D Ã&D$Ä	D!ÄDÄD!Újson_schemac                 ó°  — | d   €| d   €t        | d   «      dk(  rt        S | d   t        vrt        d| d   › d�«      ‚t        | d      }t        |   }|j
                  €	 t        j                  | d   «      }n|j                  | d   «      }| d   D �cg c]  }t        |«      ‘Œ }}t        |||«      S # t        $ r}t        d«      |‚d }~ww xY wc c}w )Nrd   r”   r×  r   zDeserializing rß  zƒUnable to deserialize context. Please make the context json load-able, or register a custom serializer using _register_pytree_node.)r3  rƒ  rr   r  rq   rp   rà  Úloadsr˜   Ú_json_to_treespecr   )ræ  rm   r¼   r”   ÚexÚchild_stringrB  s          rD   ré  ré  H  s  € à�FÑÐ#Ø˜	Ñ"Ð*Ü�˜OÑ,Ó-°Ò2äÐà�6ÑÔ"@Ñ@Ü!Ø˜[¨Ñ0Ð1Ð1NÐOó
ð 	
ô )¨°VÑ)<Ñ
=€CÜ3°CÑ8Ðà×/Ñ/Ð7ð	Ü—j‘j ¨YÑ!7Ó8‰Gð %×:Ñ:¸;ÀyÑ;QÓRˆð =HÈÑ<XöØ,8Ô˜,Õ'ð€Nð ô �C˜ .Ó1Ð1øô ò 	ÜðAóð ð	ûð	üòs   Á!B6 ÂCÂ6	CÂ?CÃCÚprotocolc           	      ó`  — t        | t        «      st        dt        | «      › d�«      ‚|€t        }|t
        v rt
        |   j                  | «      }n,t        d|› dt        t
        j                  «       «      › �«      ‚t        j                  |t        j                  |«      ft        ¬«      }|S )Nzhtreespec_dumps(treespec, protocol): Expected `treespec` to be instance of TreeSpec but got item of type rÕ   úUnknown protocol ú. Available protocols: rœ   )r\   r   r˜   rd   Ú'DEFAULT_TREESPEC_SERIALIZATION_PROTOCOLrÝ  rÛ  r{   rÛ   ró   rà  rá  rw  ÚasdictrY   )r^  rì  Ú	json_specÚstr_specs       rD   r3   r3   n  sµ   € Ü�h¤Ô)Üð-Ü-1°(«^Ð,<¸Að?ó
ð 	
ð
 ÐÜ:ˆàÔ'Ñ'Ü(¨Ñ2×CÑCÀHÓM‰	äØ ˜zð *$Ü$(Ô)=×)BÑ)BÓ)DÓ$EÐ#FðHó
ð 	
ô
 �z‰z˜8¤[×%7Ñ%7¸	Ó%BÐCÌÔU€HØ€OrG   Ú
serializedc           	      óÊ   — t        j                  | «      \  }}|t        v rt        |   j                  |«      S t	        d|› dt        t        j                  «       «      › �«      ‚)Nrî  rï  )rà  rè  rÝ  rÜ  r{   rÛ   ró   )rô  rì  ræ  s      rD   r4   r4   „  sh   € ä ŸJ™J zÓ2Ñ€HˆkàÔ'Ñ'Ü# HÑ-×>Ñ>¸{ÓKÐKÜ
Ø
˜H˜:ð & Ü $Ô%9×%>Ñ%>Ó%@Ó AÐBð	Dóð rG   c                   ó   — e Zd Zdefd„Zy)Ú
_DummyLeafr>   c                  ó   — yr{  rA   rB   s    rD   rT  z_DummyLeaf.__repr__‘  r}  rG   N)rQ   rR   rS   rW   rT  rA   rG   rD   r÷  r÷  �  s   „ ð˜#ô rG   r÷  c                 óŒ   — t        t        | j                  «      D �cg c]  }t        «       ‘Œ c}| «      }t	        |«      S c c}w r@   )r%   ÚrangerD  r÷  r@  )r^  r“   Ú
dummy_trees      rD   r5   r5   •  s<   € ÜÜ$ X×%8Ñ%8Ó9Ö:˜!Œ�Ò:Øó€Jô �
ÓÐùò 	;s   �AzC`pytree_to_str` is deprecated. Please use `treespec_dumps` instead.c                 ó   — t        | «      S r@   )r3   )r^  s    rD   Úpytree_to_strrý  ž  s   € ô
 ˜(Ó#Ð#rG   zC`str_to_pytree` is deprecated. Please use `treespec_loads` instead.rà  c                 ó   — t        | «      S r@   )r4   )rà  s    rD   Ústr_to_pytreerÿ  §  s   € ô
 ˜$ÓÐrG   r‚   rƒ   c                  óª   — g }| D ]  }|j                  t        |«      «       Œ |j                  «       D ]  }|j                  t        |«      «       Œ |S )zpGet a flat list of arguments to this function

    A slightly faster version of tree_leaves((args, kwargs))
    )Úextendr&   rá   )r‚   rƒ   ro  Úas       rD   Úarg_tree_leavesr  ¯  sR   € ð
 €FØò $ˆØ�‰”i “lÕ#ð$à�]‰]‹_ò $ˆØ�‰”i “lÕ#ð$à€MrG   c                 óP   — 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.
    rA   )r#   rÛ   Ú_generate_key_paths)r.  r:  r“   r^  s       rD   r$   r$   ¼  s.   € ô( ˜t WÓ-�K€A€xÜÔ# B¨¨gÓ6Ó7¸ÐAÐArG   c                 ó.   — 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.
    rA   )rÛ   r  r<  s     rD   r(   r(   Ô  s   € ô$ Ô# B¨¨gÓ6Ó7Ð7rG   Úkey_pathc              #   ó  K  — |r ||«      r| |f–— y t        |«      }t        j                  |«      }|s| |f–— y |j                  }|r0 ||«      \  }}|D ]  \  }}	t	        g | ¢|‘­|	|«      E d {  –—†  Œ! y t        d|› d�«      ‚7 Œ­w)Nz.Did not find a flatten_with_keys_fn for type: zF. Please pass a flatten_with_keys_fn argument to register_pytree_node.)r9  rj   rP   rg   r  r{   )
r  r.  r:  rb  ÚhandlerÚflatten_with_keysÚkey_childrenr“   rù   Úcs
             rD   r  r  é  s½   è ø€ ñ
 ‘7˜4”=Ø˜ˆnÒØä˜tÓ$€IÜ×!Ñ! )Ó,€GÙà˜ˆnÒØà×4Ñ4ÐÙÙ+¨DÓ1‰ˆ�aØ ò 	G‰DˆAˆqÜ*¨>¨X¨>°q©>¸1¸gÓF×FÑFñ	Gô Ø<¸Y¸Kð HSð Só
ð 	
ð Gús   ‚A1BÁ3B
Á4Bc                óÒ   ‡ — t        ||«      \  }}t        t        |Ž «      }||D �cg c]  }|j                  |«      ‘Œ c}z   }|j	                  ˆ fd„t        |Ž D «       «      S c c}w )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              3   ó(   •K  — | ]	  } ‰|Ž –— Œ y ­wr@   rA   )r  Úxsr‰  s     €rD   r  z%tree_map_with_path.<locals>.<genexpr>&  s   øè ø€ ÒK¨B™d BœiÑKùs   ƒ)r$   rÛ   r÷   rn  rq  )r‰  r.  r:  rŠ  Úkeypath_leavesr^  rŽ  Úall_keypath_leavess   `       rD   r+   r+     si   ø€ ô:  6°d¸GÓDÑ€N�HÜœ#˜~Ð.Ó/€NØ'ÈeÖ*TÈ¨8×+AÑ+AÀ!Õ+DÒ*TÑTÐØ×ÑÓK´#Ð7IÐ2JÔKÓKÐKùò +Us   §A$Úkpc                 ó\   — dj                  | D �cg c]  }t        |«      ‘Œ c}«      S c c}w )z9Given a key path, return a pretty-printed representation.r   )rU  rW   )r  rù   s     rD   r    r    )  s#   € à�7‰7 BÖ'˜q”C˜•FÒ'Ó(Ð(ùÒ's   �)rZ   c                 ó6   — |D ]  }|j                  | «      } Œ | S )zAGiven an object and a key path, return the value at the key path.)rP   )rZ   r  rù   s      rD   r!   r!   .  s#   € àò ˆØ�e‰e�C‹j‰ðà€JrG   )NNr@   )´rØ  rw  r¤  r   Úimportlib.metadatarà  r§  Ú	threadingr©  r³   Úcollectionsr   r   r   r   Úcollections.abcr   r   r	   r
   Úenumr   Útypingr   r   r   r   r   r   r   r   r   Útyping_extensionsr   r   Ú__all__r6   r7   r8   r9   rð  r;   r=   ÚJSONEncoderrY   r   r   rè   rÛ   r   r   r   r   r   rW   Ú	ToStrFuncÚMaybeFromStrFuncÚKeyPathri   rc   ÚRLockrz   rj   rý   rd   rh   rl   rq   rr   ÚmetadataÚversionÚ_optree_versionÚtorch._vendor.packaging.versionrt   Ú_cxx_pytree_dynamo_traceabler}   ÚPackageNotFoundErrorr~   ru   r"   r‡   r  r‰   rš   rV   r�   Ú	dataclassr�   r£   r¥   r¬   rµ   r¶   rº   r|   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-  r7  r9  r=  r   r   rƒ  r#   r%   r&   r'   r)   r*   r,   ÚType2ÚType3r¨  rª  ÚTypeAnyÚFn2ÚFn3ÚFnÚFnAnyÚ	MapOnlyFnr—  r-   r.   r/   r0   r1   r2   rÑ  rÖ  rÚ  rÝ  rT   râ  ré  r3   Ú	lru_cacher4   r÷  r5   rý  rÿ  r  r$   r(   r  r+   r    r!   rA   rG   rD   ú<module>r5     sú  ðòó" Û Û Û Û Û 
Û Û Û ß CÓ Cß AÓ AÝ ÷
÷ 
õ 
÷ 5ò €ñF ˆCƒL€ÙˆCƒL€ÙˆCƒL€ÙˆCƒL€ð +,Ð 'Ø ?Ð ôˆxô ô$�$×"Ñ"ô $ð €Ø	€Ø˜�x  t¨C¡y°'Ð'9Ñ!:Ð:Ñ;€Ø˜( 3™-¨Ð1°6Ð9Ñ:€Ø€Ø ˜y¨/Ð9Ñ:Ð Ø  /Ð!2°GÐ!;Ñ<Ð Ø�j $ s¡)Ð,¨cÐ1Ñ2€	Ø˜S˜E 8¨E°#°wÀÐ2CÑ,DÑ#EÐEÑFÐ Ø
�˜#�Ñ
€Ø ˜x¨¨t°E¸(ÀC¸-Ñ4HÑ/IÈ3Ð/NÑ)OÐOÑPÐ ô8ˆjô 8ð &�i—o‘oÓ'Ð Ø,.€��d˜3‘i Ð(Ñ)Ó .ô;˜
ô ;ð BDÐ ˜D  c¡Ð,=Ð!=Ñ>Ó CØ79Ð   S¨$¨s©) ^Ñ 4Ó 9ð
AØ×(Ñ(×0Ñ0°Ó:€Oõ
 8ñ ˆÓ¡'¨(Ó"3Ò3ð
 =BÐAÐ$Ñ'9à<@Ð@Ð$Ñ'9àÐ Ø)+Ð ˜T #™YÓ +ð +/Ø9=Ø=AØ:>òE;Ø	ˆc‰ðE;àðE;ð  ðE;ð
 # 3™-ðE;ð "Ð"5Ñ6ðE;ð $Ð$9Ñ:ðE;ð #Ð#6Ñ7ðE;ð 
óE;ðP )˜D ™Ið  )¨$ó  )ñF  ›E€��D‘	Ó !ðK ˜4 ™9ð K ¨ó K ð\;˜4 ™9ð ;¨ó ;ð €×Ñ˜dÔ#÷ð ó $ðð2˜jð 2¨Tó 2ð
$˜Zð $¨Có $ðØ	ˆc‰ðð ðð 
ó	ñ8 ðEàôð &*Ø48ð4ð +/Ø9=Ø=AØ:>ò4Ø	ˆc‰ð4àð4ð  ð4ð ˜	Ñ"ð	4ð
  Ð 0Ñ1ð4ð # 3™-ð4ð "Ð"5Ñ6ð4ð $Ð$9Ñ:ð4ð #Ð#6Ñ7ð4ð 
ò4óð
4ðn$Ø	ˆc‰ð$à	ó$ð& +/Ø9=Ø=AØ:>ò)CØ	ˆc‰ð)Càð)Cð  ð)Cð
 # 3™-ð)Cð "Ð"5Ñ6ð)Cð $Ð$9Ñ:ð)Cð #Ð#6Ñ7ð)Cð 
ó)CðX €×Ñ˜dÔ#ô"�'˜!‘*ó "ó $ð"ñ ˆC�xÔ €ð €×Ñ˜dÔ#ô!�˜˜A˜‘ó !ó $ð!ð €×Ñ˜dÔ#÷'ð 'ó $ð'ð�e˜A˜s˜F‘mð ¨¨d°1©g°wÐ.>Ñ(?ó ðHØˆQ�ˆV�}ðHà
ˆ4��h �kÑ"Ñ# WÐ,Ñ-óHð˜X a™[ð °7ð ¸uÀQÈÀV¹}ó ð�T˜!‘Wð   t¨A¡w°Ð'7Ñ!8ó ðH˜t A™wð H¨5°°e¸HÀa¸KÑ6HÑ1IÈ7Ð1RÑ+Só Hð
˜H Q™Kð °'ð ¸dÀ1¹gó ð,�T˜#˜q˜&‘\ð , e¨D°©G°WÐ,<Ñ&=ó ,ðJØˆC�ˆF�|ðJà
ˆ4��h �kÑ"Ñ# WÐ,Ñ-óJð&˜H Q™Kð &°'ð &¸dÀ3ÈÀ6¹ló &ð˜:ð ¨%°°S±	¸7Ð0BÑ*Có ðØðà
ˆ4��h �mÑ$Ñ% wÐ.Ñ/óð. (¨1¡+ð .¸ð .ÀJó .ð  7ð  ¨ó  ð(¨oð À'ó ð,˜K¨¨Q¨Ñ/ð ,°E¸$¸q¹'À7Ð:JÑ4Kó ,ðJØ�3˜�6ÑðJà
ˆ4��h �kÑ"Ñ# WÐ,Ñ-óJðLØ�Q‰KðLàðLð ��a�ÑóLð &€Ø)Ð ð5˜K¨¨Q¨Ñ/ð 5°E¸$¸q¹'À7Ð:JÑ4Kó 5ð
OØ�3˜�6ÑðOà
ˆ4��h �kÑ"Ñ# WÐ,Ñ-óOðOØ�Q‰KðOàðOð ��a�ÑóOð Gð °ó ð+¨ð +À7ó +ð&�e˜A‘hð  5¨¨a©°'Ð)9Ñ#:ó ðHØˆQ�xðHà
ˆ4��h �kÑ"Ñ# WÐ,Ñ-óHð)˜X a™[ð )°7ð )¸uÀQ¹xó )ñ Ø	ØØØ)Ø1õñ ØØØØ(Ø0õñ ØØØØ(Ø0õñ ØØØØ1Ø-Ø1Ø6õñ ØØØØ2Ø7õñ ØØØØ2Ø.Ø2Ø7õñ Ø	ØØØ,Ø1õñ (1Ø	ˆ;˜Ð$ó(Ð �Y˜t‘_ó ñ "+Ø
ˆD�$˜
 K°¸eÐDó"€ˆy˜‰ó ð7 #ð 7¨$ó 7ð˜ð  ó ñ�6ð  H¨X°v°hÀ°nÑ-EÑ$Fð ÐRVó ð €×Ñ˜D¨°$¸UÔC÷[9ð [9ó Dð[9ðD €×Ñ˜D¨°%¸eÔDôˆxó ó Eðñ& ‹Z€
ð
 37ñØ
ðà�h ˜x¨˜~Ñ.Ñ/ðð ˆ4�‰9�hÐÑóð4	&˜8 C™=ð 	&°Hð 	&Àó 	&ð 37ñ9Ø
ð9à�h ˜x¨˜~Ñ.Ñ/ð9ð ˆc�]ó9ð& 37ñ2Ø
ð2à�h ˜x¨˜~Ñ.Ñ/ð2ð 
ˆ#�Yó2ð 37ñ2Ø
ð2à�h ˜x¨˜~Ñ.Ñ/ð2ð ó2ð 37ò	)5Ø
�3˜�8Ñ
ð)5à
ð)5ð ð)5ð �h ˜x¨˜~Ñ.Ñ/ð	)5ð
 ó)5ð` 37ò	Ø
�3˜�8Ñ
ðà
ðð ðð �h ˜x¨˜~Ñ.Ñ/ð	ð
 óðD 	ˆd�1‰g�t˜A‘wÐÑ€Øˆd�1‰g�t˜A‘w  Q¡Ð'Ñ(€Ø×Ò�wÒØ�D˜‘I˜u T¨#¡Y° ^Ñ4°e·o²oÐEÑF�Gà�D˜‘I˜u T¨#¡Y° ^Ñ4Ð4Ñ5€Gà��a˜�d‘ˆ}˜aÐÑ €Ø��a˜˜A�g‘Ð Ð"Ñ#€Øˆqˆc�1ˆfÑ€Ø�#�˜�Ñ€à�a�S˜( C 5¨# :Ñ.Ð.Ñ/€	ð
 
ð D¨¡Gð °9¸RÀÀ3À¹ZÑ3Hò ó 
ðð 
ð E¨!¨Q¨$¡Kð °yÀÀQÈÈ3ÀYÁÑ7Pò ó 
ðð 
ð E¨!¨Q°¨'¡Nð ¸)ÀCÈÈ1ÈaÐQTÈÑDUÑ:Vò ó 
ðð
 
ð Gð °9¸UÀ3¹ZÑ3Hò ó 
ðð 
ð H¨c¨U°D¨[Ñ$9ð ÀÈ5ÐQTÉ:ÑAVò ó 
ðð+Ø  ¨(°C°5¸$°;Ñ*?Ð!?Ñ@ð+àˆu�S‰zÑó+ð\ 
ð 37ñð ˆQ�ˆV‰*ðð ð	ð
 �h ˜x¨˜~Ñ.Ñ/ðØ ™7ðð òó 
ðð 
ð 37ñð ˆa��Cˆi‰.ðð ð	ð
 �h ˜x¨˜~Ñ.Ñ/ðØ   A ™;ðð òó 
ðð 
ð 37ñð ˆa��A�sˆlÑ
ðð ð	ð
 �h ˜x¨˜~Ñ.Ñ/ðØ   A q ™>ðð òó 
ðð 
ð 37ñð �‰*ðð ð	ð
 �h ˜x¨˜~Ñ.Ñ/ðØ"ðð òó 
ðð 
ð 37ñð �‰*ðð ð	ð
 �h ˜x¨˜~Ñ.Ñ/ðØ# S E¨4 KÑ0ðð òó 
ðð 37ñRð �‰*ðRð ð	Rð
 �h ˜x¨˜~Ñ.Ñ/ðRØ  ¨(°C°5¸$°;Ñ*?Ð!?Ñ@ðRð óRð 
ð 37ñð ˆQ�ˆV‰*ðð ð	ð
 �h ˜x¨˜~Ñ.Ñ/ðØ ™7ðð òó 
ðð 
ð 37ñð ˆa��Cˆi‰.ðð ð	ð
 �h ˜x¨˜~Ñ.Ñ/ðØ   A ™;ðð òó 
ðð 
ð 37ñð ˆa��A�sˆlÑ
ðð ð	ð
 �h ˜x¨˜~Ñ.Ñ/ðØ   A q ™>ðð òó 
ðð 
ð 37ñð �‰*ðð ð	ð
 �h ˜x¨˜~Ñ.Ñ/ðØ"ðð òó 
ðð 
ð 37ñð �‰*ðð ð	ð
 �h ˜x¨˜~Ñ.Ñ/ðØ# S E¨4 KÑ0ðð òó 
ðð 37ñSð �‰*ðSð ð	Sð
 �h ˜x¨˜~Ñ.Ñ/ðSØ  ¨(°C°5¸$°;Ñ*?Ð!?Ñ@ðSð óSð 37ñ%Ø
�C�5˜$�;Ñ
ð%à
ð%ð �h ˜x¨˜~Ñ.Ñ/ð%ð 
ó	%ð 37ñ%Ø
�C�5˜$�;Ñ
ð%à
ð%ð �h ˜x¨˜~Ñ.Ñ/ð%ð 
ó	%ð 
ð 37ñð ˆQ�ˆW‰+ðð ð	ð
 �h ˜x¨˜~Ñ.Ñ/ðØ˜‘7ðð 
òó 
ðð 
ð 37ñð ˆa��Dˆj‰/ðð ð	ð
 �h ˜x¨˜~Ñ.Ñ/ðØ˜˜A˜‘;ðð 
òó 
ðð 
ð 37ñð ˆa��A�tˆmÑ
ðð ð	ð
 �h ˜x¨˜~Ñ.Ñ/ðØ˜˜A˜q˜‘>ðð 
òó 
ðð 37ñKð �‰+ðKð ð	Kð
 �h ˜x¨˜~Ñ.Ñ/ðKØðKð 
óKð 
ð 37ñð ˆQ�ˆW‰+ðð ð	ð
 �h ˜x¨˜~Ñ.Ñ/ðØ˜‘7ðð 
òó 
ðð 
ð 37ñð ˆa��Dˆj‰/ðð ð	ð
 �h ˜x¨˜~Ñ.Ñ/ðØ˜˜A˜‘;ðð 
òó 
ðð 
ð 37ñð ˆa��A�tˆmÑ
ðð ð	ð
 �h ˜x¨˜~Ñ.Ñ/ðØ˜˜A˜q˜‘>ðð 
òó 
ðð 37ñKð �‰+ðKð ð	Kð
 �h ˜x¨˜~Ñ.Ñ/ðKØðKð 
óKð, 37ñØ
ðàðð �h ˜x¨˜~Ñ.Ñ/ðð ˆd�3‰iÑó	ðD ×Ñ÷+ð +ó ð+ô<�*ô <ð
 02Ð �d˜3 Ð+Ñ,Ó 1ð!T ð !T¨_ó !TðH 2 ?ð  2°xó  2ñF &Ð&7Ð9JÓKÐ �QÑ ñ˜Xð °¸#±ð È#ó ð, ×Òð˜sð  xò ó ð÷ñ ð
˜hð ¨3ó ñ ØIØôð$˜Hð $¨ò $ó	ð$ñ
 ØIØôð ˜ð   ò  ó	ð ð
˜6ð 
¨Vð 
¸¸S¹	ó 
ð 37ñBØ
ðBà�h ˜x¨˜~Ñ.Ñ/ðBð ˆ4��g˜s�lÑ#Ñ$ hÐ.Ñ/óBð4 37ñ8Ø
ð8à�h ˜x¨˜~Ñ.Ñ/ð8ð 
ˆ%�˜�Ñ
Ñó8ð0 37ñ
Øð
à
ð
ð �h ˜x¨˜~Ñ.Ñ/ð
ð ˆe�G˜S�LÑ!Ñ"ó	
ðB 37ò	 LØ
�3˜�8Ñ
ð Là
ð Lð ð Lð �h ˜x¨˜~Ñ.Ñ/ð	 Lð
 ó LðF)ˆwð )˜3ó )ð
�ð ˜'ð  cô øðS4 ×Ñ×.Ñ.ò >à8=Ð=Ð Ó#5ð>ús   Å,q: ñ:ròr