§
    Ÿ²ÅjÞ³  ã                   ó  — 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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j(        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e0dee1         dee1         fd„Z2e+j3        e2_3        e+j4        e2_4        e+j5        e2_5        dddœde0dee1         dee1         fd„Z6e j7         G d„ d¦  «        ¦   «         Z8e j7         G d„ de8¦  «        ¦   «         Z9e j7         G d„ d ¦  «        ¦   «         Z:e j7         G d!„ d"e8¦  «        ¦   «         Z;e j7         G d#„ d$e8¦  «        ¦   «         Z<ee9e;e<f         Z=d%e=d&ee1e1ged'         f         d(d)dee0ee1e1f         f         d*eed+                  d,eed'ed-         ef                  d.ee0d/f         d0ed'         fd1„Z>dd2œd3ed4e
f         d5e
d6e
d7ee0         d8e
f
d9„Z?dEd8ee0e
f         fd;„Z@ G d<„ d=¦  «        ZAd>„ ZBd?ee0e
f         d6eee0e
f         ee
         ee
         df         fd@„ZCd?ee0e
f         d6eee0e
f         ee
         ee
         df         d8ee=         fdA„ZDd6eee0e
f         ee
         ee
         df         fdB„ZEdCe0d6eee0e
f         ee
         ee
         f         d8eee0e
f         ee
         ee
         f         fdD„ZFdS )Fé    N)Údefaultdict)ÚautoÚEnum)	ÚAnyÚCallableÚDictÚListÚOptionalÚSetÚTupleÚ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                   óN   — e Zd ZdZ e¦   «         Z e¦   «         Z e¦   «         ZdS )Ú_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© ó    úLC:\Projects\Historical\venv\Lib\site-packages\torch/export/dynamic_shapes.pyr#   r#   +   s;   € € € € € ðð ð ˆ4‰6Œ6€DØˆT‰VŒV€FØˆd‰fŒf€G€G€Gr,   r#   c                   óX   — 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dS )Ú_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.numbersr2   )ÚnameÚmin_Úmax_r2   s       r-   Úreadablez_Dim.readable=   s§   € à5Ð5Ð5Ð5Ð5Ð5à�1Š9ˆ9ØˆDØ�6Š>ˆ>ØˆDØˆ<˜D˜LØ#˜4Ð#Ð#Ð#Ð#Øˆ<Ø/˜4Ð/Ð/¨Ð/Ð/Ð/Ð/Øˆ<Ø/˜4Ð/Ð/¨Ð/Ð/Ð/Ð/Ø7�tÐ7Ð7 DÐ7Ð7°Ð7Ð7Ð7Ð7r,   c                 ó–   ‡— t          ‰¦  «        t          urt          d‰› d| j        › d�¦  «        ‚|                      ˆ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©ÚclsrA   s    `r-   Ú__add__z_Dim.__add__M   sn   ø€ å�‰;Œ;�cÐ!Ð!Ý%ð_ Eð _ð _¨s¬|ð _ð _ð _ñô ð ð �{Š{Ð.Ð.Ð.Ð.Ñ/Ô/Ð/r,   c                 ó   — | |z   S r>   r+   rI   s     r-   Ú__radd__z_Dim.__radd__V   ó   € Ø�U‰{Ðr,   c                 ó–   ‡— t          ‰¦  «        t          urt          d‰› d| j        › d�¦  «        ‚|                      ˆfd„¦  «        S )NzAttempted to subtract z from r<   c                 ó   •— | ‰z
  S r>   r+   r?   s    €r-   rB   z_Dim.__sub__.<locals>.<lambda>`   rC   r,   rD   rI   s    `r-   Ú__sub__z_Dim.__sub__Y   sn   ø€ å�‰;Œ;�cÐ!Ð!Ý%ð_¨ð _ð _°c´lð _ð _ð _ñô ð ð �{Š{Ð.Ð.Ð.Ð.Ñ/Ô/Ð/r,   c                 ó2   — t          d| j        › d�¦  «        ‚)NzAttempted to negate zN. (Only increasing linear operations with integer coefficients are supported.))rG   r$   rI   s     r-   Ú__rsub__z_Dim.__rsub__b   s0   € Ý!ð[ 3¤<ð [ð [ð [ñ
ô 
ð 	
r,   c                 ó¢   ‡— t          ‰¦  «        t          us‰dk    rt          d‰› d| j        › d�¦  «        ‚|                      ˆ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-   rB   z_Dim.__mul__.<locals>.<lambda>o   rC   r,   rD   rI   s    `r-   Ú__mul__z_Dim.__mul__h   sv   ø€ å�‰;Œ;�cÐ!Ð! U¨a¢Z ZÝ%ð_¨ð _ð _°c´lð _ð _ð _ñô ð ð �{Š{Ð.Ð.Ð.Ð.Ñ/Ô/Ð/r,   c                 ó   — | |z  S r>   r+   rI   s     r-   Ú__rmul__z_Dim.__rmul__q   rN   r,   c                 óZ   — ddl m} t           | || j        ¦  «        ¦  «        ¦  «        S )Nr   )Úsympify)ÚsympyrZ   Ústrr$   )rJ   ÚfnrZ   s      r-   Ú_derived_namez_Dim._derived_namet   s8   € Ø!Ð!Ð!Ð!Ð!Ð!å�2�2�g�g˜cœlÑ+Ô+Ñ,Ô,Ñ-Ô-Ð-r,   c                 ó\   — t          |                      |¦  «        t          f| |dœ¦  «        S )N©Úrootr]   )Ú_DerivedDimr^   rF   )rJ   r]   s     r-   rH   z_Dim._derivey   s,   € Ý˜3×,Ò,¨RÑ0Ô0µ3°&À3ÈbÐ:QÐ:QÑRÔRÐRr,   N)r$   r%   r&   r'   Ústaticmethodr:   rK   rM   rQ   rS   rV   rX   r^   rH   r+   r,   r-   r/   r/   8   s¶   € € € € € ðð ð ð8ð 8ñ „\ð8ð0ð 0ð 0ðð ð ð0ð 0ð 0ð
ð 
ð 
ð0ð 0ð 0ðð ð ð.ð .ð .ð
Sð Sð Sð Sð Sr,   r/   c                   ó>   — e Zd ZdZed„ ¦   «         Zed„ ¦   «         ZdS )Ú
_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Ðr,   c                 ó   — | j         S r>   rg   ri   s    r-   Úmaxz_StaticDim.max‰   rl   r,   N)r$   r%   r&   r'   Úpropertyrk   rn   r+   r,   r-   re   re   }   sT   € € € € € ðð ð ðð ñ „Xðð ðð ñ „Xðð ð r,   re   c                   óD   — e Zd ZdZed„ ¦   «         Zed„ ¦   «         Zd„ ZdS )rb   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        }|dk    s#J d| j        › d|j        › d|j        › d�¦   «         ‚t          |¦  «        S )Nr   ©ÚIntegerr1   zExpected derived min value of z9 to be >= 0. Please specify an appropriate min value for ú (currently ú).)	r[   rs   r6   r2   ra   rk   r]   r$   rF   )rj   rs   r2   Ú_min_symintra   s        r-   rk   z_DerivedDim.minž   sÅ   € ð 	"Ð!Ð!Ð!Ð!Ð!à5Ð5Ð5Ð5Ð5Ð5àŒ9Œ=˜V˜GÐ#Ð#Ø�7ˆNà—g’g˜g˜g d¤i¤mÑ4Ô4Ñ5Ô5ˆØŒyˆØ˜aÒÐÐð'¨T¬]ð 'ð 'Ø;?¼=ð'ð 'àœ(ð'ð 'ð 'ñ  ÔÐõ
 �;ÑÔÐr,   c           
      óB  — ddl m} ddlm} | j        j        |u r|S |                       || j        j        ¦  «        ¦  «        }| j        }|t          j        dz
  k    s3J d| j	        › dt          j        dz
  › d|j	        › d|j        › d	�	¦   «         ‚t          |¦  «        S )
Nr   rr   r1   r   zExpected derived max value of z
 to be <= z.. Please specify an appropriate max value for rt   ru   )r[   rs   r6   r2   ra   rn   r]   ÚsysÚmaxsizer$   rF   )rj   rs   r2   Ú_max_symintra   s        r-   rn   z_DerivedDim.max²   sÚ   € ð 	"Ð!Ð!Ð!Ð!Ð!à5Ð5Ð5Ð5Ð5Ð5àŒ9Œ=˜FÐ"Ð"ØˆMà—g’g˜g˜g d¤i¤mÑ4Ô4Ñ5Ô5ˆØŒyˆØ�cœk¨A™oÒ-Ð-Ð-ð'¨T¬]ð 'ð 'ÅcÄkÐTUÁoð 'ð 'Ø;?¼=ð'ð 'àœ(ð'ð 'ð 'ñ .Ô-Ð-õ
 �;ÑÔÐr,   c                 ór   ‡ ‡— t          ‰                      ‰¦  «        t          f‰ j        ˆˆ fd„dœ¦  «        S )Nc                 ó@   •—  ‰‰                      | ¦  «        ¦  «        S r>   )r]   )r@   r]   rj   s    €€r-   rB   z%_DerivedDim._derive.<locals>.<lambda>Í   s   ø€ °°°4·7²7¸1±:´:±´€ r,   r`   )rb   r^   rF   ra   )rj   r]   s   ``r-   rH   z_DerivedDim._deriveÆ   sH   øø€ õ Ø×Ò˜rÑ"Ô"ÝˆFØ”YÐ&>Ð&>Ð&>Ð&>Ð&>Ð?Ð?ñ
ô 
ð 	
r,   N)r$   r%   r&   r'   ro   rk   rn   rH   r+   r,   r-   rb   rb   Ž   sc   € € € € € ðð ð ð ð  ñ „Xð ð& ð ð  ñ „Xð ð&
ð 
ð 
ð 
ð 
r,   rb   ©rk   rn   r7   rk   rn   c                óV  — ddl m} |€dn|}|€|n|}||k    sJ d|› d|› �¦   «         ‚|                      ¦   «         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   r1   Nz(Cannot create Dim with inconsistent min=r5   z)Dim name must be a valid identifier, got r}   r   r$   Ú__main__)
r6   r2   Úisidentifierr/   rF   ÚgetattrÚinspectÚ	getmoduleÚstackr%   )r7   rk   rn   r2   Ú_minÚ_maxÚdims          r-   r   r   Ñ   sÒ   € ð  2Ð1Ð1Ð1Ð1Ð1à�ˆ1ˆ1 €DØ�[ˆ6ˆ6 c€DØ�$Š;ˆ;ˆ;ÐSÀ3ÐSÐSÈcÐSÐS‰;Œ;ˆ;Ø×ÒÑÔÐRÐRÐ RÈDÐ RÐ RÑRÔRÐÝ
ˆt•c�V T°$Ð7Ð7Ñ
8Ô
8€CÝÝÔ�'œ-™/œ/¨!Ô,¨QÔ/Ñ0Ô0°*¸jñô €C„Nð €Jr,   Únamesc                 ó>   ‡ ‡— t          ˆˆ fd„|D ¦   «         ¦  «        S )z4
    Util to create multiple :func:`Dim` types.
    c              3   ó<   •K  — | ]}t          |‰‰¬ ¦  «        V — ŒdS )r}   N)r   )Ú.0r7   rn   rk   s     €€r-   ú	<genexpr>zdims.<locals>.<genexpr>÷   s2   øè è € Ð?Ð?°•�T˜s¨Ð,Ñ,Ô,Ð?Ð?Ð?Ð?Ð?Ð?r,   )Útuple)rk   rn   rˆ   s   `` r-   r    r    ó   s,   øø€ õ Ð?Ð?Ð?Ð?Ð?¸Ð?Ñ?Ô?Ñ?Ô?Ð?r,   c                   ó(   — e Zd ZU dZeed<   eed<   dS )Ú_ConstraintTargetz2
    This represents input tensor dimensions.
    Út_idr‡   N)r$   r%   r&   r'   rF   Ú__annotations__r+   r,   r-   r�   r�   ú   s.   € € € € € € ðð ð €I€I�IØ	€H€H�H€H€Hr,   r�   c                   ód   — 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dS )Ú_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.
    r7   r   Úconstraint_ranger   Nc                 óº   — ddl m} ddlm} ddlm} |€|} || j        j         |||¬¦  «        z  d¬¦  «        }t          | j	        | j
        | j        |¦  «        S )Nr   ©r   r1   ©ÚValueRanges©ÚlowerÚupperF©ÚvrÚ	warn_only)Ú%torch.fx.experimental.symbolic_shapesr   r6   r2   Útorch.utils._sympy.value_rangesr˜   r”   r�   r“   r�   r‡   r7   )rj   rš   r›   r   r2   r˜   r”   s          r-   Ú_clone_with_rangez_Constraint._clone_with_range  s    € àPÐPÐPÐPÐPÐPØ5Ð5Ð5Ð5Ð5Ð5Ø?Ð?Ð?Ð?Ð?Ð?àˆ=ØˆEà1Ð1ØÔ$Ô'¨+¨+¸EÈÐ*OÑ*OÔ*OÑOØð
