Ë
    f^(h*¯  ã                   ó  — d dl Z d dlZd dlZd dlZd dlmZ d dlmZmZ d dl	m
Z
mZmZmZmZ d dl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 erd dlmZ d d	lmZ d d
l m!Z!m"Z" g d¢Z# ejH                  e%«      Z& G d„ de«      Z' G d„ de(«      Z) G d„ de)«      Z* G d„ de)«      Z+dddœde,dee-   dee-   fd„Z.e'j^                  e._/        e'j`                  e._0        e'jb                  e._1        dddœde,dee-   dee-   de2e)df   fd„Z3e jh                   G d„ d«      «       Z5e jh                   G d„ d e5«      «       Z6e jh                   G d!„ d"«      «       Z7e jh                   G d#„ d$e5«      «       Z8e jh                   G d%„ d&e5«      «       Z9ee6e8e9f   Z:d'e:d(ee-e-ge;d)   f   d*d+de<e,e2e-e-f   f   d,e;e2d-      d.e;e2d)ed/   ef      d0e<e,d1f   d2e=d)   fd3„Z>dd4œd5ede
f   d6e
d7e
d8ee,   de
f
d9„Z?dDde<e,e
f   fd:„Z@ G d;„ d<«      ZAd=„ ZBd>e<e,e
f   d7ee<e,e
f   e2e
   e;e
   df   fd?„ZCd>e<e,e
f   d7ee<e,e
f   e2e
   e;e
   df   de;e:   fd@„ZDd7ee<e,e
f   e2e
   e;e
   df   fdA„ZEdBe,d7ee<e,e
f   e2e
   e;e
   f   dee<e,e
f   e2e
   e;e
   f   fdC„ZFy)Eé    N)Údefaultdict)ÚautoÚEnum)ÚAnyÚCallableÚOptionalÚTYPE_CHECKINGÚUnion)	Ú_get_node_typeÚBUILTIN_TYPESÚkeystrÚLeafSpecÚ
MappingKeyÚSequenceKeyÚSUPPORTED_NODESÚtree_flattenÚtree_map_with_pathé   )ÚExportedProgram)ÚSymbol)ÚSource)ÚShapeEnvÚStrictMinMaxConstraint)Ú
ConstraintÚDimÚdimsÚ*refine_dynamic_shapes_from_suggested_fixesc                   ó:   — e Zd ZdZ e«       Z e«       Z e«       Zy)Ú_DimHintzÜ
    Enum for dynamic shape hints.
    - AUTO means automatic inference of shape (static or dynamic).
    - STATIC means static shape (always specialized).
    - DYNAMIC means dynamic, will error out if specialized.
    N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚAUTOÚSTATICÚDYNAMIC© ó    úY/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/torch/export/dynamic_shapes.pyr   r   +   s   „ ññ ‹6€DÙ‹V€FÙ‹f�Gr(   r   c                   óP   — e Zd ZdZed„ «       Zd„ Zd„ Zd„ Zd„ Z	d„ Z
d„ Zd	„ Zd
„ Zy)Ú_Dimz*
    Metaclass for :func:`Dim` types.
    c                 ó‚   — ddl m} |dk(  rd }||k(  rd }|€|€d| › d�S |€	d| › d|› d�S |€	d| › d|› d�S d| › d|› d	|› d�S )
Nr   ©Úint_ooé   zDim('z')z', max=ú)z', min=ú, max=)Útorch.utils._sympy.numbersr.   )ÚnameÚmin_Úmax_r.   s       r)   Úreadablez_Dim.readable=   s„   € å5à�1Š9ØˆDØ�6Š>ØˆDØˆ<˜D˜LØ˜4˜& Ð#Ð#Øˆ<Ø˜4˜& ¨ v¨QÐ/Ð/Øˆ<Ø˜4˜& ¨ v¨QÐ/Ð/Ø�t�f˜G D 6¨°¨v°QÐ7Ð7r(   c                 ó†   ‡— t        ‰«      t        urt        d‰› d| j                  › d�«      ‚| j	                  ˆfd„«      S )NzAttempted to add z to úm, where an integer was expected. (Only increasing linear operations with integer coefficients are supported.)c                 ó   •— | ‰z   S ©Nr'   ©ÚxÚothers    €r)   ú<lambda>z_Dim.__add__.<locals>.<lambda>T   ó   ø€  Q¨¡Y€ r(   ©ÚtypeÚintÚNotImplementedErrorr    Ú_derive©Úclsr=   s    `r)   Ú__add__z_Dim.__add__M   sK   ø€ ä�‹;œcÑ!Ü%Ø# E 7¨$¨s¯|©|¨nð =_ð _óð ð �{‰{Ó.Ó/Ð/r(   c                 ó   — | |z   S r:   r'   rE   s     r)   Ú__radd__z_Dim.__radd__V   ó   € Ø�U‰{Ðr(   c                 ó†   ‡— t        ‰«      t        urt        d‰› d| j                  › d�«      ‚| j	                  ˆfd„«      S )NzAttempted to subtract z from r8   c                 ó   •— | ‰z
  S r:   r'   r;   s    €r)   r>   z_Dim.__sub__.<locals>.<lambda>`   r?   r(   r@   rE   s    `r)   Ú__sub__z_Dim.__sub__Y   sL   ø€ ä�‹;œcÑ!Ü%Ø(¨¨¨v°c·l±l°^ð D_ð _óð ð �{‰{Ó.Ó/Ð/r(   c                 ó4   — t        d| j                  › d�«      ‚)NzAttempted to negate zN. (Only increasing linear operations with integer coefficients are supported.))rC   r    rE   s     r)   Ú__rsub__z_Dim.__rsub__b   s&   € Ü!Ø" 3§<¡< .ð 1[ð [ó
ð 	
r(   c                 ó�   ‡— t        ‰«      t        us‰dk  rt        d‰› d| j                  › d�«      ‚| j	                  ˆfd„«      S )Nr   zAttempted to multiply z with zu, where a positive integer was expected. (Only increasing linear operations with integer coefficients are supported.)c                 ó   •— | ‰z  S r:   r'   r;   s    €r)   r>   z_Dim.__mul__.<locals>.<lambda>o   r?   r(   r@   rE   s    `r)   Ú__mul__z_Dim.__mul__h   sR   ø€ ä�‹;œcÑ! U¨a¢ZÜ%Ø(¨¨¨v°c·l±l°^ð D_ð _óð ð �{‰{Ó.Ó/Ð/r(   c                 ó   — | |z  S r:   r'   rE   s     r)   Ú__rmul__z_Dim.__rmul__q   rJ   r(   c                 óP   — ddl m} t         | || j                  «      «      «      S )Nr   )Úsympify)ÚsympyrV   Ústrr    )rF   ÚfnrV   s      r)   Ú_derived_namez_Dim._derived_namet   s   € Ý!ä‘2‘g˜cŸl™lÓ+Ó,Ó-Ð-r(   c                 óJ   — t        | j                  |«      t        f| |dœ«      S )N©ÚrootrY   )Ú_DerivedDimrZ   rB   )rF   rY   s     r)   rD   z_Dim._derivey   s#   € Ü˜3×,Ñ,¨RÓ0´3°&À3ÈbÑ:QÓRÐRr(   N)r    r!   r"   r#   Ústaticmethodr6   rG   rI   rM   rO   rR   rT   rZ   rD   r'   r(   r)   r+   r+   8   sD   „ ñð ñ8ó ð8ò0òò0ò
ò0òò.ó
Sr(   r+   c                   ó0   — e Zd ZdZed„ «       Zed„ «       Zy)Ú
_StaticDimz«
    Meta class for static :func:`Dim` types.

    This class is only for setting and checking static dim constraints,
    and the user should never interact with it.
    c                 ó   — | j                   S r:   ©Úvalue©Úselfs    r)   Úminz_StaticDim.min…   ó   € à�z‰zÐr(   c                 ó   — | j                   S r:   rc   re   s    r)   Úmaxz_StaticDim.max‰   rh   r(   N)r    r!   r"   r#   Úpropertyrg   rj   r'   r(   r)   ra   ra   }   s/   „ ñð ñó ðð ñó ñr(   ra   c                   ó6   — e Zd ZdZed„ «       Zed„ «       Zd„ Zy)r^   a  
    Metaclass for derived :func:`Dim` types.

    Currently we only support increasing linear expressions with integer coefficients.
    In other words, a derived Dim can always be written in the form Ax + B, where
    x is a regular Dim (i.e., non-derived Dim), A and B are integers, and A is positive.
    (In particular, the latter ensures that x < y => Ax + B < Ay + B.)
    These restrictions on the form of derived Dims makes the metatheory simpler: e.g.,
    it simplifies computing ranges for derived Dims, solving for underlying regular Dims,
    deciding equalities between derived Dims, and so on.

    The function lambda x: Ax + B is expressed by `fn`, where x is a normal Dim, `root`.
    The range of a derived Dim is computed by mapping `fn` over the range of its `root`.
    c                 ó>  — ddl m} ddlm} | j                  j
                  | u r| S | j                   || j                  j
                  «      «      }| j                  }|dk\  s/J d| j                  › d|j                  › d|j
                  › d�«       ‚t        |«      S )Nr   ©ÚIntegerr-   zExpected derived min value of z9 to be >= 0. Please specify an appropriate min value for ú (currently ú).)	rW   ro   r2   r.   r]   rg   rY   r    rB   )rf   ro   r.   Ú_min_symintr]   s        r)   rg   z_DerivedDim.minž   s˜   € õ 	"å5à�9‰9�=‰=˜V˜GÑ#Ø�7ˆNà—g‘g™g d§i¡i§m¡mÓ4Ó5ˆØ�y‰yˆØ˜aÒð 	