ñ 
ô 
Ðõ ØŒIØŒHØŒIØñ	
ô 
ð 	
r,   c                 ó.   — |                       |¬¦  «        S )N©rš   ©r¡   ©rj   rš   s     r-   Ú__ge__z_Constraint.__ge__$  ó   € Ø×%Ò%¨EÐ%Ñ2Ô2Ð2r,   c                 ó4   — |                       |dz   ¬¦  «        S )Nr   r£   r¤   r¥   s     r-   Ú__gt__z_Constraint.__gt__'  ó   € Ø×%Ò%¨E°A©IÐ%Ñ6Ô6Ð6r,   c                 ó.   — |                       |¬¦  «        S )N©r›   r¤   ©rj   r›   s     r-   Ú__le__z_Constraint.__le__*  r§   r,   c                 ó4   — |                       |dz
  ¬¦  «        S )Nr   r¬   r¤   r­   s     r-   Ú__lt__z_Constraint.__lt__-  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.)Ú	TypeErrorri   s    r-   Ú__bool__z_Constraint.__bool__0  s   € õ
 ð7ñ
ô 
ð 	
r,   c                 ó`   — | j         | j        | j        j        j        | j        j        j        dœS ©N)r�   r‡   rk   rn   ©r�   r‡   r”   r�   rš   r›   ri   s    r-   Úserializable_specz_Constraint.serializable_spec;  s5   € ð ”IØ”8ØÔ(Ô+Ô1ØÔ(Ô+Ô1ð	
ð 
ð 	
r,   )r   N)r$   r%   r&   r'   r\   r‘   r¡   r¦   r©   r®   r°   r³   ro   r·   r+   r,   r-   r“   r“     s±   € € € € € € ðð ð €I€I�IØ.Ð.Ð.Ñ.ð
ð 
ð 
ð 
ð(3ð 3ð 3ð7ð 7ð 7ð3ð 3ð 3ð7ð 7ð 7ð	
ð 	
ð 	
ð ð
ð 
ñ „Xð
ð 
ð 
r,   r“   c                   ó2   — e Zd ZU dZeed<   ded<   eed<   dS )Ú_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.
    r7   r   r”   ÚvalN)r$   r%   r&   r'   r\   r‘   rF   r+   r,   r-   r¹   r¹   L  s:   € € € € € € ð	ð 	ð €I€I�IØ.Ð.Ð.Ñ.Ø	€H€H�H€H€Hr,   r¹   c                   ób   — 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dS )	Ú_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.
    r7   r   r”   ra   r]   c                 ó`   — | j         | j        | j        j        j        | j        j        j        dœS rµ   r¶   ri   s    r-   r·   z$_DerivedConstraint.serializable_specn  s5   € ð ”IØ”8ØÔ(Ô+Ô1ØÔ(Ô+Ô1ð	
ð 
ð 	
r,   N)r$   r%   r&   r'   r\   r‘   r   r�   r¹   r   ro   r·   r+   r,   r-   r¼   r¼   ^  sp   € € € € € € ðð ð €I€I�IØ.Ð.Ð.Ñ.Ø
Ð! <Ð/Ô
0Ð0Ð0Ñ0Ø€L€L�Làð
ð 
ñ „Xð
ð 
ð 
r,   r¼   c                   ó(   — e Zd ZdZed„ ¦   «         ZdS )Ú_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                 ó    — | j         | j        dœS )N©r�   r‡   rÁ   ri   s    r-   r·   z$_RelaxedConstraint.serializable_spec‚  s   € ð ”IØ”8ð
ð 
ð 	
r,   N)r$   r%   r&   r'   ro   r·   r+   r,   r-   r¿   r¿   y  s9   € € € € € ðð ð ð
ð 
ñ „Xð
ð 
ð 
r,   r¿   Ú
constraintÚget_sourcesr   Ú	shape_envr   Úsource_pairs)r   r   Úderived_equalities)r   r   Úphantom_symbolsr   Úrelaxed_sourcesc                 ó  ‡—  || j         | j        ¦  «        }|sdS |^Š}	|                     ˆfd„|	D ¦   «         ¦  «         t          | t          ¦  «        r`| j        |v r?|| j                 \  }
} ||
|¦  «        }	|                     ˆfd„|	D ¦   «         ¦  «         dS | j         | j        f|| j        <   dS t          | t          ¦  «        �r	t          | j        t          ¦  «        s' || j        j         | j        j        ¦  «        d         }n§| j        j        |v r|| j        j                 }n†| 	                    | j        j
        t          j        j                             | j        j        ¦  «        t          j        j        j        j        j        | j        j        ¬¦  «        }||| j        j        <   | j        }|                     ‰||f¦  «         dS t          | t.          ¦  «        r|                     ‰¦  «         dS dS )z¤
    Updates `source_pairs`, `derived_equalities`, and `phantom_symbols` (which become
    fields of `EqualityConstraint`) based on a given input `constraint`.
    Nc              3   ó    •K  — | ]}‰|fV — Œ	d S r>   r+   ©r‹   Úother_sourceÚsources     €r-   rŒ   z&_process_equalities.<locals>.<genexpr>£  s(   øè è € ÐQÐQ°<˜ Ð.ÐQÐQÐQÐQÐQÐQr,   c              3   ó    •K  — | ]}‰|fV — Œ	d S r>   r+   rË   s     €r-   rŒ   z&_process_equalities.<locals>.<genexpr>¨  s9   øè è € ð  ð  Ø+7�˜Ð&ð ð  ð  ð  ð  ð  r,   r   )rº   rÍ   Údynamic_dimÚconstraint_dim)r�   r‡   ÚextendÚ
isinstancer“   r7   r¼   ra   r¹   Úcreate_symbolrº   ÚtorchÚ_dynamorÍ   ÚConstantSourceÚfxÚexperimentalÚsymbolic_shapesÚ
DimDynamicr*   r”   r]   Úappendr¿   Úadd)rÂ   rÃ   rÄ   rˆ   rÅ   rÆ   rÇ   rÈ   ÚsourcesÚother_sourcesÚshared_t_idÚ
shared_dimra   r]   rÍ   s                 @r-   Ú_process_equalitiesrá   �  s8  ø€ ð ˆk˜*œ/¨:¬>Ñ:Ô:€GØð Øˆà$Ð€Fˆ]ð ×ÒÐQÐQÐQÐQÀ=ÐQÑQÔQÑQÔQÐQÝ�*�kÑ*Ô*ð !$ØŒ?˜eÐ#Ð#Ø&+¨J¬OÔ&<Ñ#ˆK˜Ø'˜K¨°ZÑ@Ô@ˆMØ×Òð  ð  ð  ð  Ø;Hð ñ  ô  ñ ô ð ð ð ð '1¤o°z´~Ð%FˆE�*”/Ñ"Ð"Ð"Ý	�JÕ 2Ñ	3Ô	3ñ $å˜*œ/­<Ñ8Ô8ð 	=à�;˜zœÔ3°Z´_Ô5HÑIÔIÈ!ÔLˆDˆDð ŒÔ# Ð6Ð6Ø& z¤Ô';Ô<��ð !×.Ò.Ø"œÔ+Ý œ=Ô/×>Ò>¸z¼Ô?SÑTÔTÝ %¤Ô 5Ô EÔ PÔ XØ#-¤?Ô#Cð	 /ñ ô �ð 9=� 
¤Ô 4Ñ5àŒ]ˆð 	×!Ò! 6¨4°Ð"4Ñ5Ô5Ð5Ð5Ð5Ý	�JÕ 2Ñ	3Ô	3ð $Ø×Ò˜FÑ#Ô#Ð#Ð#Ð#ð$ð $r,   ©Ú	tree_nameÚfunc.ÚtreeÚdynamic_shapesrã   Úreturnc                óN  ‡ ‡‡	‡
‡‡‡— d„ Šˆˆ ˆfd„Š	 t          ‰|g|¢R d‰iŽS # t          $ rv}d|j        d         v ra|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 r5t          ‰t          |                              |¦  «        d         g|¢R d‰iŽS  ‰| |g|¢R Ž S )Nr   rë   )r   r   r   Ú
flatten_fn)Úpathrê   ræ   ÚtypÚfrä   rë   s       €€€r-   rð   z_tree_map_with_path.<locals>.fè  s‡   ø€ Ý˜QÑÔˆà•/Ð!Ð!õ &ØÝ Ô$×/Ò/°Ñ2Ô2°1Ô5ðð  ðð ð ð  ð	ð ð ð �4˜˜aÐ1 .Ð1Ð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   sX   € à�D�=�=Ý% g¨a¤jÑ1Ô1Ð1Ø�T¥5˜MÐ)Ð)Ø"˜?˜?˜?Ý& q™>œ>Ð)Ý$Ð%C¸EÐ%CÐ%CÑDÔDÐDr,   c                 óF   •— 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	  sQ   ø€ ØFÐFÐFÐFÐFÐFÐFÐFà�iØ!Ô/ØkÀ9ÐkÐkÐfiÐkÐkØ9ðñ ô ð r,   c                 óÊ  •‡— t          |¦  «        }t          | t          ¦  «        rd S t          |t          ¦  «        r ‰d‰› |› d| j        › d|› d�¦  «         | j        |j        k    r# ‰d‰› |› d| j        › d|› d|j        › �	¦  «         t	          | j        ¦  «        t	          |j        ¦  «        k    r> ‰d‰› |› dt	          | j        ¦  «        › d|› dt	          |j        ¦  «        › d�
¦  «         | j        t          u rˆt          | j        ¦  «        t          |j        ¦  «        k    r# ‰d‰› |› d| j        › d|› d|j        › �	¦  «         t          t          |j        |j        ¦  «        ¦  «        Šˆfd	„| j        D ¦   «         }n|j        }t          t          | j        |¦  «        ¦  «        D ].\  }\  }} ‰	||| ‰
| j        | j        |¦  «        gz   ¦  «         Œ/d S )
Nú`z` is a z, but `dynamic_shapesz` is notz` has z elements, but `dynamic_shapesz	 elementsz` has keys c                 ó    •— g | ]
}‰|         ‘ŒS r+   r+   )r‹   ÚkÚ_remaps     €r-   ú
<listcomp>z9_tree_map_with_path.<locals>._compare.<locals>.<listcomp>1  s   ø€ Ð4UÐ4UÐ4UÀ1°V¸A´YÐ4UÐ4UÐ4Ur,   )r   rÒ   r   rE   ÚlenÚchildren_specsró   Úsortedr÷   ÚzipÚ	enumerate)rå   ræ   rî   Úrendered_pathÚdynamic_shapes_children_specsrø   Útree_Údynamic_shapes_r	  Ú_comparerù   r  rã   s           @€€€€r-   r  z%_tree_map_with_path.<locals>._compare  sü  øø€ õ !' t¡¤�Ý˜d¥HÑ-Ô-ð Ø�FÝ˜n­hÑ7Ô7ð Ø(Ð(ðF˜Ið F }ð Fð F¸T¼Yð Fð FØ.;ðFð Fð Fñô ð ð ”9 Ô 3Ò3Ð3Ø(Ð(ðZ˜Ið Z }ð Zð Z¸T¼Yð Zð ZØ.;ðZð ZØDRÔDWðZð Zñô ð õ �tÔ*Ñ+Ô+­s°>Ô3PÑ/QÔ/QÒQÐQØ(Ð(ðq˜Ið q }ð qð q½CÀÔ@SÑ<TÔ<Tð qð qØ.;ðqð qÝCFÀ~ÔGdÑCeÔCeðqð qð qñô ð ð ”9¥Ð$Ð$å˜dœlÑ+Ô+­v°nÔ6LÑ/MÔ/MÒMÐMØ,Ð,ðe 	ð e¨=ð eð eÀTÄ\ð eð eØ2?ðeð eØLZÔLbðeð eñô ð õ "Ý˜NÔ2°NÔ4QÑRÔRñô �Fð 5VÐ4UÐ4UÐ4UÈÌÐ4UÑ4UÔ4UÐ1Ð1à4BÔ4QÐ1Ý3<Ý˜Ô+Ð-JÑKÔKñ4ô 4ð ð Ñ/�AÑ/˜˜ð �HØØ'Ø   T¤Y°´¸aÑ @Ô @ÐAÑAñô ð ð ðð r,   ©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  È  si  øøøøøøø€ ð26ð 6ð 6ð2ð 2ð 2ð 2ð 2ð 2ð 2ðJÝ! ! TÐL¨NÐLÐLÐLÀGÐLÐLÐLøÝð Hð Hð HØ˜œ œÐ"Ð"ð "ÐWÐWÐ#WÑWÔW�>ØÐWÐWÐWÑWÔW�9ðEð Eð Eðð ð ð ð ð)ð )ð )ð )ð )ð )ð )ð )õV (¨°gÐ>Ñ>Ô>‰LˆAˆyØ,ð 9ð 9�
Ý%1°*¸gÑ%FÔ%FÑ"��?Ø�˜ O°RÑ8Ô8Ð8Ð8ØøøøøðQHøøøs   “$ ¤
B$®A1BÂB$Fc                 ó$  — t          | t          ¦  «        r|                      ¦   «         } |sdt          | 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(  D  s—   € õ �!•_Ñ%Ô%ð Ø�HŠH‰JŒJˆØð 9õ ˜!�UœXœ_Ñ-Ô-ð&�GÔ˜aœiÑ(Ô(Ð(åÔ" 1Ñ%Ô%ð 	ð
 "Ð-��°2ˆØˆyŒ~˜tÐ. vÐ.Ð.Ô8Ð8Ø€Kr,   c                   ó2   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zdd„ZdS )	ÚShapesCollectionab  
    Builder for dynamic_shapes.
    Used to assign dynamic shape specifications to tensors that appear in inputs.

    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 | _         d S r>   )Ú_shapesri   s    r-   Ú__init__zShapesCollection.__init__f  s   € ØˆŒˆˆr,   c                 ó  — t          |t          j        ¦  «        sJ dt          |¦  «        › �¦   «         ‚t	          |¦  «        }|| j        v r%| j        |         }||k    sJ d|› d|› �¦   «         ‚d S || j        t	          |¦  «        <   d S )Nz'Cannot assign shape to non-tensor type z1Shapes assigned to tensor do not match: expected z, got )rÒ   rÔ   ÚTensorrE   Úidr,  )rj   rê   Úshaper�   Ú_shapes        r-   Ú__setitem__zShapesCollection.__setitem__i  s¬   € ÝØ�uŒ|ñ