Ø,¨T¯]©]¨Oð <;Ø;?¿=¹=¸/ð JØŸ(™(˜ 2ð'ó	
Ðô
 �;ÓÐr(   c           
      ó„  — ddl m} ddlm} | j                  j
                  |u r|S | j                   || j                  j
                  «      «      }| j                  }|t        j                  dz
  k  sCJ d| j                  › dt        j                  dz
  › d|j                  › d|j
                  › d	�	«       ‚t        |«      S )
Nr   rn   r-   r   zExpected derived max value of z
 to be <= z.. Please specify an appropriate max value for rp   rq   )rW   ro   r2   r.   r]   rj   rY   ÚsysÚmaxsizer    rB   )rf   ro   r.   Ú_max_symintr]   s        r)   rj   z_DerivedDim.max²   s­   € õ 	"å5à�9‰9�=‰=˜FÑ"ØˆMà—g‘g™g d§i¡i§m¡mÓ4Ó5ˆØ�y‰yˆØœcŸk™k¨A™oÒ-ð 	
Ø,¨T¯]©]¨O¸:ÄcÇkÁkÐTUÁoÐEVð W;Ø;?¿=¹=¸/ð JØŸ(™(˜ 2ð'ó	
Ð-ô
 �;ÓÐr(   c                 ój   ‡ ‡— t        ‰ j                  ‰«      t        f‰ j                  ˆˆ fd„dœ«      S )Nc                 ó2   •—  ‰‰j                  | «      «      S r:   )rY   )r<   rY   rf   s    €€r)   r>   z%_DerivedDim._derive.<locals>.<lambda>Í   s   ø€ ±°4·7±7¸1³:³€ r(   r\   )r^   rZ   rB   r]   )rf   rY   s   ``r)   rD   z_DerivedDim._deriveÆ   s2   ù€ ô Ø×Ñ˜rÓ"ÜˆFØ—Y‘YÔ&>Ñ?ó
ð 	
r(   N)r    r!   r"   r#   rk   rg   rj   rD   r'   r(   r)   r^   r^   Ž   s4   „ ñð ñ ó ð ð& ñ ó ð ó&
r(   r^   ©rg   rj   r3   rg   rj   c                ó&  — ddl m} |€dn|}|€|n|}||kD  sJ d|› d|› �«       ‚| j                  «       s
J d| › �«       ‚t        | t        f||dœ«      }t        t        j                  t        j                  «       d   d   «      dd	«      |_	        |S )
an  
    :func:`Dim` constructs a type analogous to a named symbolic integer with a range.
    It can be used to describe multiple possible values of a dynamic tensor dimension.
    Note that different dynamic dimensions of the same tensor, or of different tensors,
    can be described by the same type.

    Args:
        name (str): Human-readable name for debugging.
        min (Optional[int]): Minimum possible value of given symbol (inclusive)
        max (Optional[int]): Maximum possible value of given symbol (inclusive)

    Returns:
        A type that can be used in dynamic shape specifications for tensors.
    r   r-   z(Cannot create Dim with inconsistent min=r1   z)Dim name must be a valid identifier, got ry   r   r    Ú__main__)
r2   r.   Úisidentifierr+   rB   ÚgetattrÚinspectÚ	getmoduleÚstackr!   )r3   rg   rj   r.   Ú_minÚ_maxÚdims          r)   r   r   Ñ   s¥   € õ  2à�‰1 €DØ�[‰6 c€DØ�$Š;ÐSÐBÀ3À%ÀvÈcÈUÐSÓSˆ;Ø×ÑÔÐRÐ"KÈDÈ6Ð RÓRÐÜ
ˆt”c�V T°$Ñ7Ó
8€CÜÜ×Ñœ'Ÿ-™-›/¨!Ñ,¨QÑ/Ó0°*¸jó€C„Nð €Jr(   ÚnamesÚreturn.c                 ó0   ‡ ‡— t        ˆˆ fd„|D «       «      S )zh
    Util to create multiple :func:`Dim` types.

    Returns:
        A tuple of :func:`Dim` types.
    c              3   ó:   •K  — | ]  }t        |‰‰¬ «      –— Œ y­w)ry   N)r   )Ú.0r3   rj   rg   s     €€r)   ú	<genexpr>zdims.<locals>.<genexpr>ü   s   øè ø€ Ò?°”�T˜s¨×,Ð,Ñ?ùs   ƒ)Útuple)rg   rj   r„   s   `` r)   r   r   ó   s   ù€ ô Ô?¸Ô?Ó?Ð?r(   c                   ó&   — e Zd ZU dZeed<   eed<   y)Ú_ConstraintTargetz2
    This represents input tensor dimensions.
    Út_idrƒ   N)r    r!   r"   r#   rB   Ú__annotations__r'   r(   r)   rŒ   rŒ   ÿ   s   … ñð ƒIØ	„Hr(   rŒ   c                   ó\   — e Zd ZU dZeed<   ded<   dd„Zd„ Zd„ Zd	„ Z	d
„ Z
d„ Zed„ «       Zy)Ú_Constraintz¢
    This represents a Dim describing a constraint target.

    `name` is the name of the Dim.
    `constraint_range` contains the min/max bounds of the Dim.
    r3   r   Úconstraint_rangeNc                 óØ   — ddl m} ddlm} ddlm} |€|} || j                  j                   |||¬«      z  d¬«      }t        | j                  | j                  | j                  |«      S )Nr   ©r   r-   ©ÚValueRanges©ÚlowerÚupperF©ÚvrÚ	warn_only)Ú%torch.fx.experimental.symbolic_shapesr   r2   r.   Útorch.utils._sympy.value_rangesr•   r‘   rš   r�   r�   rƒ   r3   )rf   r—   r˜   r   r.   r•   r‘   s          r)   Ú_clone_with_rangez_Constraint._clone_with_range  se   € åPÝ5Ý?àˆ=ØˆEá1Ø×$Ñ$×'Ñ'©+¸EÈÔ*OÑOØô
Ðô Ø�I‰IØ�H‰HØ�I‰IØó	
ð 	
r(   c                 ó&   — | j                  |¬«      S )N©r—   ©rž   ©rf   r—   s     r)   Ú__ge__z_Constraint.__ge__)  ó   € Ø×%Ñ%¨EÐ%Ó2Ð2r(   c                 ó,   — | j                  |dz   ¬«      S )Nr   r    r¡   r¢   s     r)   Ú__gt__z_Constraint.__gt__,  ó   € Ø×%Ñ%¨E°A©IÐ%Ó6Ð6r(   c                 ó&   — | j                  |¬«      S )N©r˜   r¡   ©rf   r˜   s     r)   Ú__le__z_Constraint.__le__/  r¤   r(   c                 ó,   — | j                  |dz
  ¬«      S )Nr   r©   r¡   rª   s     r)   Ú__lt__z_Constraint.__lt__2  r§   r(   c                 ó   — t        d«      ‚)NzšCannot determine truth value of _Constraint. If you are trying to combine _Constraint's with logical connectives, you can specify them separately instead.)Ú	TypeErrorre   s    r)   Ú__bool__z_Constraint.__bool__5  s   € ô
 ð7ó
ð 	
r(   c                 ó°   — | j                   | j                  | j                  j                  j                  | j                  j                  j
                  dœS ©N)r�   rƒ   rg   rj   ©r�   rƒ   r‘   rš   r—   r˜   re   s    r)   Úserializable_specz_Constraint.serializable_spec@  sF   € ð —I‘IØ—8‘8Ø×(Ñ(×+Ñ+×1Ñ1Ø×(Ñ(×+Ñ+×1Ñ1ñ	
ð 	
r(   )r   N)r    r!   r"   r#   rX   rŽ   rž   r£   r¦   r«   r­   r°   rk   r´   r'   r(   r)   r�   r�   	  sF   … ñð ƒIØ.Ó.ó
ò(3ò7ò3ò7ò	
ð ñ
ó ñ
r(   r�   c                   ó0   — e Zd ZU dZeed<   ded<   eed<   y)Ú_PhantomRoota´  
    This represents the root of a derived Dim where the root does not directly
    specify the shape of any input dimension, but the derived Dim does.

    e.g., the input shapes 2*dim and dim + 1 are related via a "phantom" dim.

    The fields `name`, `constraint_range`, and `val` carried by a phantom root
    help create a symbol for it. Any derived dims with this phantom root are
    backed by expressions over this symbol.
    r3   r   r‘   ÚvalN)r    r!   r"   r#   rX   rŽ   rB   r'   r(   r)   r¶   r¶   Q  s   … ñ	ð ƒIØ.Ó.Ø	„Hr(   r¶   c                   óT   — e Zd ZU dZeed<   ded<   eeef   ed<   e	ed<   e
d„ «       Zy)	Ú_DerivedConstraintaC  
    This represents a derived Dim, whose root is either a regular constraint target
    (which directly specifies the shape of some input dimension) or a phantom root
    (which does so indirectly).

    It can be thought of as a subclass of `_Constraint`, except that it does not
    support <, <=, >, >= operations.
    r3   r   r‘   r]   rY   c                 ó°   — | j                   | j                  | j                  j                  j                  | j                  j                  j
                  dœS r²   r³   re   s    r)   r´   z$_DerivedConstraint.serializable_specs  sF   € ð —I‘IØ—8‘8Ø×(Ñ(×+Ñ+×1Ñ1Ø×(Ñ(×+Ñ+×1Ñ1ñ	
ð 	
r(   N)r    r!   r"   r#   rX   rŽ   r
   rŒ   r¶   r   rk   r´   r'   r(   r)   r¹   r¹   c  s<   … ñð ƒIØ.Ó.Ø
Ð! <Ð/Ñ
0Ó0ØƒLàñ
ó ñ
r(   r¹   c                   ó    — e Zd ZdZed„ «       Zy)Ú_RelaxedConstrainta‡  
    This represents a dim marked with Dim.AUTO/DYNAMIC (i.e. mark_dynamic() or maybe_mark_dynamic()),
    which leaves relations & min/max ranges for inference, instead of requiring explicit specification.
    The intention is for constraint violations to not be raised if produce_guards() finds equalities or
    relations between a _RelaxedConstraint and another type of _Constraint.
    c                 ó4   — | j                   | j                  dœS )N©r�   rƒ   r¾   re   s    r)   r´   z$_RelaxedConstraint.serializable_spec‡  s   € ð —I‘IØ—8‘8ñ
ð 	
r(   N)r    r!   r"   r#   rk   r´   r'   r(   r)   r¼   r¼   ~  s   „ ñð ñ
ó ñ
r(   r¼   Ú
constraintÚget_sourcesr   Ú	shape_envr   Úsource_pairs)r   r   Úderived_equalities)r   r   Úphantom_symbolsr   Úrelaxed_sourcesc                 ó®  ‡—  || j                   | j                  «      }|sy|^Š}	|j                  ˆfd„|	D «       «       t        | t        «      rj| j
                  |v r6|| j
                     \  }
} ||
|«      }	|j                  ˆfd„|	D «       «       y| j                   | j                  f|| j
                  <   yt        | t        «      �rit        | j                  t        «      s5 || j                  j                   | j                  j                  «      d   }nù| j                  j
                  |v r|| j                  j
                     }nÇ|j                  | j                  j                  t        j                  j                  j                  | j                  j
                  «      t        j                  j                   j"                  j$                  j&                  | j                  j(                  ¬«      }||| j                  j
                  <   | j*                  }|j-                  ‰||f«       yt        | t.        «      r|j1                  ‰«       yy)z¤
    Updates `source_pairs`, `derived_equalities`, and `phantom_symbols` (which become
    fields of `EqualityConstraint`) based on a given input `constraint`.
    Nc              3   ó&   •K  — | ]  }‰|f–— Œ
 y ­wr:   r'   ©rˆ   Úother_sourceÚsources     €r)   r‰   z&_process_equalities.<locals>.<genexpr>¨  s   øè ø€ ÒQ°<˜ Ô.ÑQùó   ƒc              3   ó&   •K  — | ]  }‰|f–— Œ
 y ­wr:   r'   rÈ   s     €r)   r‰   z&_process_equalities.<locals>.<genexpr>­  s   øè ø€ ò  Ø+7�˜Ô&ñ ùrË   r   )r·   rÊ   Údynamic_dimÚconstraint_dim)r�   rƒ   ÚextendÚ
isinstancer�   r3   r¹   r]   r¶   Úcreate_symbolr·   ÚtorchÚ_dynamorÊ   ÚConstantSourceÚfxÚexperimentalÚsymbolic_shapesÚ
DimDynamicr&   r‘   rY   Úappendr¼   Úadd)r¿   rÀ   rÁ   r„   rÂ   rÃ   rÄ   rÅ   ÚsourcesÚother_sourcesÚshared_t_idÚ
shared_dimr]   rY   rÊ   s                 @r)   Ú_process_equalitiesrß   ’  sØ  ø€ ñ ˜*Ÿ/™/¨:¯>©>Ó:€GÙØà$Ð€Fˆ]ð ×ÑÓQÀ=ÔQÔQÜ�*œkÔ*Ø�?‰?˜eÑ#Ø&+¨J¯O©OÑ&<Ñ#ˆK˜Ù'¨°ZÓ@ˆMØ×Ñó  Ø;Hô õ ð '1§o¡o°z·~±~Ð%FˆE�*—/‘/Ò"Ü	�JÔ 2Õ	3ä˜*Ÿ/™/¬<Ô8á˜zŸ™×3Ñ3°Z·_±_×5HÑ5HÓIÈ!ÑL‰Dð �‰×#Ñ# Ñ6Ø& z§¡×';Ñ';Ñ<‘ð !×.Ñ.Ø"Ÿ™×+Ñ+Ü Ÿ=™=×/Ñ/×>Ñ>¸z¿¹×?SÑ?SÓTÜ %§¡× 5Ñ 5× EÑ E× PÑ P× XÑ XØ#-§?¡?×#CÑ#Cð	 /ó �ð 9=� 
§¡× 4Ñ 4Ñ5à�]‰]ˆð 	×!Ñ! 6¨4°Ð"4Õ5Ü	�JÔ 2Ô	3Ø×Ñ˜FÕ#ð 
4r(   ©Ú	tree_nameÚfuncÚtreeÚdynamic_shapesrá   c                ó0  ‡ ‡‡	‡
‡‡‡— d„ Šˆˆ ˆfd„Š	 t        ‰|g|¢­d‰iŽS # t        $ ri}d|j                  d   v rR|sJ d«       ‚‰sJ d«       ‚d„ Š
ˆfd	„Šˆ	ˆ
ˆˆfd
„Š	t        |‰¬«      \  }}|D ]  }t        |‰«      \  }} ‰	||g «       Œ ‚ d}~ww xY w)a"  
    Customized tree_map for mapping pytrees to dynamic_shapes.

    For built-in types (e.g., standard collections) this behaves exactly like tree_map.

    OTOH for a user-defined class C registered with pytree, we cannot assume that a C
    containing tensors can be mapped to a C containing dynamic shapes (i.e., C may not
    be a polymorphic container). In that case we use the flattened form of C instead.
    Thus a C(**tensors) that flattens to (**tensors) will map to (**dynamic_shapes).

    Args:
        func: function to apply to each (int, float, str, bool, None, torch.Tensor)
        tree: input pytree
        dynamic_shapes: zero or more (typically one) dynamic_shapes to match

    Returns:
        output pytree mapping func to each (int, float, str, bool, None, torch.Tensor)
    c                 ó$   — t        | «      t        vS r:   )r   r   )Úts    r)   Úis_leafz$_tree_map_with_path.<locals>.is_leafæ  s   € ô
 ˜aÓ ¬Ð5Ð5r(   c                 ó�   •— t        |«      }|t        v r)t        ‰t        |   j                  |«      d   g|¢­d‰iŽS  ‰| |g|¢­Ž S )Nr   rè   )r   r   r   Ú