ô 
ð 	?ð 	?à>µT¸!±W´WÐ>Ð>ñ	?ô 	?ð 
õ �!‰uŒuˆØ�4”<ÐÐØ”\ $Ô'ˆFà˜’��ØXÀ6ÐXÐXÐQVÐXÐXñ  ”���ð #(ˆDŒL�˜A™œÑÐÐr,   c                 óP   — t          |¦  «        }|| j        v r| j        |         S d S r>   )r0  r,  )rj   rê   r�   s      r-   Ú__getitem__zShapesCollection.__getitem__w  s,   € Ý�!‰uŒuˆØ�4”<ÐÐØ”< Ô%Ð%à�4r,   c                 ó*   — t          | j        ¦  «        S r>   )r  r,  ri   s    r-   Ú__len__zShapesCollection.__len__~  s   € Ý�4”<Ñ Ô Ð r,   Nc                 óÒ   ‡ ‡— t          ¦   «         Šˆ ˆfd„}t          |||¦  «        }t          ||¦  «        }t          ˆfd„‰ j        D ¦   «         ¦  «        rt          d¦  «        ‚|S )z*
        Generate dynamic_shapes.
        c                 ó|   •— t          |¦  «        }|‰j        v r"‰                     |¦  «         ‰j        |         S d S r>   )r0  r,  rÜ   )rî   rê   r�   rj   Út_idss      €€r-   Ú