flatten_fn)Úpathrç   rä   ÚtypÚfrâ   rè   s       €€€r)   rí   z_tree_map_with_path.<locals>.fí  sg   ø€ Ü˜QÓˆà”/Ñ!ô &ØÜ Ñ$×/Ñ/°Ó2°1Ñ5ðð  òð  ñ	ð ñ ˜˜aÐ1 .Ò1Ð1r(   rè   Úmismatchr   z2Cannot be a mismatch if there is no dynamic_shapesz7Must provide a tree_name when there might be a mismatchc                 ó„   — | t         u rt        ||   «      S | t        t        fv r|�J ‚t	        |«      S t        d| › �«      ‚)NzDid not expect type )Údictr   ÚlistrŠ   r   ÚAssertionError)Útype_ÚcontextÚis      r)   Ú_keyz!_tree_map_with_path.<locals>._key  sK   € àœD‘=Ü% g¨a¡jÓ1Ð1ØœT¤5˜MÑ)Ø"˜?Ð*˜?Ü& q›>Ð)Ü$Ð';¸E¸7Ð%CÓDÐDr(   c                 óJ   •— ddl m}m}  ||j                  d‰› d| › �d¬«      ‚)Nr   ©Ú	UserErrorÚUserErrorTypez,Detected mismatch between the structure of `z` and `dynamic_shapes`: Údynamic_shapes_validation©Ú	case_name)Útorch._dynamo.excrù   rú   ÚINVALID_INPUT)Úmsgrù   rú   rá   s      €r)   Úraise_mismatch_errorz1_tree_map_with_path.<locals>.raise_mismatch_error  s2   ø€ ßFáØ!×/Ñ/ØBÀ9À+ÐMeÐfiÐejÐkØ9ôð r(   c                 ó  •— t        |«      }t        | t        «      ry t        |t        «      r ‰d‰› |› d| j                  › d|› d�«       | j                  |j                  k7  r* ‰d‰› |› d| j                  › d|› d|j                  › �	«       t	        | j
                  «      t	        |j
                  «      k7  r= ‰d‰› |› dt	        | j
                  «      › d|› dt	        |j
                  «      › d�
«       | j                  t        u r›t        | j                  «      t        |j                  «      k7  r* ‰d‰› |› d| j                  › d|› d|j                  › �	«       t        t        |j                  |j
                  «      «      }| j                  D �cg c]  }||   ‘Œ	 }}n|j
                  }t        t        | j
                  |«      «      D ]2  \  }\  }}	 ‰
||	| ‰| j                  | j                  |«      gz   «       Œ4 y c c}w )	Nú`z` is a z, but `dynamic_shapesz` is notz` has z elements, but `dynamic_shapesz	 elementsz` has keys )r   rÐ   r   rA   ÚlenÚchildren_specsrð   Úsortedrô   ÚzipÚ	enumerate)rã   rä   rë   Úrendered_pathÚ_remapÚkÚdynamic_shapes_children_specsrõ   Útree_Údynamic_shapes_Ú_comparerö   r  rá   s             €€€€r)   r  z%_tree_map_with_path.<locals>._compare  s#  ø€ ô !' t£�Ü˜d¤HÔ-ØÜ˜n¬hÔ7Ù(Ø˜I˜; } o°W¸T¿Y¹Y¸Kð H.Ø.;¨_¸HðFôð —9‘9 × 3Ñ 3Ò3Ù(Ø˜I˜; } o°W¸T¿Y¹Y¸Kð H.Ø.;¨_¸GÀN×DWÑDWÐCXðZôô �t×*Ñ*Ó+¬s°>×3PÑ3PÓ/QÒQÙ(Ø˜I˜; } o°V¼CÀ×@SÑ@SÓ<TÐ;Uð V.Ø.;¨_¸FÄ3À~×GdÑGdÓCeÐBfÐfoðqôð —9‘9¤Ñ$ä˜dŸl™lÓ+¬v°n×6LÑ6LÓ/MÒMÙ,Ø 	˜{¨=¨/¸ÀTÇ\Á\ÀNð S2Ø2?°ÀÈN×LbÑLbÐKcðeôô "Ü˜N×2Ñ2°N×4QÑ4QÓRó�Fð IMÏÉÖ4UÀ1°V¸A³YÐ4UÐ1Ñ4Uà4B×4QÑ4QÐ1Ü3<Ü˜×+Ñ+Ð-JÓKó4ò Ñ/�AÑ/˜˜ñ ØØ'Ø¡ T§Y¡Y°·±¸aÓ @ÐAÑAõñùò 5Vs   ÆH©rè   N)r   Ú
ValueErrorÚargsr   )râ   rã   rá   rä   ÚeÚ_Ú	tree_specÚ
other_treeÚother_tree_specr  rö   rí   rè   r  s   ` `      @@@@@r)   Ú_tree_map_with_pathr  Í  s¿   þ€ ò26ö2ðJÜ! ! TÐL¨NÒLÀGÑLÐLøÜò HØ˜Ÿ™ ™Ñ"ñ "ÐWÐ#WÓW�>ÙÐWÐWÓW�9òEô÷)ôV (¨°gÔ>‰LˆAˆyØ,ò 9�
Ü%1°*¸gÓ%FÑ"��?Ù˜ O°RÕ8ð9ð 	ûðQHús   “# £	B¬A$BÂBc                 ó>  — t        | t        «      r| j                  «       } |szt        | t        j                  j
                  «      rt        j                  | j                  «      nt        j                  | «      }|�|ni } |j                  |i |¤Žj                  S |S r:   )rÐ   r   ÚmodulerÒ   ÚnnÚModuler~   Ú	signatureÚforwardÚbindÚ	arguments)rí   r  ÚkwargsÚ_is_torch_jit_tracer  s        r)   Ú_combine_argsr#  I  s†   € ô �!”_Ô%Ø�H‰H‹JˆÙô ˜!œUŸX™XŸ_™_Ô-ô ×Ñ˜aŸi™iÔ(ä×"Ñ" 1Ó%ð 	ð
 "Ð-‘°2ˆØˆy�~‰~˜tÐ. vÑ.×8Ñ8Ð8Ø€Kr(   c                   ó0   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zdd„Zy)	ÚShapesCollectionaD  
    Builder for dynamic_shapes.
    Used to assign dynamic shape specifications to tensors that appear in inputs.

    This is useful particularly when :func:`args` is a nested input structure, and it's
    easier to index the input tensors, than to replicate the structure of :func:`args` in
    the :func:`dynamic_shapes` specification.

    Example::

        args = ({"x": tensor_x, "others": [tensor_y, tensor_z]})

        dim = torch.export.Dim(...)
        dynamic_shapes = torch.export.ShapesCollection()
        dynamic_shapes[tensor_x] = (dim, dim + 1, 8)
        dynamic_shapes[tensor_y] = {0: dim * 2}
        # This is equivalent to the following (now auto-generated):
        # dynamic_shapes = {"x": (dim, dim + 1, 8), "others": [{0: dim * 2}, None]}

        torch.export(..., args, dynamic_shapes=dynamic_shapes)
    c                 ó   — i | _         y r:   )Ú_shapesre   s    r)   Ú__init__zShapesCollection.__init__p  s	   € Øˆ�r(   c                 ó  — t        |t        j                  «      sJ dt        |«      › �«       ‚t	        |«      }|| j
                  v r"| j
                  |   }||k(  sJ d|› d|› �«       ‚y || j
                  t	        |«      <   y )Nz'Cannot assign shape to non-tensor type z1Shapes assigned to tensor do not match: expected z, got )rÐ   rÒ   ÚTensorrA   Úidr'  )rf   rç   Úshaper�   Ú_shapes        r)   Ú__setitem__zShapesCollection.__setitem__s  s‘   € ÜØŒu�|‰|ô
ð 	?à4´T¸!³W°IÐ>ó	?ð 
ô �!‹uˆØ�4—<‘<ÑØ—\‘\ $Ñ'ˆFà˜’ðYàBÀ6À(È&ÐQVÐPWÐXóYÙð #(ˆD�L‰Lœ˜A›Òr(   c                 óp   — t        |«      }|| j                  vri | j                  |<   | j                  |   S r:   )r+  r'  )rf   rç   r�   s      r)   Ú__getitem__zShapesCollection.__getitem__�  s4   € Ü�!‹uˆØ�t—|‘|Ñ#Ø!#ˆD�L‰L˜ÑØ�|‰|˜DÑ!Ð!r(   c                 ó,   — t        | j                  «      S r:   )r  r'  re   s    r)   Ú__len__zShapesCollection.__len__‡  s   € Ü�4—<‘<Ó Ð r(   Nc                 ó®   ‡ ‡— t        «       Šˆ ˆfd„}t        |||«      }t        ||«      }t        ˆfd„‰ j                  D «       «      rt        d«      ‚|S )zu
        Generates the :func:`dynamic_shapes` pytree structure according to :func:`args` and :func:`kwargs`.
        c                 óx   •— t        |«      }|‰j                  v r ‰j                  |«       ‰j                  |   S y r:   )r+  r'  rÚ   )rë   rç   r�   rf   Út_idss      €€r)   Ú
find_shapez3ShapesCollection.dynamic_shapes.<locals>.find_shape‘  s5   ø€ Ü�a“5ˆDØ�t—|‘|Ñ#Ø—	‘	˜$”Ø—|‘| DÑ)Ð)àr(   c              3   ó&   •K  — | ]  }|‰v–— Œ
 y ­wr:   r'   )rˆ   r�   r5  s     €r)   r‰   z2ShapesCollection.dynamic_shapes.<locals>.<genexpr>›  s   øè ø€ Ò: Tˆt˜5Ô Ñ:ùrË   zÊSome tensors that were assigned shapes were not found in args. Maybe such tensors were copied when passing them as args? Maybe such tensors are contained in classes that were not registered with pytree?)Úsetr#  r  Úanyr'  r  )rf   Úmr  r!  r6  Úcombined_argsrä   r5  s   `      @r)   rä   zShapesCollection.dynamic_shapesŠ  sZ   ù€ ô
 “ˆõ	ô & a¨¨vÓ6ˆÜ,¨Z¸ÓGˆÜÓ:¨T¯\©\Ô:Ô:Üðdóð ð
 Ðr(   r:   )	r    r!   r"   r#   r(  r.  r0  r2  rä   r'   r(   r)   r%  r%  Y  s    „ ñò,ò(ò"ò!ôr(   r%  c                  ó2   — d} t         j                  | «       y )NzTUsing None as a dynamic shape dimension is deprecated. Please use Dim.STATIC instead)ÚlogÚwarning)r   s    r)   Ú%_warn_on_None_dynamic_shape_dimensionr?  ¤  s   € ð	(ð ô
 ‡K�K�Õr(   r;  c                 óŠ  ‡‡‡‡	‡
— ddl mŠmŠ |�t        |«      dk(  ryt	        |t
        t        f«      r t        |«      | j                  «       «      } i Šˆˆˆfd„Š	ˆˆˆ	fd„Š
t	        |t        t
        t        f«      sJ ‚t	        |t        «      r�t        |j                  «       «      }t        | j                  «       «      }t        |«      t        |«      k7  rTd|› d|› d�}t        | «      d	k(  r#|d   |vrt	        | |d      t        «      r|d
z  }n|dz  } ‰‰j                  |d¬«      ‚ˆˆˆ
fd„}t        || |d¬«       y)z†
    Checks the dynamic_shapes specification for correctness,
    using combined args + kwargs as reference for inputs structure.
    r   rø   Nc           
      ó´  •— | j                   ‰v r¤‰| j                      \  }}| j                  |k7  s| j                  |k7  rst        j	                  | j                   ||«      }t        j	                  | j                   | j                  | j                  «      } ‰‰j
                  d|› d|› d| › d�«      ‚y | j                  | j                  f‰| j                   <   y )NzFound different definitions z and z! for the same symbolic dimension ú!)r    rg   rj   r+   r6   rÿ   )rƒ   r4   r5   Úthis_Úthat_rù   rú   Úboundss        €€€r)   Úcheck_same_boundsz0_check_dynamic_shapes.<locals>.check_same_bounds¾  sÁ   ø€ Ø�<‰<˜6Ñ!Ø §¡Ñ-‰JˆD�$Ø�w‰w˜$Š #§'¡'¨T¢/ÜŸ™ c§l¡l°D¸$Ó?�ÜŸ™ c§l¡l°C·G±G¸S¿W¹WÓE�ÙØ!×/Ñ/Ø2°5°'¸¸u¸gð F7Ø7:°e¸1ð>óð ð #2ð %(§G¡G¨S¯W©WÐ#5ˆF�3—<‘<Ò r(   c                 ó–  •— t        |t        «      r€|j                  «       D ]l  \  }}t        |t        «      r	 ‰|«       Œ|€t	        «        Œ,t        |t
        t        f«      rŒC ‰‰j                  d|› d|› dt        | «      › d|› d�	d¬«      ‚ y t        |t        t        f«      r{t        |«      D ]l  \  }}t        |t        «      r	 ‰|«       Œ|€t	        «        Œ,t        |t
        t        f«      rŒC ‰‰j                  d|› d|› dt        | «      › d	|› d�	d¬«      ‚ y |�% ‰‰j                  d