find_shapez3ShapesCollection.dynamic_shapes.<locals>.find_shapeˆ  s<   ø€ Ý�a‘5”5ˆDØ�t”|Ð#Ð#Ø—	’	˜$‘”�Ø”| DÔ)Ð)à�tr,   c              3   ó    •K  — | ]}|‰vV — Œ	d S r>   r+   )r‹   r�   r:  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  )rj   Úmr  r&  r;  Úcombined_argsræ   r:  s   `      @r-   ræ   zShapesCollection.dynamic_shapes�  s–   øø€ õ
 ‘”ˆð	ð 	ð 	ð 	ð 	ð 	õ & a¨¨vÑ6Ô6ˆÝ,¨Z¸ÑGÔGˆÝÐ:Ð:Ð:Ð:¨T¬\Ð:Ñ:Ô:Ñ:Ô:ð 	Ýðdñô ð ð
 Ðr,   r>   )	r$   r%   r&   r'   r-  r3  r5  r7  ræ   r+   r,   r-   r*  r*  T  sn   € € € € € ðð ð"ð ð ð(ð (ð (ðð ð ð!ð !ð !ðð ð ð ð ð r,   r*  c                  ó>   — d} t                                | ¦  «         d S )NzTUsing None as a dynamic shape dimension is deprecated. Please use Dim.STATIC instead)ÚlogÚwarning)r  s    r-   Ú%_warn_on_None_dynamic_shape_dimensionrD  ›  s&   € ð	(ð õ
 ‡K‚K�ÑÔÐÐÐr,   r@  c                 ó.  ‡‡‡‡	‡