|› dt        | «      › d�d¬«      ‚y )Nz%Unexpected dimension mapped to index z in input tensor shape ú specified at `dynamic_shapeszP` (expected None, an int, a Dim, Dim.AUTO, Dim.STATIC, or Dim.DYNAMIC,  but got z	 instead)rû   rü   zUnexpected dimension #zO` (expected None, an int, a Dim, Dim.AUTO, Dim.STATIC, or Dim.DYNAMIC, but got zUnexpected input tensor shape z¤` (expected either a list/tuple of dimensions, or a dict mapping indices to dimensions, where each dimension is an int, a Dim, Dim.AUTO, Dim.STATIC, or Dim.DYNAMIC))rÐ   rð   Úitemsr+   r?  rB   r   rÿ   r   rŠ   rñ   r  )rë   Útensorr,  rõ   rƒ   rù   rú   rF  s        €€€r)   Úcheck_symbolsz,_check_dynamic_shapes.<locals>.check_symbolsÌ  s…  ø€ Ü�eœTÔ"ØŸ+™+›-ò ‘��3Ü˜c¤4Ô(Ù% cÕ*Ø�[Ü9Õ;Ü$ S¬3´¨/Õ:Ù#Ø%×3Ñ3Ø?À¸sÐBYÐZ_ÐY`ð a7Ü7=¸d³|°nð E$à$' 5¨	ð3ð #>ôð ñô ˜¤¤t˜}Ô-Ü# EÓ*ò ‘��3Ü˜c¤4Ô(Ù% cÕ*Ø�[Ü9Õ;Ü$ S¬3´¨/Õ:Ù#Ø%×3Ñ3Ø0°°Ð3JÈ5È'ð R7Ü7=¸d³|°nð E#à#& % yð2ð #>ôð ñð ÐÙØ×+Ñ+Ø0°°Ð7TÔU[Ð\`ÓUaÐTbð c`ð að 6ôð ð r(   zWWhen `dynamic_shapes` is specified as a dict, its top-level keys must be the arg names z  of `inputs`, but here they are z. r   zSince here `inputs` is a list/tuple enclosing a single dict, maybe you just forgot to enclose `dynamic_shapes` in a list/tuple?zwAlternatively, you could also ignore arg names entirely and specify `dynamic_shapes` as a list/tuple matching `inputs`.rû   rü   c                 óÀ   •— t        |t        j                  «      r ‰| ||«       y |�6t        | «      } ‰‰j                  d|› d|› dt        |«      › d|› d�	d¬«      ‚y )NzCannot associate shape rH  z` to non-tensor type z at `inputsz` (expected None)rû   rü   )rÐ   rÒ   r*  r   rÿ   rA   )rë   rç   Údynamic_shaper	  rù   rú   rK  s       €€€r)   Úcheck_shapez*_check_dynamic_shapes.<locals>.check_shape  sx   ø€ Ü�aœŸ™Ô&Ù˜$  =Õ1àÐ(Ü & t£�ÙØ!×/Ñ/Ø-¨m¨_Ð<YÐZgÐYhð i*Ü*.¨q«'¨°+¸m¸_ÐL]ð_à9ô	ð ð )r(   Úinputsrà   )rþ   rù   rú   r  rÐ   rŠ   rñ   rA   Úvaluesrð   Úkeysr  rÿ   r  )r;  rä   Úgot_keysÚexpected_arg_namesr   rN  rù   rú   rE  rF  rK  s         @@@@@r)   Ú_check_dynamic_shapesrT  ­  sX  ü€ ÷ ;àÐ¤ ^Ó!4¸Ò!9ØÜ�.¤5¬$ -Ô0Ø,œ˜^Ó,¨]×-AÑ-AÓ-CÓDˆà)+€Fö6ö&ôP �n¤t¬U´DÐ&9Ô:Ð:Ð:Ü�.¤$Ô'Ü˜×+Ñ+Ó-Ó.ˆÜ! -×"4Ñ"4Ó"6Ó7ÐÜ�(ÓœvÐ&8Ó9Ò9ð)Ø);Ð(<ð =!Ø!) 
¨"ð.ð ô �MÓ" aÒ'Ø& qÑ)°Ñ9Ü˜}Ð-?ÀÑ-BÑCÄTÔJàðYñ‘ð
 ðVñ�ñ Ø×+Ñ+¨SÐ<Wôð öô ˜ ]°NÈhÖWr(   c                 óÐ  ‡‡‡‡	‡
‡‡‡— ddl mŠmŠ |�t        |«      dk(  rg S t	        |t
        t        f«      r t        |«      | j                  «       «      } t        t        «      Ši Š
g Š	g Šˆˆˆ	ˆ
ˆfd„Šˆˆˆfd„Šˆfd„}t        || |d¬«       ‰	D ]*  }|j                  j                  }|‰v sŒ‰|   d   |_        Œ, ‰j                  «       D ]  }‰j                  |«       Œ ‰S )zT
    Reads the dynamic_shapes specification and produces a list of constraints.
    r   rø   c                 ó0  •‡ ‡‡‡
‡— dd l Š
ddlm} ddlmŠ ddlm} ˆˆˆ ˆˆ
ˆˆfd„}t        ‰ t        «      �r/‰ j                  }|j                  ‰v r3‰|j                     d   }t        |j                  |j                  «      }nn|j                  ‰vrQt        |j                   | ||j                  |j                   ¬«      d¬«       |«       ¬	«      }|‰|j                  <   n‰|j                     }t#        t%        ‰«      ‰‰ j                   | |‰ j                  ‰ j                   ¬«      d¬«      |‰ j&                  «      }	t        |t        «      r‰j)                  |	«       |	S t        ‰ t*        «      rGt-        t%        ‰«      ‰‰ j                   | |‰ j.                  ‰ j.                  ¬«      d¬«      «      }	|	S t        ‰ t0        «      sJ ‚t-        t%        ‰«      ‰‰ j                   | |‰ j                  ‰ j                   ¬«      d¬«      «      }	|	S )
Nr   r“   )Ú	try_solver”   c                  ó:  •— ‰j                  ‰j                  j                  d¬«      } ‰j                  | «      } ‰	‰j	                  |‰j
                  ‰   «      | «      }|�t        |d   «      S  ‰‰j                  d‰› d‰j
                  ‰   › d|› d| › d�	«      ‚)	NT)Úintegerr   zExpected shape[z] = z# of input Tensor to be of the form z, where z is an integer)r   r]   r    rY   ÚEqr,  rB   ÚCONSTRAINT_VIOLATION)
ÚsymbolÚexprÚsolutionrù   rú   rƒ   rõ   rW   rJ  rW  s
      €€€€€€€r)   Ú
root_valuezB_process_dynamic_shapes.<locals>.to_constraint.<locals>.root_value>  s¦   ø€ ð —\‘\ #§(¡(×"3Ñ"3¸T�\ÓBˆFØ—6‘6˜&“>ˆDÙ  §¡¨$°·±¸Q±Ó!@À&ÓIˆHØÐ#Ü˜8 A™;Ó'Ð'áØ!×6Ñ6Ø% a S¨¨V¯\©\¸!©_Ð,=ð >#Ø#' &¨°°¸ðHóð r(   r–   Fr™   )r3   r‘   r·   )rW   rœ   r   Útorch.utils._sympy.solverW  r�   r•   rÐ   r^   r]   r    rŒ   r�   rƒ   r¶   rg   rj   r¹   r+  rY   rÙ   ra   r�   rd   r+   )rƒ   rJ  rõ   r   r•   r_  Údim_rootÚroot_constraintr]   r¿   rW   rW  rù   rú   Ú%derived_constraints_with_phantom_rootÚphantom_rootsÚsymbolss   ```       @@€€€€€r)   Úto_constraintz._process_dynamic_shapes.<locals>.to_constraint7  sÝ  ý€ ÛåPÝ6Ý?÷	ò 	ô �cœ;Õ'ð —x‘xˆHØ× Ñ  GÑ+à")¨(×*;Ñ*;Ñ"<¸QÑ"?�Ü(Ø#×(Ñ(Ø#×'Ñ'ó‘ð ×"Ñ"¨-Ñ7ä#Ø!×*Ñ*Ù%;Ù&¨X¯\©\ÀÇÁÔNØ"'ô&ñ #›ô�ð 48�˜h×/Ñ/Ò0à$ X×%6Ñ%6Ñ7�Ü+Ü�6“
ØØ—‘Ù&Ù"¨¯©¸¿¹Ô@Ø#ôð Ø—‘ó
ˆJô ˜$¤Ô-ð 6×<Ñ<¸ZÔHð( Ðô' ˜œZÔ(Ü$Ü�6“
ØØ—‘Ù&Ù"¨¯©¸#¿)¹)ÔDÐPUôó	ˆJð$ Ðô ˜c¤4Ô(Ð(Ð(Ü$Ü�6“
ØØ—‘Ù&Ù"¨¯©¸¿¹Ô@ÈEôó	ˆJð Ðr(   c                 ó  •— d„ }t        «       |_        t        «       |_        t        «       |_        t        «       |_        t        «       |_        t        |t        «      �ri|j                  «       D �]T  \  }}t        |t        t        f«      rCt        |t        «      r
 ||||«      } ‰	|||«      }‰|j                     j                  |«       Œ`t        |t        «      rÁ|t        j                  k(  r!t        j                   j#                  ||«       ng|t        j$                  k(  r!t        j                   j'                  ||«       n3|t        j(                  k(  r t        j                   j+                  ||«       ‰j                  t-        t/        |«      |«      «       �Œ1|��Œ5t        j                   j'                  ||«       �ŒW y t        |t0        t2        f«      �rdt5        |«      D �]T  \  }}t        |t        t        f«      rCt        |t        «      r
 ||||«      } ‰	|||«      }‰|j                     j                  |«       Œ`t        |t        «      rÁ|t        j                  k(  r!t        j                   j#                  ||«       ng|t        j$                  k(  r!t        j                   j'                  ||«       n3|t        j(                  k(  r t        j                   j+                  ||«       ‰j                  t-        t/        |«      |«      «       �Œ1|��Œ5t        j                   j'                  ||«       �ŒW y |€?t7        |j9                  «       «      D ]"  }t        j                   j'                  ||«       Œ$ y y )Nc                 ó<   — t        t        |«      t        fd|i«      S )Nrd   )ra   rX   rB   )rJ  rõ   rd   s      r)   Ú_create_static_dimzK_process_dynamic_shapes.<locals>.update_symbols.<locals>._create_static_dim‹  s   € Üœc %›j¬3¨&°7¸EÐ2BÓCÐCr(   )r8  Ú_dynamo_weak_dynamic_indicesÚ_dynamo_dynamic_indicesÚ_dynamo_dynamic_rangeÚ_dynamo_static_indicesÚ_dynamo_unbacked_indicesrÐ   rð   rI  rB   r+   r    rÙ   r   r$   rÒ   rÓ   Úmaybe_mark_dynamicr%   Úmark_staticr&   Úmark_dynamicr¼   r+  rŠ   rñ   r  Úrangerƒ   )
rë   rJ  r,  ri  rõ   rƒ   r¿   Úconstraintsre  rf  s
          €€€r)   Úupdate_symbolsz/_process_dynamic_shapes.<locals>.update_symbolsŠ  s–  ø€ ò	Dô
 /2«eˆÔ+Ü),«ˆÔ&Ü'*£uˆÔ$Ü(+«ˆÔ%Ü*-«%ˆÔ'ä�eœTÕ"ØŸ+™+›-ó 9‘��3Ü˜c¤C¬ ;Ô/Ü! #¤sÔ+Ù0°¸¸CÓ@˜Ù!.¨s°F¸AÓ!>�JØ˜CŸL™LÑ)×0Ñ0°Õ<Ü ¤XÔ.ØœhŸm™mÒ+ÜŸ™×8Ñ8¸ÀÕCØ¤§¡Ò/ÜŸ™×1Ñ1°&¸!Õ<Ø¤× 0Ñ 0Ò0ÜŸ™×2Ñ2°6¸1Ô=Ø×&Ñ&Ô'9¼"¸V»*ÀaÓ'HÖIØ’[Ü—M‘M×-Ñ-¨f°aÖ8ñ9ô  ˜¤¤t˜}Õ-Ü# EÓ*ó 9‘��3Ü˜c¤C¬ ;Ô/Ü! #¤sÔ+Ù0°¸¸CÓ@˜Ù!.¨s°F¸AÓ!>�JØ˜CŸL™LÑ)×0Ñ0°Õ<Ü ¤XÔ.ØœhŸm™mÒ+ÜŸ™×8Ñ8¸ÀÕCØ¤§¡Ò/ÜŸ™×1Ñ1°&¸!Õ<Ø¤× 0Ñ 0Ò0ÜŸ™×2Ñ2°6¸1Ô=Ø×&Ñ&Ô'9¼"¸V»*ÀaÓ'HÖIØ’[Ü—M‘M×-Ñ-¨f°aÖ8ñ9ð  ˆ]Ü˜6Ÿ:™:›<Ó(ò 5�Ü—‘×)Ñ)¨&°!Õ4ñ5ð r(   c                 óP   •— t        |t        j                  «      r ‰| ||«       y y r:   )rÐ   rÒ   r*  )rë   rç   rM  rt  s      €r)   Úassoc_shapez,_process_dynamic_shapes.<locals>.assoc_shape¼  s"   ø€ Ü�aœŸ™Ô&Ù˜4  MÕ2ð 'r(   rO  rà   )rþ   rù   rú   r  rÐ   rŠ   rñ   rA   rP  r   r  r]   r3   rÏ   )r;  rä   rv  Ú$derived_constraint_with_phantom_rootÚphantom_root_nameÚdynamic_dimsrù   rú   rs  rc  rd  re  rf  rt  s         @@@@@@@@r)   Ú_process_dynamic_shapesrz     sý   ÿ€ ÷ ;àÐ¤ ^Ó!4¸Ò!9àˆ	Ü�.¤5¬$ -Ô0Ø,œ˜^Ó,¨]×-AÑ-AÓ-CÓDˆô ,7´tÓ+<€Gà-/€MØFHÐ)à$&€K÷Qð Qöf05ôd3ô ˜ ]°NÈhÕWà0Uò 
VÐ,Ø@×EÑE×JÑJÐØ Ò'ð 9@Ð@QÑ8RÐSTÑ8UÐ0Õ5ð
Vð  Ÿ™Ó(ò )ˆØ×Ñ˜<Õ(ð)ð Ðr(   c                 ó*  — i }t        | d„ ¬«      d   D ]|  }|€Œt        |t        «      rŒt        |t        «      rD|||j                  <   t        |t
        «      sŒG|j                  ||j                  j                  <   Œkt        |t        «      rŒ|J ‚ |S )Nc                 ó"   — t        | t        «      S r:   )rÐ   r+   )r<   s    r)   r>   z'_get_dim_name_mapping.<locals>.<lambda>Ú  s   € œ* Q¬Ó-€ r(   r  r   )r   rÐ   rB   r+   r    r^   r]   r   )rä   Úname_to_dimrƒ   s      r)   Ú_get_dim_name_mappingr~  Ô  s–   € ð €KÜØÙ-ôð ñ	ò -ˆð ˆ;àÜ�cœ3ÔØÜ˜œTÔ"Ø(+ˆK˜Ÿ™Ñ%Ü˜#œ{Õ+Ø14·±�˜CŸH™H×-Ñ-Ò.ä˜c¤8Õ,Ð,Ð,ð-ð Ðr(   r   c           
      ó$  ‡‡‡‡— ddl }ddlŠddlm}m} ddlm} 	 | j                  d«      d   j                  «       }i Š|j                  d«      D ]ù  }|j                  «       }|j                  d	|«      x}	r„|	j                  d«      }