— ddl mŠmŠ |�t          |¦  «        dk    rdS t	          |t
          t          f¦  «        r* t          |¦  «        |                      ¦   «         ¦  «        } i Šˆˆˆfd„Š	ˆˆˆ	fd„Š
t	          |t          t
          t          f¦  «        sJ ‚t	          |t          ¦  «        rÇt          | 
                    ¦   «         ¦  «        }t          |  
                    ¦   «         ¦  «        }t          |¦  «        t          |¦  «        k    red|› d|› d�}t          | ¦  «        d	k    r1|d         |vr't	          | |d                  t          ¦  «        r|d
z  }n|dz  } ‰‰j        |d¬¦  «        ‚ˆˆˆ
fd„}t          || |d¬¦  «         dS )z†
    Checks the dynamic_shapes specification for correctness,
    using combined args + kwargs as reference for inputs structure.
    r   rû   Nc           
      ód  •— | j         ‰v r�‰| j                  \  }}| j        |k    s| j        |k    rgt                               | j         ||¦  «        }t                               | j         | j        | j        ¦  «        } ‰‰j        d|› d|› d| › d�¦  «        ‚d S | j        | j        f‰| j         <   d S )NzFound different definitions z and z! for the same symbolic dimension ú!)r$   rk   rn   r/   r:   r  )r‡   r8   r9   Úthis_Úthat_rü   rý   Úboundss        €€€r-   Úcheck_same_boundsz0_check_dynamic_shapes.<locals>.check_same_boundsµ  sÔ   ø€ ØŒ<˜6Ð!Ð!Ø ¤Ô-‰JˆD�$ØŒw˜$Šˆ #¤'¨T¢/ /ÝŸš c¤l°D¸$Ñ?Ô?�ÝŸš c¤l°C´G¸S¼WÑEÔE�Ø�iØ!Ô/ð>°5ð >ð >¸uð >ð >Ø7:ð>ð >ð >ñô ð ð #2 /ð %(¤G¨S¬WÐ#5ˆF�3”<Ñ Ð Ð r,   c                 ó  •— t          |t          ¦  «        r—|                     ¦   «         D ]€\  }}t          |t          ¦  «        r ‰|¦  «         Œ&|€t	          ¦   «          Œ7t          |t
          t          f¦  «        s- ‰‰j        d|› d|› dt          | ¦  «        › d|› d�	d¬¦  «        ‚Œ�d S t          |t          t          f¦  «        r’t          |¦  «        D ]€\  }}t          |t          ¦  «        r ‰|¦  «         Œ&|€t	          ¦   «          Œ7t          |t
          t          f¦  «        s- ‰‰j        d|› d|› dt          | ¦  «        › d	|› d�	d¬¦  «        ‚Œ�d S |�' ‰‰j        d
|› dt          | ¦  «        › d�d¬¦  «        ‚d S )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/   rD  rF   r#   r  r   r�   rô   r  )rî   Útensorr1  rø   r‡   rü   rý   rK  s        €€€r-   Úcheck_symbolsz,_check_dynamic_shapes.<locals>.check_symbolsÃ  sX  ø€ Ý�e�TÑ"Ô"ð %	ØŸ+š+™-œ-ð ð ‘��3Ý˜c¥4Ñ(Ô(ð Ø%Ð% cÑ*Ô*Ð*Ð*Ø�[Ý9Ñ;Ô;Ð;Ð;Ý$ S­3µ¨/Ñ:Ô:ð Ø#˜)Ø%Ô3ð3Àð 3ð 3ÐZ_ð 3ð 3Ý7=¸d±|´|ð3ð 3ð %(ð3ð 3ð 3ð #>ðñ ô ð ððð õ ˜¥¥t˜}Ñ-Ô-ð 	Ý# EÑ*Ô*ð ð ‘��3Ý˜c¥4Ñ(Ô(ð Ø%Ð% cÑ*Ô*Ð*Ð*Ø�[Ý9Ñ;Ô;Ð;Ð;Ý$ S­3µ¨/Ñ:Ô:ð Ø#˜)Ø%Ô3ð2°ð 2ð 2È5ð 2ð 2Ý7=¸d±|´|ð2ð 2ð $'ð2ð 2ð 2ð #>ðñ ô ð ððð ð ÐØ�)ØÔ+ða°ð að aÕU[Ð\`ÑUaÔUað að að 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 ‰| ||¦  «         d S |�<t          | ¦  «        } ‰‰j        d|› d|› dt          |¦  «        › d|› d�	d¬¦  «        ‚d S )NzCannot associate shape rM  z` to non-tensor type z at `inputsz` (expected None)rþ   rÿ   )rÒ   rÔ   r/  r   r  rE   )rî   rê   Údynamic_shaper  rü   rý   rP  s       €€€r-   Úcheck_shapez*_check_dynamic_shapes.<locals>.check_shape  s¹   ø€ Ý�a�œÑ&Ô&ð 
	ØˆM˜$  =Ñ1Ô1Ð1Ð1Ð1àÐ(Ý & t¡¤�Ø�iØ!Ô/ð_¨mð _ð _ÐZgð _ð _Ý*.¨q©'¬'ð_ð _Ø>Kð_ð _ð _à9ð	ñ ô ð ð )Ð(r,   Úinputsrâ   )r  rü   rý   r  rÒ   r�   rô   rE   Úvaluesró   Úkeysr  r  r  )r@  ræ   Úgot_keysÚexpected_arg_namesr  rS  rü   rý   rJ  rK  rP  s         @@@@@r-   Ú_check_dynamic_shapesrY  ¤  s=  øøøøø€ ð ;Ð:Ð:Ð:Ð:Ð:Ð:Ð:àÐ¥ ^Ñ!4Ô!4¸Ò!9Ð!9ØˆÝ�.¥5­$ -Ñ0Ô0ð EØ,�˜^Ñ,Ô,¨]×-AÒ-AÑ-CÔ-CÑDÔDˆà)+€Fð6ð 6ð 6ð 6ð 6ð 6ð 6ð&ð &ð &ð &ð &ð &ð &õP �n¥t­UµDÐ&9Ñ:Ô:Ð:Ð:Ð:Ý�.¥$Ñ'Ô'ð Ý˜×+Ò+Ñ-Ô-Ñ.Ô.ˆÝ! -×"4Ò"4Ñ"6Ô"6Ñ7Ô7ÐÝ�(ÑÔ�vÐ&8Ñ9Ô9Ò9Ð9ð.Ø);ð.ð .à!)ð.ð .ð .ð õ �MÑ"Ô" aÒ'Ð'Ø& qÔ)°Ð9Ð9Ý˜}Ð-?ÀÔ-BÔCÅTÑJÔJð :ð ðYñ��ð
 ðVñ�ð �)ØÔ+¨SÐ<Wðñ ô ð ðð ð ð ð ð ð õ ˜ ]°NÈhÐWÑWÔWÐWÐWÐWr,   c                 ó  ‡‡‡‡	‡
‡‡‡— ddl mŠmŠ |�t          |¦  «        dk    rg S t	          |t
          t          f¦  «        r* t          |¦  «        |                      ¦   «         ¦  «        } t          t          ¦  «        Ši Š
g Š	g Šˆˆˆ	ˆ
ˆfd„Šˆˆˆfd„Šˆfd„}t          || |d¬¦  «         ‰	D ]%}|j        j        }|‰v r‰|         d         |_        Œ&‰                     ¦   «         D ]}‰                     |¦  «         Œ‰S )	zT
    Reads the dynamic_shapes specification and produces a list of constraints.
    r   rû   Nc                 ó  •‡ ‡‡‡