d
\  }}|j                  d|«      x}rt        |j                  d«      «      }|j                  d|«      x}rt        |j                  d«      «      }t        |
||¬«      ‰|
<   Œ«|j                  d«      \  }
}‰j                  |«      }t!        |‰j"                  «      rt        |«      ‰|
<   Œõ|‰|
<   Œû t%        |«      Št'        «       }‰j)                  «       D ]¾  \  }}t!        |t        t*        t,        ‰j.                  f«      sJ ‚t!        |‰j.                  «      rE ||«      sJ ‚|‰|<   |j1                  t3        t5        t7        |j8                  «      «      «      «       t!        |t,        «      sŒš|j1                  |j:                  j<                  «       ŒÀ ‰j)                  «       D ]  \  }}|‰v rŒ||v rŒJ ‚ i Šˆˆˆˆfd„}t?        |||«      S # t        $ r} ||j                  d«      |‚d}~ww xY w)a©  
    When exporting with :func:`dynamic_shapes`, export may fail with a ConstraintViolation error if the specification
    doesn't match the constraints inferred from tracing the model. The error message may provide suggested fixes -
    changes that can be made to :func:`dynamic_shapes` to export successfully.

    Example ConstraintViolation error message::

        Suggested fixes:

            dim = Dim('dim', min=3, max=6)  # this just refines the dim's range
            dim = 4  # this specializes to a constant
            dy = dx + 1  # dy was specified as an independent dim, but is actually tied to dx with this relation

    This is a helper function that takes the ConstraintViolation error message and the original :func:`dynamic_shapes` spec,
    and returns a new :func:`dynamic_shapes` spec that incorporates the suggested fixes.

    Example usage::

        try:
            ep = export(mod, args, dynamic_shapes=dynamic_shapes)
        except torch._dynamo.exc.UserError as exc:
            new_shapes = refine_dynamic_shapes_from_suggested_fixes(
                exc.msg, dynamic_shapes
            )
            ep = export(mod, args, dynamic_shapes=new_shapes)

    r   Nrø   )Ú_is_supported_equivalencezSuggested fixes:r   z`Suggested fixes not found in error message given to refine_dynamic_shapes_from_suggested_fixes()ú
z(.*) = Dim\('(.*)'.*\))NNz!.* = Dim\('.*', min\=([0-9]+).*\)z.* = Dim\('.*'.*max\=([0-9]+)\)ry   z = c                 óD  •— |�t        |t        «      r|S |j                  ‰v rþ‰|j                     }t        |‰j                  «      r×t	        |«      ‰	v r‰	t	        |«         S t        t        |j                  «      «      }|j                  ‰v r‰|j                     }n|j                  ‰
v sJ ‚‰
|j                     }‰j                  j                  j                  ||«      \  }}|}|dk7  rt        |«      |z  }|dk7  r|t        |«      z   }|‰	t	        |«      <   |S |S t        |t        «      rn|j                  j                  ‰v rV|j                  ‰	v r‰	|j                     S |j                  ‰|j                  j                     «      }|‰	|j                  <   |S |S )Nr   r   )rÐ   rB   r    ÚExprrX   ÚnextÚiterÚfree_symbolsr3   ÚpolysÚ	polytoolsÚdivr^   r]   rY   )rë   rƒ   ÚdummyÚfixr\  r]   ÚmodulusÚ	remainderÚ_dimÚderived_dim_cacher}  Úshape_fixesrW   s            €€€€r)   Úapply_fixesz?refine_dynamic_shapes_from_suggested_fixes.<locals>.apply_fixesC  s  ø€ Øˆ;œ* S¬#Ô.ØˆJØ�\‰\˜[Ñ(Ø˜cŸl™lÑ+ˆCÜ˜#˜uŸz™zÔ*Ü�s“8Ð0Ñ0Ø,¬S°«XÑ6Ð6ä!¤$ s×'7Ñ'7Ó"8Ó9�Fà—{‘{ kÑ1Ø*¨6¯;©;Ñ7™à%Ÿ{™{¨kÑ9Ð9Ð9Ø*¨6¯;©;Ñ7˜à).¯©×)>Ñ)>×)BÑ)BÀ3ÈÓ)OÑ&�G˜YØ�CØ !’|Ü! '›l¨SÑ0˜Ø  A’~Ø!¤C¨	£NÑ2˜Ø25Ð%¤c¨#£hÑ/Ø�Jà�
Ü˜œ[Ô)¨c¯h©h×.?Ñ.?À;Ñ.NØ�|‰|Ð0Ñ0Ø(¨¯©Ñ6Ð6à—v‘v˜k¨#¯(©(×*;Ñ*;Ñ<Ó=�Ø26Ð! #§,¡,Ñ/Ø�Øˆ
r(   ) ÚrerW   rþ   rù   rú   rœ   r€  ÚsplitÚstripÚ	Exceptionrÿ   ÚmatchÚgrouprB   r   rV   rÐ   ÚNumberr~  r8  rI  r+   r^   rƒ  rÚ   rX   r„  r…  r†  r]   r    r  )r   rä   r’  rù   rú   r€  Úshape_fixes_msgÚexcr‹  r–  r3   r�   r‚   Ú	match_minÚ	match_maxr]  Úrootsr  Úcr‘  r�  r}  r�  rW   s                       @@@@r)   r   r   ê  sn  û€ ó@ ãç:ÝOðØŸ)™)Ð$6Ó7¸Ñ:×@Ñ@ÓBˆð €KØ×$Ñ$ TÓ*ò )ˆØ�i‰i‹kˆØ—H‘HÐ6¸Ó<Ð<ˆ5Ð<Ø—;‘;˜q“>ˆDØ#‰JˆD�$ØŸH™HÐ%IÈ3ÓOÐOˆyÐOÜ˜9Ÿ?™?¨1Ó-Ó.�ØŸH™HÐ%GÈÓMÐMˆyÐMÜ˜9Ÿ?™?¨1Ó-Ó.�Ü # D¨d¸Ô =ˆK˜ÒàŸ™ 5Ó)‰JˆD�$Ø—=‘= Ó&ˆDÜ˜$ §¡Ô-ä$'¨£I�˜DÒ!ð %)�˜DÒ!ð%)ô( (¨Ó7€Kô “e€EØ×!Ñ!Ó#ò '‰ˆˆ1Ü˜!œc¤4¬°e·j±jÐAÔBÐBÐBÜ�a˜Ÿ™Ô$Ù,¨QÔ/Ð/Ð/ØˆK˜‰NØ�I‰I”cœ$œt A§N¡NÓ3Ó4Ó5Ô6Ü�aœÕ%Ø�I‰I�a—f‘f—o‘oÕ&ð'ð ×!Ñ!Ó#ò .‰ˆˆ1Ø�KÒ 1¨¢:Ð-Ð-ð.ð 13Ð÷"ôH ˜{¨N¸NÓKÐKøôi ò ÙØ×'Ñ'Ønó
ð ð	ûðús   œ"I- É-	JÉ6J
Ê
J)F)GÚdataclassesr~   Úloggingrt   Úcollectionsr   Úenumr   r   Útypingr   r   r   r	   r
   rÒ   Útorch.utils._pytreer   r   r   r   r   r   r   r   r   Úexported_programr   rW   r   Útorch._guardsr   rœ   r   r   Ú__all__Ú	getLoggerr    r=  r   rA   r+   ra   r^   rX   rB   r   r$   r%   r&   rŠ   r   Ú	dataclassrŒ   r�   r¶   r¹   r¼   r   rñ   rð   r8  rß   r  r#  r%  r?  rT  rz  r~  r   r'   r(   r)   ú<module>rª     s  ðã Û Û Û 
Ý #ß ß @Õ @ã ÷
÷ 
õ 
õ .ñ Ýå$ßVò€ð €g×Ñ˜Ó!€ô
ˆtô 
ôBSˆ4ô BSôJ�ô ô"@
�$ô @
ðF ,0Àdò ˆcð ˜8 C™=ð °h¸s±mó ð: �=‰=€„Ø�_‰_€„
Ø×Ñ€„ð '+Àò	@Øð	@Ø˜s‘mð	@Ø19¸#±ð	@à
ˆ4�ˆ9Ñó	@ð ×Ñ÷ð ó ðð ×ÑôD
Ð#ó D
ó ðD
ðN ×Ñ÷ð ó ðð" ×Ñô
Ð*ó 
ó ð
ð4 ×Ñô
Ð*ó 
ó ð
ð  �;Ð 2Ð4FÐFÑG€
ð8$Øð8$à˜3 ˜* d¨8¡nÐ4Ñ5ð8$ð ð8$ð ��U˜3 ˜8‘_Ð$Ñ%ð	8$ð
 �uÐ/Ñ0Ñ1ð8$ð ˜U 8¨UÐ3EÑ-FÈÐ#PÑQÑRð8$ð ˜#˜x˜-Ñ(ð8$ð ˜‘]ó8$ð~  $ò	yØ
�3˜�8Ñ
ðyà
ðyð ðyð ˜‰}ð	yð
 	óyñxÀÀcÈ3ÀhÁó ÷ Hñ HòVðpXØ˜˜S˜‘>ðpXà˜$˜s C˜x™.¨%°©*°d¸3±iÀÐEÑFópXðfqØ˜˜S˜‘>ðqà˜$˜s C˜x™.¨%°©*°d¸3±iÀÐEÑFðqð 
ˆ*ÑóqðhØ˜$˜s C˜x™.¨%°©*°d¸3±iÀÐEÑFóð,}LØ	ð}Là˜$˜s C˜x™.¨%°©*°d¸3±iÐ?Ñ@ð}Lð ˆ4��S�‰>˜5 ™: t¨C¡yÐ0Ñ1ô}Lr(   