‡— dd l Š
ddlm} ddlmŠ ddlm} ˆˆˆ ˆˆ
ˆˆfd„}t          ‰ t          ¦  «        �r‰ j	        }|j
        ‰v r.‰|j
                 d         }t          |j        |j        ¦  «        }n`|j
        ‰vrJt          |j
         | ||j        |j        ¬¦  «        d¬¦  «         |¦   «         ¬	¦  «        }|‰|j
        <   n‰|j
                 }t#          t%          ‰¦  «        ‰‰ j
         | |‰ j        ‰ j        ¬¦  «        d¬¦  «        |‰ j        ¦  «        }	t          |t          ¦  «        r‰                     |	¦  «         nµt          ‰ t*          ¦  «        rEt-          t%          ‰¦  «        ‰‰ j
         | |‰ j        ‰ j        ¬¦  «        d¬¦  «        ¦  «        }	n[t          ‰ t0          ¦  «        sJ ‚t-          t%          ‰¦  «        ‰‰ j
         | |‰ j        ‰ j        ¬¦  «        d¬¦  «        ¦  «        }	|	S )
Nr   r–   )Ú	try_solver—   c                  óF  •— ‰                      ‰j        j        d¬¦  «        } ‰                     | ¦  «        } ‰	‰                     |‰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   ra   r$   r]   ÚEqr1  rF   ÚCONSTRAINT_VIOLATION)
ÚsymbolÚexprÚsolutionrü   rý   r‡   rø   r[   rO  r\  s
      €€€€€€€r-   Ú
root_valuezB_process_dynamic_shapes.<locals>.to_constraint.<locals>.root_value5  sÑ   ø€ ð —\’\ #¤(Ô"3¸T�\ÑBÔBˆFØ—6’6˜&‘>”>ˆDØ �y §¢¨$°´¸Q´Ñ!@Ô!@À&ÑIÔIˆHØÐ#Ý˜8 Aœ;Ñ'Ô'Ð'à�iØ!Ô6ðH að Hð H¨V¬\¸!¬_ð Hð HØ#'ðHð HØ17ðHð Hð Hñô ð r,   r™   Frœ   )r7   r”   rº   )r[   rŸ   r   Útorch.utils._sympy.solver\  r    r˜   rÒ   rb   ra   r$   r�   r�   r‡   r¹   rk   rn   r¼   r0  r]   rÛ   re   r“   rh   r/   )r‡   rO  rø   r   r˜   rd  Údim_rootÚroot_constraintra   rÂ   r[   r\  rü   rý   Ú%derived_constraints_with_phantom_rootÚphantom_rootsÚsymbolss   ```       @@€€€€€r-   Úto_constraintz._process_dynamic_shapes.<locals>.to_constraint.  s­  øøøøøø€ ØˆˆˆàPÐPÐPÐPÐPÐPØ6Ð6Ð6Ð6Ð6Ð6Ø?Ð?Ð?Ð?Ð?Ð?ð	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	õ �c�;Ñ'Ô'ñ :	ð ”xˆHØÔ  GÐ+Ð+à")¨(Ô*;Ô"<¸QÔ"?�Ý(Ø#Ô(Ø#Ô'ñô ��ð Ô"¨-Ð7Ð7å#Ø!Ô*Ø%;Ð%;Ø&˜;¨X¬\ÀÄÐNÑNÔNØ"'ð&ñ &ô &ð #˜
™œðñ ô �ð 48�˜hÔ/Ñ0Ð0à$ XÔ%6Ô7�Ý+Ý�6‘
”
ØØ”Ø&Ð&Ø"�{¨¬¸¼Ð@Ñ@Ô@Ø#ðñ ô ð Ø”ñ
ô 
ˆJõ ˜$¥Ñ-Ô-ð Ið 6×<Ò<¸ZÑHÔHÐHøÝ˜�ZÑ(Ô(ð 	Ý$Ý�6‘
”
ØØ”Ø&Ð&Ø"�{¨¬¸#¼)ÐDÑDÔDÐPUðñ ô ñ	ô ˆJˆJõ ˜c¥4Ñ(Ô(Ð(Ð(Ð(Ý$Ý�6‘
”
ØØ”Ø&Ð&Ø"�{¨¬¸¼Ð@Ñ@Ô@ÈEðñ ô ñ	ô ˆJð Ðr,   c                 óÌ  •— d„ }t          ¦   «         |_        t          ¦   «         |_        t          ¦   «         |_        t          ¦   «         |_        t          ¦   «         |_        t          |t          ¦  «        �r…|                     ¦   «         D �]m\  }}t          |t          t          f¦  «        rPt          |t          ¦  «        r ||||¦  «        } ‰	|||¦  «        }‰|j                                      |¦  «         Œrt          |t          ¦  «        rÄ|t          j        k    r!t          j                             ||¦  «         na|t          j        k    r!t          j                             ||¦  «         n0|t          j        k    r t          j                             ||¦  «         ‰                     t-          t/          |¦  «        |¦  «        ¦  «         �ŒK|€ t          j                             ||¦  «         �Œod S t          |t0          t2          f¦  «        �r€t5          |¦  «        D �]m\  }}t          |t          t          f¦  «        rPt          |t          ¦  «        r ||||¦  «        } ‰	|||¦  «        }‰|j                                      |¦  «         Œrt          |t          ¦  «        rÄ|t          j        k    r!t          j                             ||¦  «         na|t          j        k    r!t          j                             ||¦  «         n0|t          j        k    r t          j                             ||¦  «         ‰                     t-          t/          |¦  «        |¦  «        ¦  «         �ŒK|€ t          j                             ||¦  «         �Œod S |€Dt7          |                     ¦   «         ¦  «        D ]$}t          j                             ||¦  «         Œ#d S d S )Nc                 óN   — t          t          |¦  «        t          fd|i¦  «        S )Nrh   )re   r\   rF   )rO  rø   rh   s      r-   Ú_create_static_dimzK_process_dynamic_shapes.<locals>.update_symbols.<locals>._create_static_dim‚  s!   € Ý�c %™jœj­3¨&°7¸EÐ2BÑCÔCÐCr,   )r=  Ú_dynamo_weak_dynamic_indicesÚ_dynamo_dynamic_indicesÚ_dynamo_dynamic_rangeÚ_dynamo_static_indicesÚ_dynamo_unbacked_indicesrÒ   ró   rN  rF   r/   r$   rÛ   r#   r(   rÔ   rÕ   Úmaybe_mark_dynamicr)   Úmark_staticr*   Úmark_dynamicr¿   r0  r�   rô   r  Úranger‡   )
rî   rO  r1  rn  rø   r‡   rÂ   Úconstraintsrj  rk  s
          €€€r-   Úupdate_symbolsz/_process_dynamic_shapes.<locals>.update_symbols�  s‘  ø€ ð	Dð 	Dð 	Dõ
 /2©e¬eˆÔ+Ý),©¬ˆÔ&Ý'*¡u¤uˆÔ$Ý(+©¬ˆÔ%Ý*-©%¬%ˆÔ'å�e�TÑ"Ô"ñ $	5ØŸ+š+™-œ-ð 9ñ 9‘��3Ý˜c¥C­ ;Ñ/Ô/ð 9Ý! #¥sÑ+Ô+ð AØ0Ð0°¸¸CÑ@Ô@˜Ø!. ¨s°F¸AÑ!>Ô!>�JØ˜CœLÔ)×0Ò0°Ñ<Ô<Ð<Ð<Ý ¥XÑ.Ô.ð 	9Ø�hœmÒ+Ð+Ýœ×8Ò8¸ÀÑCÔCÐCÐCØ¥¤Ò/Ð/Ýœ×1Ò1°&¸!Ñ<Ô<Ð<Ð<Ø¥Ô 0Ò0Ð0Ýœ×2Ò2°6¸1Ñ=Ô=Ð=Ø×&Ò&Õ'9½"¸V¹*¼*ÀaÑ'HÔ'HÑIÔIÐIÑIØ�[Ý”M×-Ò-¨f°aÑ8Ô8Ð8ùð9ð 9õ  ˜¥¥t˜}Ñ-Ô-ñ 	5Ý# EÑ*Ô*ð 9ñ 9‘��3Ý˜c¥C­ ;Ñ/Ô/ð 9Ý! #¥sÑ+Ô+ð AØ0Ð0°¸¸CÑ@Ô@˜Ø!. ¨s°F¸AÑ!>Ô!>�JØ˜CœLÔ)×0Ò0°Ñ<Ô<Ð<Ð<Ý ¥XÑ.Ô.ð 	9Ø�hœmÒ+Ð+Ýœ×8Ò8¸ÀÑCÔCÐCÐCØ¥¤Ò/Ð/Ýœ×1Ò1°&¸!Ñ<Ô<Ð<Ð<Ø¥Ô 0Ò0Ð0Ýœ×2Ò2°6¸1Ñ=Ô=Ð=Ø×&Ò&Õ'9½"¸V¹*¼*ÀaÑ'HÔ'HÑIÔIÐIÑIØ�[Ý”M×-Ò-¨f°aÑ8Ô8Ð8ùð9ð 9ð  ˆ]Ý˜6Ÿ:š:™<œ<Ñ(Ô(ð 5ð 5�Ý”×)Ò)¨&°!Ñ4Ô4Ð4Ð4ð ˆ]ð5ð 5r,   c                 óZ   •— t          |t          j        ¦  «        r ‰| ||¦  «         d S d S r>   )rÒ   rÔ   r/  )rî   rê   rR  ry  s      €r-   Úassoc_shapez,_process_dynamic_shapes.<locals>.assoc_shape³  s;   ø€ Ý�a�œÑ&Ô&ð 	3ØˆN˜4  MÑ2Ô2Ð2Ð2Ð2ð	3ð 	3r,   rT  râ   )r  rü   rý   r  rÒ   r�   rô   rE   rU  r   r  ra   r7   rÑ   )r@  ræ   r{  Ú$derived_constraint_with_phantom_rootÚphantom_root_nameÚdynamic_dimsrü   rý   rx  rh  ri  rj  rk  ry  s         @@@@@@@@r-   Ú_process_dynamic_shapesr    sŸ  øøøøøøøø€ ð ;Ð:Ð:Ð:Ð:Ð:Ð:Ð:àÐ¥ ^Ñ!4Ô!4¸Ò!9Ð!9àˆ	Ý�.¥5­$ -Ñ0Ô0ð EØ,�˜^Ñ,Ô,¨]×-AÒ-AÑ-CÔ-CÑDÔDˆõ ,7µtÑ+<Ô+<€Gà-/€MØFHÐ)à$&€KðQð Qð Qð Qð Qð Qð Qð Qð Qðf05ð 05ð 05ð 05ð 05ð 05ð 05ðd3ð 3ð 3ð 3ð 3õ ˜ ]°NÈhÐWÑWÔWÐWà0Uð 
Vð 
VÐ,Ø@ÔEÔJÐØ Ð'Ð'ð 9@Ð@QÔ8RÐSTÔ8UÐ0Ô5øàŸšÑ(Ô(ð )ð )ˆØ×Ò˜<Ñ(Ô(Ð(Ð(àÐr,   c                 ó2  — i }t          | d„ ¬¦  «        d         D ]{}|€Œt          |t          ¦  «        rŒt          |t          ¦  «        r4|||j        <   t          |t
          ¦  «        r|j        ||j        j        <   Œdt          |t          ¦  «        sJ ‚Œ||S )Nc                 ó,   — t          | t          ¦  «        S r>   )rÒ   r/   )r@   s    r-   rB   z'_get_dim_name_mapping.<locals>.<lambda>Ñ  s   € �* Q­Ñ-Ô-€ r,   r  r   )r   rÒ   rF   r/   r$   rb   ra   r#   )ræ   Úname_to_dimr‡   s      r-   Ú_get_dim_name_mappingrƒ  Ë  sº   € ð €KÝØØ-Ð-ðñ ô ð ô	ð -ð -ˆð ˆ;àÝ�c�3ÑÔð 	-ØÝ˜�TÑ"Ô"ð 	-Ø(+ˆK˜œÑ%Ý˜#�{Ñ+Ô+ð :Ø14´�˜CœHÔ-Ñ.øå˜c¥8Ñ,Ô,Ð,Ð,Ð,Ð,ØÐr,   r  c           
      óâ  ‡‡‡‡— ddl }ddlŠddlm}m} ddlm} 	 |                      d¦  «        d                              ¦   «         }n$# t          $ r} ||j
        d¦  «        |‚d}~ww xY wi Š|                     d¦  «        D �].}|                     ¦   «         }|                     d	|¦  «        x}	r¤|	                     d¦  «        }
d
\  }}|                     d|¦  «        x}r"t          |                     d¦  «        ¦  «        }|                     d|¦  «        x}r"t          |                     d¦  «        ¦  «        }t          |
||¬¦  «        ‰|
<   ŒÓ|                     d¦  «        \  }
}‰                     |¦  «        }t!          |‰j        ¦  «        rt          |¦  «        ‰|
<   �Œ)|‰|
<   �Œ0t%          |¦  «        Št'          ¦   «         }‰                     ¦   «         D ]Ë\  }}t!          |t          t*          t,          ‰j        f¦  «        sJ ‚t!          |‰j        ¦  «        rS ||¦  «        sJ ‚|‰|<   |                     t3          t5          t7          |j        ¦  «        ¦  «        ¦  «        ¦  «         t!          |t,          ¦  «        r|                     |j        j        ¦  «         ŒÌ‰                     ¦   «         D ]\  }}|‰v s||v sJ ‚Œi Šˆˆˆˆfd„}t?          |||¦  «        S )aU  
    For working with export's dynamic shapes suggested fixes, and/or automatic dynamic shapes.
    Refines the given dynamic shapes spec, given a ConstraintViolation error message and the original dynamic shapes.

    For most cases behavior is straightforward - i.e. for suggested fixes that specialize or refine a Dim's range,
    or fixes that suggest a derived relation, the new dynamic shapes spec will be updated as such.

    e.g.
    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

    However, suggested fixes associated with derived dims can be more complicated.
    For example, if a suggested fix is provided for a root dim, the new derived dim value is evaluated based on the root.

    e.g.
    dx = Dim('dx')
    dy = dx + 2
    dynamic_shapes = {"x": (dx,), "y": (dy,)}

    Suggested fixes:

        dx = 4  # specialization will lead to dy also specializing = 6
        dx = Dim('dx', max=6)  # dy now has max = 8

    Derived dims suggested fixes can also be used to express divisibility constraints.
    This involves creating new root dims that aren't tied to a particular input shape.
    In this case the root dims won't appear directly in the new spec, but as a root of
    one of the dims.

    e.g.
    Suggested fixes:

        _dx = Dim('_dx', max=1024)  # this won't appear in the return result, but dx will
        dx = 4*_dx  # dx is now divisible by 4, with a max value of 4096
    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]+)\)r}   z = c                 ó(  •— |�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
                             ||¦  «        \  }}|}|dk    rt          |¦  «        |z  }|dk    r|t          |¦  «        z   }|‰	t	          |¦  «        <   |S |S t          |t          ¦  «        rU|j        j        ‰v rG|j        ‰	v r‰	|j                 S |                     ‰|j        j                 ¦  «        }|‰	|j        <   |S |S )Nr   r   )rÒ   rF   r$   ÚExprr\   ÚnextÚiterÚfree_symbolsr7   ÚpolysÚ	polytoolsÚdivrb   ra   r]   )rî   r‡   ÚdummyÚfixra  ra   ÚmodulusÚ	remainderÚ_dimÚderived_dim_cacher‚  Úshape_fixesr[   s            €€€€r-   Úapply_fixesz?refine_dynamic_shapes_from_suggested_fixes.<locals>.apply_fixesE  sœ  ø€ Øˆ;�* S­#Ñ.Ô.ˆ;ØˆJØŒ\˜[Ð(Ñ(Ø˜cœlÔ+ˆCÝ˜#˜uœzÑ*Ô*ð Ý�s‘8”8Ð0Ð0Ð0Ø,­S°©X¬XÔ6Ð6å!¥$ sÔ'7Ñ"8Ô"8Ñ9Ô9�Fà”{ kÐ1Ð1Ø*¨6¬;Ô7˜˜à%œ{¨kÐ9Ð9Ð9Ð9Ø*¨6¬;Ô7˜à).¬Ô)>×)BÒ)BÀ3ÈÑ)OÔ)OÑ&�G˜YØ�CØ !’|�|Ý! '™lœl¨SÑ0˜Ø  A’~�~Ø!¥C¨	¡N¤NÑ2˜Ø25Ð%¥c¨#¡h¤hÑ/Ø�Jà�
Ý˜�[Ñ)Ô)ð 	¨c¬hÔ.?À;Ð.NÐ.NØŒ|Ð0Ð0Ð0Ø(¨¬Ô6Ð6à—v’v˜k¨#¬(Ô*;Ô<Ñ=Ô=�Ø26Ð! #¤,Ñ/Ø�Øˆ
r,   ) Úrer[   r  rü   rý   rŸ   r…  ÚsplitÚstripÚ	Exceptionr  ÚmatchÚgrouprF   r   rZ   rÒ   ÚNumberrƒ  r=  rN  r/   rb   rˆ  rÜ   r\   r‰  rŠ  r‹  ra   r$   r  )r  ræ   r—  rü   rý   r…  Úshape_fixes_msgÚexcr�  r›  r7   r…   r†   Ú	match_minÚ	match_maxrb  Úrootsr  Úcr–  r”  r‚  r•  r[   s                       @@@@r-   r!   r!   á  sW  øøøø€ ðV €I€I€Ià€L€L€Là:Ð:Ð:Ð:Ð:Ð:Ð:Ð:ØOÐOÐOÐOÐOÐOðØŸ)š)Ð$6Ñ7Ô7¸Ô:×@Ò@ÑBÔBˆˆøÝð ð ð ØˆiØÔ'Ønñ
ô 
ð ð	øøøøðøøøð €KØ×$Ò$ TÑ*Ô*ð )ñ )ˆØ�iŠi‰kŒkˆØ—H’HÐ6¸Ñ<Ô<Ð<ˆ5ð 	)Ø—;’;˜q‘>”>ˆDØ#‰JˆD�$ØŸHšHÐ%IÈ3ÑOÔOÐOˆyð /Ý˜9Ÿ?š?¨1Ñ-Ô-Ñ.Ô.�ØŸHšHÐ%GÈÑMÔMÐMˆyð /Ý˜9Ÿ?š?¨1Ñ-Ô-Ñ.Ô.�Ý # D¨d¸Ð =Ñ =Ô =ˆK˜ÑÐàŸš 5Ñ)Ô)‰JˆD�$Ø—=’= Ñ&Ô&ˆDÝ˜$ ¤Ñ-Ô-ð )å$'¨¡I¤I�˜DÑ!Ñ!ð %)�˜DÑ!Ñ!å'¨Ñ7Ô7€Kõ ‘e”e€EØ×!Ò!Ñ#Ô#ð 'ð '‰ˆˆ1Ý˜!�c¥4­°e´jÐAÑBÔBÐBÐBÐBÝ�a˜œÑ$Ô$ð 	7Ø,Ð,¨QÑ/Ô/Ð/Ð/Ð/ØˆK˜‰NØ�IŠI•c�$�t A¤NÑ3Ô3Ñ4Ô4Ñ5Ô5Ñ6Ô6Ð6Ý�a�Ñ%Ô%ð 	'Ø�IŠI�a”f”oÑ&Ô&Ð&øð ×!Ò!Ñ#Ô#ð .ð .‰ˆˆ1Ø�KÐÐ 1¨ : : :Ð-øð 13Ðð"ð "ð "ð "ð "ð "ð "ð "õH ˜{¨N¸NÑKÔKÐKs   œ-A
 Á

A+ÁA&Á&A+)F)GÚdataclassesr‚   Úloggingrx   Úcollectionsr   Úenumr   r   Útypingr   r   r   r	   r
   r   r   r   r   rÔ   Útorch.utils._pytreer   r   r   r   r   r   r   r   r   Úexported_programr   r[   r   Útorch._guardsr   rŸ   r   r   Ú__all__Ú	getLoggerr$   rB  r#   rE   r/   re   rb   r\   rF   r   r(   r)   r*   r    Ú	dataclassr�   r“   r¹   r¼   r¿   r   rá   r  r(  r*  rD  rY  r  rƒ  r!   r+   r,   r-   ú<module>r¯     s5  ðà Ð Ð Ð Ø €€€Ø €€€Ø 
€
€
€
Ø #Ð #Ð #Ð #Ð #Ð #Ø Ð Ð Ð Ð Ð Ð Ð Ø XÐ XÐ XÐ XÐ XÐ XÐ XÐ XÐ XÐ XÐ XÐ XÐ XÐ XÐ XÐ XÐ XÐ XÐ XÐ XÐ XÐ Xà €€€ð
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð .Ð -Ð -Ð -Ð -Ð -ð ð WØÐÐÐÐÐà$Ð$Ð$Ð$Ð$Ð$ØVÐVÐVÐVÐVÐVÐVÐVðð ð €ð €gÔ˜Ñ!Ô!€ð
ð 
ð 
ð 
ð 
ˆtñ 
ô 
ð 
ðBSð BSð BSð BSð BSˆ4ñ BSô BSð BSðJð ð ð ð �ñ ô ð ð"@
ð @
ð @
ð @
ð @
�$ñ @
ô @
ð @
ðF ,0Àdð ð ð ˆcð ˜8 Cœ=ð °h¸s´mð ð ð ð ð: Œ=€„ØŒ_€„
ØÔ€„ð ,0Àdð @ð @ð @�ð @˜8 Cœ=ð @°h¸s´mð @ð @ð @ð @ð Ôðð ð ð ð ñ ô ñ Ôðð ÔðD
ð D
ð D
ð D
ð D
Ð#ñ 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$ð 8$ð 8$ð 8$ð~  $ð	yð yð yØ
�3˜�8Ô
ðyà
ðyð ðyð ˜Œ}ð	yð
 	ðyð yð yð yðxð ÀÀcÈ3ÀhÄð ð ð ð ð Dð Dð Dð Dð Dñ Dô Dð DðNð ð ðpXØ˜˜S˜”>ðpXà˜$˜s C˜xœ.¨%°¬*°d¸3´iÀÐEÔFðpXð pXð pXð pXðfqØ˜˜S˜”>ðqà˜$˜s C˜xœ.¨%°¬*°d¸3´iÀÐEÔFðqð 
ˆ*Ôðqð qð qð qðhØ˜$˜s C˜xœ.¨%°¬*°d¸3´iÀÐEÔFðð ð ð ð,HLØ	ðHLà˜$˜s C˜xœ.¨%°¬*°d¸3´iÐ?Ô@ðHLð ˆ4��S�Œ>˜5 œ: t¨C¤yÐ0Ô1ðHLð HLð HLð HLð HLð HLr,   