§
    ŠŠtj<Ú  ã                   ó  — 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 d dlm	Z	m
Z
 d dl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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*e j+         G d„ d¦  «        ¦   «         Z, G d„ d¦  «        Z-e-Z. G d„ de-¦  «        Z/ G d„ de-¦  «        Z0dddœde1de2dz  de2dz  de3e-df         fd„Z4e j+         G d„ d¦  «        ¦   «         Z5e j+         G d „ d!e5¦  «        ¦   «         Z6e j+         G d"„ d#¦  «        ¦   «         Z7e j+         G d$„ d%e5¦  «        ¦   «         Z8e j+         G d&„ d'e5¦  «        ¦   «         Z9e6e8z  e9z  Z:e j+         G d(„ d)¦  «        ¦   «         Z;d*e:d+ee2e2ge<d,         f         d-d.de=e1e3e2e2f         f         d/e<e3d0                  d1e<e3d,ed2         ef                  d3e=e1d4f         d5e>d,         fd6„Z?dd7œd8edef         d9ed:ed;e1dz  def
d<„Z@de=e1ef         fd=„ZA G d>„ d?¦  «        ZB G d@„ dA¦  «        ZCdB„ ZDdCe=e1ef         d:e=e1ef         e3e         z  e<e         z  dz  fdD„ZEdCe=e1ef         d:e=e1ef         e3e         z  e<e         z  dz  de<e:         fdE„ZFd:e=e1ef         e3e         z  e<e         z  dz  fdF„ZGdGe1d:e=e1ef         e3e         z  e<e         z  de=e1ef         e3e         z  e<e         z  fdH„ZHdS )Ié    N)Údefaultdict)ÚCallable)ÚautoÚEnum)ÚAnyÚTYPE_CHECKINGÚUnion)Ú_get_node_typeÚBUILTIN_TYPESÚKeyPathÚkeystrÚ
MappingKeyÚSequenceKeyÚSUPPORTED_NODESÚ	tree_iterÚtree_mapÚtree_map_with_pathÚtree_structureÚTreeSpecé   )ÚExportedProgram)ÚSymbol)ÚSource)ÚShapeEnvÚStrictMinMaxConstraint)Ú
ConstraintÚDimÚdimsÚ*refine_dynamic_shapes_from_suggested_fixesÚAdditionalInputsc                   óN   — e Zd ZdZ e¦   «         Z e¦   «         Z e¦   «         ZdS )Ú_DimHintTypezÜ
    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/html/CA-Chatbot/venv/lib/python3.11/site-packages/torch/export/dynamic_shapes.pyr"   r"   0   s;   € € € € € ðð ð ˆ4‰6Œ6€DØˆT‰VŒV€FØˆd‰fŒf€G€G€Gr+   r"   c                   ó¬   — e Zd ZU dZeed<   dZedz  ed<   dZedz  ed<   dZ	e
dz  ed<   ed„ ¦   «         Zed	„ ¦   «         Zed
„ ¦   «         Zddd„Zd„ ZdS )Ú_DimHintaj  
    Internal class for dynamic shape hints.
    - min and max are optional.
    - _factory is for UX only, below example:
        auto_hint = _DimHint.AUTO()  # _factory=True
        bounded_hint = auto_hint(min=10, max=100)  # Returns new instance with _factory=False
        bounded_hint(min=5, max=50)  # Will fail, non-factory instance cannot be called
    ÚtypeNÚminÚmaxTÚ_factoryc                  ó4   — t          t          j        ¦  «        S ©N)r.   r"   r'   r*   r+   r,   r'   z_DimHint.AUTOM   s   € å�Ô)Ñ*Ô*Ð*r+   c                  ó4   — t          t          j        ¦  «        S r4   )r.   r"   r)   r*   r+   r,   r)   z_DimHint.DYNAMICQ   s   € å�Ô,Ñ-Ô-Ð-r+   c                  ó4   — t          t          j        ¦  «        S r4   )r.   r"   r(   r*   r+   r,   r(   z_DimHint.STATICU   s   € å�Ô+Ñ,Ô,Ð,r+   Úreturnc                 ó&  — | j         s t          dt          | ¦  «        › d�¦  «        ‚|�|dk     rt          d|› �¦  «        ‚|�|dk     rt          d|› �¦  «        ‚|�|�||k    rt          d|› d|› �¦  «        ‚t	          | j        ||d¬	¦  «        S )
Nú'z' object is not callabler   zmin must be non-negative, got zmax must be non-negative, got zmin must be <= max, got min=ú, max=F)r0   r1   r2   )r2   Ú	TypeErrorr/   ÚAssertionErrorr.   )Úselfr0   r1   s      r,   Ú__call__z_DimHint.__call__Y   s¾   € ØŒ}ð 	FÝÐD¥ T¡
¤
ÐDÐDÐDÑEÔEÐEØˆ?˜s Qšw˜wÝ Ð!GÀ#Ð!GÐ!GÑHÔHÐHØˆ?˜s Qšw˜wÝ Ð!GÀ#Ð!GÐ!GÑHÔHÐHØˆ?˜s˜°3¸²9°9Ý Ð!PÀÐ!PÐ!PÈ3Ð!PÐ!PÑQÔQÐQÝ˜œ	 s°¸eÐDÑDÔDÐDr+   c                 óÞ   — | j         j        g}| j        �|                     d| j        › �¦  «         | j        �|                     d| j        › �¦  «         dd                     |¦  «        › d�S )Nzmin=zmax=zDimHint(z, ú))r/   Únamer0   Úappendr1   Újoin)r=   Úpartss     r,   Ú__repr__z_DimHint.__repr__d   su   € Ø””Ð ˆØŒ8ÐØ�LŠLÐ* ¤Ð*Ð*Ñ+Ô+Ð+ØŒ8ÐØ�LŠLÐ* ¤Ð*Ð*Ñ+Ô+Ð+Ø-˜$Ÿ)š) EÑ*Ô*Ð-Ð-Ð-Ð-r+   ©NN)r7   r.   )r#   r$   r%   r&   r"   Ú__annotations__r0   Úintr1   r2   ÚboolÚstaticmethodr'   r)   r(   r>   rE   r*   r+   r,   r.   r.   =   sæ   € € € € € € ðð ð ÐÐÑØ€Cˆˆt‰ÐÐÑØ€Cˆˆt‰ÐÐÑØ €Hˆd�T‰kÐ Ð Ñ àð+ð +ñ „\ð+ð ð.ð .ñ „\ð.ð ð-ð -ñ „\ð-ð	Eð 	Eð 	Eð 	Eð 	Eð.ð .ð .ð .ð .r+   r.   c            	       ó$  — e Zd ZdZe                     ¦   «         Ze                     ¦   «         Ze                     ¦   «         Zdddœdede	dz  de	dz  fd„Z
dd	„Zdd
„Zdd„Zdd„Zdd„Zdd„Zdefd„Zdd„Zedede	de	defd„¦   «         Zd„ ZdS )r   aS
  
    The ``Dim`` class allows users to specify dynamism in their exported
    programs. By marking a dimension with a ``Dim``, the compiler associates the
    dimension with a symbolic integer containing a dynamic range.

    The API can be used in 2 ways: Dim hints (i.e. automatic dynamic shapes:
    ``Dim.AUTO``, ``Dim.DYNAMIC``, ``Dim.STATIC``), or named Dims (i.e.
    ``Dim("name", min=1, max=2)``).

    Dim hints provide the lowest barrier to exportability, with the user only
    needing to specify if a dimension if dynamic, static, or left for the
    compiler to decide (``Dim.AUTO``). The export process will automatically
    infer the remaining constraints on min/max ranges and relationships between
    dimensions.

    Example::

        class Foo(nn.Module):
            def forward(self, x, y):
                assert x.shape[0] == 4
                assert y.shape[0] >= 16
                return x @ y


        x = torch.randn(4, 8)
        y = torch.randn(8, 16)
        dynamic_shapes = {
            "x": {0: Dim.AUTO, 1: Dim.AUTO},
            "y": {0: Dim.AUTO, 1: Dim.AUTO},
        }
        ep = torch.export(Foo(), (x, y), dynamic_shapes=dynamic_shapes)

    Here, export would raise an exception if we replaced all uses of ``Dim.AUTO`` with ``Dim.DYNAMIC``,
    as ``x.shape[0]`` is constrained to be static by the model.

    More complex relations between dimensions may also be codegened as runtime assertion nodes by the compiler,
    e.g. ``(x.shape[0] + y.shape[1]) % 4 == 0``, to be raised if runtime inputs do not satisfy such constraints.

    You may also specify min-max bounds for Dim hints, e.g. ``Dim.AUTO(min=16, max=32)``, ``Dim.DYNAMIC(max=64)``,
    with the compiler inferring the remaining constraints within the ranges. An exception will be raised if
    the valid range is entirely outside the user-specified range.

    Named Dims provide a stricter way of specifying dynamism, where exceptions are raised if the compiler
    infers constraints that do not match the user specification. For example, exporting the previous
    model, the user would need the following ``dynamic_shapes`` argument::

        s0 = Dim("s0")
        s1 = Dim("s1", min=16)
        dynamic_shapes = {
            "x": {0: 4, 1: s0},
            "y": {0: s0, 1: s1},
        }
        ep = torch.export(Foo(), (x, y), dynamic_shapes=dynamic_shapes)

    Named Dims also allow specification of relationships between dimensions, up
    to univariate linear relations.  For example, the following indicates one
    dimension is a multiple of another plus 4::

        s0 = Dim("s0")
        s1 = 3 * s0 + 4

    N©r0   r1   rA   r0   r1   c                óÖ   — ddl m} |€dn|}|€|n|}||k    st          d|› d|› �¦  «        ‚|                     ¦   «         st          d|› �¦  «        ‚|| _        || _        || _        d S )Nr   ©Úint_ooz(Cannot create Dim with inconsistent min=r:   z)Dim name must be a valid identifier, got )Útorch.utils._sympy.numbersrO   r<   Úisidentifierr#   r0   r1   )r=   rA   r0   r1   rO   Ú_minÚ_maxs          r,   Ú__init__zDim.__init__±   s£   € Ø5Ð5Ð5Ð5Ð5Ð5à�Kˆqˆq SˆØ˜ˆvˆv¨#ˆØ�t’�Ý ØK¸3ÐKÐKÀcÐKÐKñô ð ð × Ò Ñ"Ô"ð 	UÝ Ð!SÈTÐ!SÐ!SÑTÔTÐTØˆŒØˆŒØˆŒˆˆr+   r7   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 r4   r*   ©ÚxÚothers    €r,   ú<lambda>zDim.__add__.<locals>.<lambda>Ç   ó   ø€  a¨%¡i€ r+   ©r/   rH   ÚNotImplementedErrorr#   Ú_derive©r=   rZ   s    `r,   Ú__add__zDim.__add__À   sn   ø€ å�‰;Œ;�cÐ!Ð!Ý%ð_ Eð _ð _¨t¬}ð _ð _ð _ñô ð ð �|Š|Ð/Ð/Ð/Ð/Ñ0Ô0Ð0r+   c                 ó   — | |z   S r4   r*   r`   s     r,   Ú__radd__zDim.__radd__É   ó   € Ø�e‰|Ðr+   c                 ó–   ‡— t          ‰¦  «        t          urt          d‰› d| j        › d�¦  «        ‚|                      ˆfd„¦  «        S )NzAttempted to subtract z from rV   c                 ó   •— | ‰z
  S r4   r*   rX   s    €r,   r[   zDim.__sub__.<locals>.<lambda>Ó   r\   r+   r]   r`   s    `r,   Ú__sub__zDim.__sub__Ì   sn   ø€ å�‰;Œ;�cÐ!Ð!Ý%ð_¨ð _ð _°d´mð _ð _ð _ñô ð ð �|Š|Ð/Ð/Ð/Ð/Ñ0Ô0Ð0r+   c                 ó2   — t          d| j        › d�¦  «        ‚)NzAttempted to negate zN. (Only increasing linear operations with integer coefficients are supported.))r^   r#   r`   s     r,   Ú__rsub__zDim.__rsub__Õ   s0   € Ý!ð[ 4¤=ð [ð [ð [ñ
ô 
ð 	
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 r4   r*   rX   s    €r,   r[   zDim.__mul__.<locals>.<lambda>â   r\   r+   r]   r`   s    `r,   Ú__mul__zDim.__mul__Û   sv   ø€ å�‰;Œ;�cÐ!Ð! U¨a¢Z ZÝ%ð_¨ð _ð _°d´mð _ð _ð _ñô ð ð �|Š|Ð/Ð/Ð/Ð/Ñ0Ô0Ð0r+   c                 ó   — | |z  S r4   r*   r`   s     r,   Ú__rmul__zDim.__rmul__ä   rd   r+   c                 óZ   — ddl m} t           | || j        ¦  «        ¦  «        ¦  «        S )Nr   )Úsympify)Úsympyrp   Ústrr#   )r=   Úfnrp   s      r,   Ú_derived_namezDim._derived_nameç   s8   € Ø!Ð!Ð!Ð!Ð!Ð!å�2�2�g�g˜dœmÑ,Ô,Ñ-Ô-Ñ.Ô.Ð.r+   c                 óJ   — t          |                      |¦  «        | |¦  «        S r4   )Ú_DerivedDimrt   ©r=   rs   s     r,   r_   zDim._deriveì   s"   € Ý˜4×-Ò-¨bÑ1Ô1°4¸Ñ<Ô<Ð<r+   Úmin_Úmax_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   rN   é   zDim('z')z', max=r@   z', min=r:   )rP   rO   )rA   rx   ry   rO   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                 óX   — t                                | j        | j        | j        ¦  «        S r4   )r   r|   r#   r0   r1   ©r=   s    r,   rE   zDim.__repr__ÿ   s   € Ý�}Š}˜Tœ]¨D¬H°d´hÑ?Ô?Ð?r+   )r7   r   )r#   r$   r%   r&   r.   r'   r)   r(   rr   rH   rT   ra   rc   rg   ri   rl   rn   rt   r_   rJ   r|   rE   r*   r+   r,   r   r   m   s…  € € € € € ð=ð =ð~ �=Š=‰?Œ?€DØ×ÒÑ Ô €GØ�_Š_ÑÔ€Fà7;Ètð ð ð ˜Sð ¨#°©*ð À#ÈÁ*ð ð ð ð ð1ð 1ð 1ð 1ðð ð ð ð1ð 1ð 1ð 1ð
ð 
ð 
ð 
ð1ð 1ð 1ð 1ðð ð ð ð/ 3ð /ð /ð /ð /ð
=ð =ð =ð =ð ð8˜ð 8 3ð 8¨cð 8°cð 8ð 8ð 8ñ „\ð8ð@ð @ð @ð @ð @r+   r   c                   óJ   — e Zd ZdZdefd„Zed„ ¦   «         Zed„ ¦   «         ZdS )Ú
_StaticDimz¦
    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.
    Úvaluec                 ó<   — t          |¦  «        | _        || _        d S r4   )rr   r#   r�   )r=   r�   s     r,   rT   z_StaticDim.__init__  s   € Ý˜E™
œ
ˆŒØˆŒ
ˆ
ˆ
r+   c                 ó   — | j         S r4   ©r�   r~   s    r,   r0   z_StaticDim.min  ó
   € àŒzÐr+   c                 ó   — | j         S r4   r„   r~   s    r,   r1   z_StaticDim.max  r…   r+   N)	r#   r$   r%   r&   rH   rT   Úpropertyr0   r1   r*   r+   r,   r€   r€     so   € € € € € ðð ð˜cð ð ð ð ð ðð ñ „Xðð ðð ñ „Xðð ð r+   r€   c                   ó^   — e Zd ZdZdededefd„Zed„ ¦   «         Z	ed„ ¦   «         Z
d„ Zd	„ Zd
S )rv   a  
    Class 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`.
    rA   Úrootrs   c                 ó0   — || _         || _        || _        d S r4   )r#   r‰   rs   )r=   rA   r‰   rs   s       r,   rT   z_DerivedDim.__init__+  s   € ØˆŒØˆŒ	ØˆŒˆˆr+   c           	      ó  — ddl m} ddlm} | j        j        | u r| S |                       || j        j        ¦  «        ¦  «        }| j        }|dk     r(t          d| j        › d|j        › d|j        › d�¦  «        ‚t          |¦  «        S )Nr   ©ÚIntegerrN   zExpected derived min value of z9 to be >= 0. Please specify an appropriate min value for ú (currently ú).)
rq   r�   rP   rO   r‰   r0   rs   r<   r#   rH   )r=   r�   rO   Ú_min_symintr‰   s        r,   r0   z_DerivedDim.min0  sÇ   € ð 	"Ð!Ð!Ð!Ð!Ð!à5Ð5Ð5Ð5Ð5Ð5àŒ9Œ=˜V˜GÐ#Ð#Ø�7ˆNà—g’g˜g˜g d¤i¤mÑ4Ô4Ñ5Ô5ˆØŒyˆØ˜Š?ˆ?Ý ð+°´ð +ð +Ø?C¼}ð+ð +à"œhð+ð +ð +ñô ð õ
 �;ÑÔÐr+   c                 óL  — ddl m} ddlm} | j        j        |u r|S |                       || j        j        ¦  «        ¦  «        }| j        }|t          j        dz
  k    r8t          d| j
        › dt          j        dz
  › d|j
        › d|j        › d	�	¦  «        ‚t          |¦  «        S )
Nr   rŒ   rN   r   zExpected derived max value of z
 to be <= z.. Please specify an appropriate max value for rŽ   r�   )rq   r�   rP   rO   r‰   r1   rs   ÚsysÚmaxsizer<   r#   rH   )r=   r�   rO   Ú_max_symintr‰   s        r,   r1   z_DerivedDim.maxE  sÞ   € ð 	"Ð!Ð!Ð!Ð!Ð!à5Ð5Ð5Ð5Ð5Ð5àŒ9Œ=˜FÐ"Ð"ØˆMà—g’g˜g˜g d¤i¤mÑ4Ô4Ñ5Ô5ˆØŒyˆØ�œ q™Ò(Ð(Ý ð+°´ð +ð +Í#Ì+ÐXYÉ/ð +ð +Ø?C¼}ð+ð +à"œhð+ð +ð +ñô ð õ
 �;ÑÔÐr+   c                 ó`   ‡ ‡— t          ‰                      ‰¦  «        ‰ j        ˆˆ fd„¦  «        S )Nc                 ó@   •—  ‰‰                      | ¦  «        ¦  «        S r4   )rs   )rY   rs   r=   s    €€r,   r[   z%_DerivedDim._derive.<locals>.<lambda>a  s   ø€ �b�b˜Ÿš ™œ‘n”n€ r+   )rv   rt   r‰   rw   s   ``r,   r_   z_DerivedDim._deriveZ  s=   øø€ õ Ø×Ò˜rÑ"Ô"ØŒIØ$Ð$Ð$Ð$Ð$ñ
ô 
ð 	
r+   c                 ó   — | j         S r4   )r#   r~   s    r,   rE   z_DerivedDim.__repr__d  s
   € ØŒ}Ðr+   N)r#   r$   r%   r&   rr   r   r   rT   r‡   r0   r1   r_   rE   r*   r+   r,   rv   rv     s›   € € € € € ðð ð˜Sð ¨ð °ð ð ð ð ð
 ð ð  ñ „Xð ð( ð ð  ñ „Xð ð(
ð 
ð 
ðð ð ð ð r+   rv   rL   Únamesr0   r1   r7   .c                 ó>   ‡ ‡— t          ˆˆ fd„|D ¦   «         ¦  «        S )zh
    Util to create multiple :func:`Dim` types.

    Returns:
        A tuple of :func:`Dim` types.
    c              3   ó<   •K  — | ]}t          |‰‰¬ ¦  «        V — ŒdS )rL   N)r   )Ú.0rA   r1   r0   s     €€r,   ú	<genexpr>zdims.<locals>.<genexpr>q  s2   øè è € Ð?Ð?°•�T˜s¨Ð,Ñ,Ô,Ð?Ð?Ð?Ð?Ð?Ð?r+   )Útuple)r0   r1   r˜   s   `` r,   r   r   h  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_idÚdimN)r#   r$   r%   r&   rH   rG   r*   r+   r,   rŸ   rŸ   t  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.
    rA   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   rN   ©ÚValueRanges©ÚlowerÚupperF©ÚvrÚ	warn_only)Ú%torch.fx.experimental.symbolic_shapesr   rP   rO   Útorch.utils._sympy.value_rangesr¨   r¤   r­   r£   r    r¡   rA   )r=   rª   r«   r   rO   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±   ©r=   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´   ©r=   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.)r;   r~   s    r,   Ú__bool__z_Constraint.__bool__ª  s   € õ
 ð7ñ
ô 
ð 	
r+   c                 ó`   — | j         | j        | j        j        j        | j        j        j        dœS ©N)r    r¡   r0   r1   ©r    r¡   r¤   r­   rª   r«   r~   s    r,   Úserializable_specz_Constraint.serializable_specµ  s5   € ð ”IØ”8ØÔ(Ô+Ô1ØÔ(Ô+Ô1ð	
ð 
ð 	
r+   )r   N)r#   r$   r%   r&   rr   rG   r±   r¶   r¹   r¾   rÀ   rÂ   r‡   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.
    rA   r   r¤   ÚvalN)r#   r$   r%   r&   rr   rG   rH   r*   r+   r,   rÈ   rÈ   Æ  s:   € € € € € € ð	ð 	ð €I€I�IØ.Ð.Ð.Ñ.Ø	€H€H�H€H€Hr+   rÈ   c                   óX   — e Zd ZU dZeed<   ded<   eez  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.
    rA   r   r¤   r‰   rs   c                 ó`   — | j         | j        | j        j        j        | j        j        j        dœS rÄ   rÅ   r~   s    r,   rÆ   z$_DerivedConstraint.serializable_specè  s5   € ð ”IØ”8ØÔ(Ô+Ô1ØÔ(Ô+Ô1ð	
ð 
ð 	
r+   N)r#   r$   r%   r&   rr   rG   rŸ   rÈ   r   r‡   rÆ   r*   r+   r,   rË   rË   Ø  sj   € € € € € € ðð ð €I€I�IØ.Ð.Ð.Ñ.Ø
˜lÑ
*Ð*Ð*Ñ*Ø€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Ð   r~   s    r,   rÆ   z$_RelaxedConstraint.serializable_specü  s   € ð ”IØ”8ð
ð 
ð 	
r+   N)r#   r$   r%   r&   r‡   rÆ   r*   r+   r,   rÎ   rÎ   ó  s9   € € € € € ðð ð ð
ð 
ñ „Xð
ð 
ð 
r+   rÎ   c                   óX   — e Zd ZU dZeed<    ej        dd¬¦  «        Ze	ez  dz  ed<   dS )Ú_IntWrapperz²
    Dummy wrapper class to wrap around integer inputs so that when we parse the
    dynamic_shapes structure, we can mark if any of the integers were marked as
    dynamic.
    rÉ   FN)ÚinitÚdefaultÚdynamism)
r#   r$   r%   r&   rH   rG   ÚdataclassesÚfieldrÕ   r.   r*   r+   r,   rÒ   rÒ     sR   € € € € € € ðð ð 
€H€H�Hà&7 kÔ&7¸UÈDÐ&QÑ&QÔ&Q€Hˆh˜‰n˜tÑ#ÐQÐQÑQÐQÐQr+   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 r4   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 r4   r*   rá   s     €r,   rœ   z&_process_equalities.<locals>.<genexpr>/  s9   øè è € ð  ð  Ø+7�˜Ð&ð ð  ð  ð  ð  ð  r+   r   )rÉ   rã   Údynamic_dimÚconstraint_dim)r    r¡   ÚextendÚ
isinstancer£   rA   rË   r‰   rÈ   Úcreate_symbolrÉ   ÚtorchÚ_dynamorã   ÚConstantSourceÚfxÚexperimentalÚsymbolic_shapesÚ
DimDynamicr)   r¤   rs   rB   rÎ   Úadd)rØ   rÙ   rÚ   r˜   rÛ   rÜ   rÝ   rÞ   ÚsourcesÚother_sourcesÚshared_t_idÚ
shared_dimr‰   rs   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ø   c          	      óŠ  ‡ ‡‡‡	‡
‡‡— d„ Šˆ
ˆ ˆfd„Š
	 t          ‰
|g|¢R d‰iŽS # t          $ r”}d|j        d         v r|st          d¦  «        d‚‰st          d¦  «        d‚d	„ Š	ˆfd
„Šdt          dt          dt
          ddfˆˆ	ˆˆfd„Št          |‰¬¦  «        }|D ]}t          |‰¦  «        } ‰||d¦  «         Œ ‚ 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 r4   )r
   r   )Úts    r,   Úis_leafz$_tree_map_with_path.<locals>.is_leafh  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>.fo  s‡   ø€ Ý˜QÑÔˆà•/Ð!Ð!õ &ØÝ Ô$×/Ò/°Ñ2Ô2°1Ô5ðð  ðð ð ð  ð	ð ð ð �4˜˜aÐ1 .Ð1Ð1Ð1Ð1r+   rÿ   Úmismatchr   z2Cannot be a mismatch if there is no dynamic_shapesNz7Must provide a tree_name when there might be a mismatchc                 óÎ   — | t           u rt          ||         ¦  «        S | t          t          fv r&|�t	          d| › d|› �¦  «        ‚t          |¦  «        S t	          d| › �¦  «        ‚)Nz%expected context to be None for type ú, got zDid not expect type )Údictr   Úlistr�   r<   r   )Útype_ÚcontextÚis      r,   Ú_keyz!_tree_map_with_path.<locals>._key�  s}   € à�D�=�=Ý% g¨a¤jÑ1Ô1Ð1Ø�T¥5˜MÐ)Ð)ØÐ*Ý,ØZÀEÐZÐZÐQXÐZÐZñô ð õ ' 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+   ÚtreespecÚother_treespecr  r7   c                 ó¬  •‡— t          |¦  «        }|                      ¦   «         rd S |                     ¦   «         r ‰d‰› |› d| j        › d|› d�¦  «         | j        |j        k    r# ‰d‰› |› d| j        › d|› d|j        › �	¦  «         | j        |j        k    r$ ‰d‰› |› d| j        › d|› d|j        › d�
¦  «         | j        t          u r•t          | j        ¦  «        t          |j        ¦  «        k    r# ‰d‰› |› d| j        › d|› d|j        › �	¦  «         t	          t          |j        |                     ¦   «         ¦  «        ¦  «        Šˆfd	„| j        D ¦   «         }n|                     ¦   «         }t          t          |                      ¦   «         |¦  «        ¦  «        D ].\  }\  }} ‰	||| ‰
| j        | j        |¦  «        f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>Ã  s   ø€ Ð%JÐ%JÐ%J°A f¨Q¤iÐ%JÐ%JÐ%Jr+   )
r   rÿ   r/   Únum_childrenr  Úsetr  ÚzipÚchildrenÚ	enumerate)r  r  r  Úrendered_pathÚother_childrenr  ÚchildÚother_childr  Ú_comparer  r  rø   s           @€€€€r,   r*  z%_tree_map_with_path.<locals>._compare¢  sû  øø€ õ
 !' t¡¤�Ø×#Ò#Ñ%Ô%ð Ø�FØ!×)Ò)Ñ+Ô+ð Ø(Ð(ðF˜Ið F }ð Fð F¸X¼]ð Fð FØ.;ðFð Fð Fñô ð ð ”= NÔ$7Ò7Ð7Ø(Ð(ðZ˜Ið Z }ð Zð Z¸X¼]ð Zð ZØ.;ðZð ZØDRÔDWðZð Zñô ð ð Ô(¨NÔ,GÒGÐGØ(Ð(ðj˜Ið j }ð jð j¸HÔ<Qð jð jØ.;ðjð jØCQÔC^ðjð jð jñô ð ð ”=¥DÐ(Ð(å˜8Ô+Ñ,Ô,µ°NÔ4JÑ0KÔ0KÒKÐKØ,Ð,ðe 	ð e¨=ð eð eÀXÔEUð eð eØ2?ðeð eØLZÔLbðeð eñô ð õ "Ý˜NÔ2°N×4KÒ4KÑ4MÔ4MÑNÔNñô �Fð &KÐ%JÐ%JÐ%J¸Ô9IÐ%JÑ%JÔ%J�N�Nà%3×%<Ò%<Ñ%>Ô%>�NÝ/8Ý˜×)Ò)Ñ+Ô+¨^Ñ<Ô<ñ0ô 0ð ð Ñ+�AÑ+˜˜{ð �HØØ#Ø   X¤]°HÔ4DÀaÑ HÔ HÐJÑJñô ð ð ðð r+   ©rÿ   r*   )r   Ú
ValueErrorÚargsr<   r   r   r   )rù   rú   rø   rû   Úer  Ú
other_treer  r*  r  r  rÿ   r  s   ` `     @@@@@r,   Ú_tree_map_with_pathr0  O  sŸ  øøøøøøø€ ð26ð 6ð 6ð2ð 2ð 2ð 2ð 2ð 2ð 2ðUÝ! ! TÐL¨NÐLÐLÐLÀGÐLÐLÐLøÝð Sð Sð SØ˜œ œÐ"Ð"ð "ð Ý$ØHñô àðð ð Ý$ØMñô àðð
Eð 
Eð 
Eðð ð ð ð ð+Ý"ð+Ý4<ð+ÝDKð+àð+ð +ð +ð +ð +ð +ð +ð +ð +õZ & d°GÐ<Ñ<Ô<ˆHØ,ð 7ð 7�
Ý!/°
¸GÑ!DÔ!D�Ø�˜ >°2Ñ6Ô6Ð6Ð6ØøøøøðgSøøøs   “$ ¤
C®BB=Â=Cc                 ó  — t          | t          ¦  «        r|                      ¦   «         } t          | t          j        j        ¦  «        rt          j        | j        ¦  «        nt          j        | ¦  «        }|�|ni } |j	        |i |¤Žj
        S r4   )rè   r   Úmodulerê   ÚnnÚModuleÚinspectÚ	signatureÚforwardÚbindÚ	arguments)r  r-  Úkwargsr6  s       r,   Ú_combine_argsr;  Ö  sŠ   € õ �!•_Ñ%Ô%ð Ø�HŠH‰JŒJˆõ �a�œœÑ)Ô)ð	"�Ô˜!œ)Ñ$Ô$Ð$åÔ˜qÑ!Ô!ð ð
 Ð)ˆVˆV¨r€FØˆ9Œ>˜4Ð* 6Ð*Ð*Ô4Ð4r+   c                   ó2   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zdd„ZdS )	ÚShapesCollectiona*  
    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)

    To specify dynamism for integers, we need to first wrap the integers using
    _IntWrapper so that we have a "unique identification tag" for each integer.

    Example::

        args = {"x": tensor_x, "others": [int_x, int_y]}
        # Wrap all ints with _IntWrapper
        mapped_args = pytree.tree_map_only(int, lambda a: _IntWrapper(a), args)

        dynamic_shapes = torch.export.ShapesCollection()
        dynamic_shapes[tensor_x] = (dim, dim + 1, 8)
        dynamic_shapes[mapped_args["others"][0]] = Dim.DYNAMIC

        # This is equivalent to the following (now auto-generated):
        # dynamic_shapes = {"x": (dim, dim + 1, 8), "others": [Dim.DYNAMIC, None]}

        torch.export(..., args, dynamic_shapes=dynamic_shapes)
    c                 ó   — i | _         d S r4   )Ú_shapesr~   s    r,   rT   zShapesCollection.__init__  s   € ØˆŒˆˆr+   c                 ó8  — t          |t          j        t          f¦  «        st	          dt          |¦  «        › �¦  «        ‚t          |¦  «        }|| j        v r*| j        |         }||k    rt	          d|› d|› �¦  «        ‚d S || j        t          |¦  «        <   d S )Nz:Cannot assign shape to non-tensor or non-_IntWrapper type z0Shapes assigned to input do not match: expected r  )rè   rê   ÚTensorrÒ   r<   r/   Úidr?  )r=   rþ   Úshaper    Ú_shapes        r,   Ú__setitem__zShapesCollection.__setitem__  sµ   € Ý˜!�eœl­KÐ8Ñ9Ô9ð 	Ý ØVÍTÐRSÉWÌWÐVÐVñô ð õ �!‰uŒuˆØ�4”<ÐÐØ”\ $Ô'ˆFØ˜ŠˆÝ$Ø\ÀvÐ\Ð\ÐUZÐ\Ð\ñô ð ð ˆð
 #(ˆDŒL�˜A™œÑÐÐr+   c                 ó`   — t          |¦  «        }|| j        vr
i | j        |<   | j        |         S r4   )rB  r?  )r=   rþ   r    s      r,   Ú__getitem__zShapesCollection.__getitem__#  s3   € Ý�!‰uŒuˆØ�t”|Ð#Ð#Ø!#ˆDŒL˜ÑØŒ|˜DÔ!Ð!r+   c                 ó*   — t          | j        ¦  «        S r4   )Úlenr?  r~   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                 ó|   •— t          |¦  «        }|‰j        v r"‰                     |¦  «         ‰j        |         S d S r4   )rB  r?  rñ   )r  rþ   r    r=   Út_idss      €€r,   Ú
find_shapez3ShapesCollection.dynamic_shapes.<locals>.find_shape3  s<   ø€ Ý�a‘5”5ˆDØ�t”|Ð#Ð#Ø—	’	˜$‘”�Ø”| DÔ)Ð)à�tr+   c              3   ó    •K  — | ]}|‰vV — Œ	d S r4   r*   )r›   r    rM  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?)r"  r;  r0  Úanyr?  r,  )r=   Úmr-  r:  rN  Úcombined_argsrû   rM  s   `      @r,   rû   zShapesCollection.dynamic_shapes,  s–   øø€ õ
 ‘”ˆð	ð 	ð 	ð 	ð 	ð 	õ & a¨¨vÑ6Ô6ˆÝ,¨Z¸ÑGÔGˆÝÐ:Ð:Ð:Ð:¨T¬\Ð:Ñ:Ô:Ñ:Ô:ð 	Ýðdñô ð ð
 Ðr+   r4   )	r#   r$   r%   r&   rT   rE  rG  rJ  rû   r*   r+   r,   r=  r=  å  so   € € € € € ð&ð &ðPð ð ð(ð (ð (ð$"ð "ð "ð!ð !ð !ðð ð ð ð ð r+   r=  c                   ó.   — e Zd ZdZd„ Zdd„Zdd„Zd„ ZdS )r    aQ  
    Infers dynamic_shapes based on additional inputs.

    This is useful particularly for deployment engineers who, on the one hand, may
    have access to ample testing or profiling data that can provide a fair sense of
    representative inputs for a model, but on the other hand, may not know enough
    about the model to guess which input shapes should be dynamic.

    Input shapes that are different than the original are considered dynamic; conversely,
    those that are the same as the original are considered static. Moreover, we verify
    that the additional inputs are valid for the exported program. This guarantees that
    tracing with them instead of the original would have generated the same graph.

    Example::

        args0, kwargs0 = ...  # example inputs for export

        # other representative inputs that the exported program will run on
        dynamic_shapes = torch.export.AdditionalInputs()
        dynamic_shapes.add(args1, kwargs1)
        ...
        dynamic_shapes.add(argsN, kwargsN)

        torch.export(..., args0, kwargs0, dynamic_shapes=dynamic_shapes)
    c                 ó   — g | _         d S r4   )Ú	_examplesr~   s    r,   rT   zAdditionalInputs.__init__a  s   € ØˆŒˆˆr+   Nc                 óæ   — t          |¦  «        t          urt          d|› d�¦  «        ‚|�)t          |¦  «        t          urt          d|› d�¦  «        ‚| j                             ||f¦  «         dS )zC
        Additional input :func:`args` and :func:`kwargs`.
        zRepresentative args z must be a tupleNzRepresentative kwargs z must be None or a dict)r/   r�   r<   r  rU  rB   )r=   r-  r:  s      r,   rñ   zAdditionalInputs.addd  s‡   € õ
 �‰:Œ:�UÐ"Ð"Ý Ð!N¸Ð!NÐ!NÐ!NÑOÔOÐOØÐ¥$ v¡,¤,µdÐ":Ð":Ý ØH¨ÐHÐHÐHñô ð ð 	Œ×Ò˜t V˜nÑ-Ô-Ð-Ð-Ð-r+   c                 ób   ‡— ˆfd„||fg| j         ¢D ¦   «         ^}}d„ }t          ||g|¢R dd„ iŽS )zÈ
        Infers a :func:`dynamic_shapes` pytree structure by merging shapes of the
        original input :func:`args` and :func:`kwargs` and of each additional input
        args and kwargs.
        c           
      óV   •— g | ]%\  }}t          d „ t          ‰||¦  «        ¦  «        ‘Œ&S )c                 ób   — t          |t          j        ¦  «        rt          |j        ¦  «        n|S r4   )rè   rê   rA  r�   rC  )r  rþ   s     r,   r[   z<AdditionalInputs.dynamic_shapes.<locals>.<listcomp>.<lambda>z  s$   € µ*¸QÅÄÑ2MÔ2MÐ T¥ a¤g¡¤ ÐST€ r+   )r0  r;  )r›   r-  r:  rQ  s      €r,   r   z3AdditionalInputs.dynamic_shapes.<locals>.<listcomp>x  sN   ø€ ð 1
ð 1
ð 1
ñ
 ��fõ	  ØTÐTÝ˜a  vÑ.Ô.ñô ð1
ð 1
ð 1
r+   c                 óv  ‡ — t          ˆ fd„|D ¦   «         ¦  «        st          d‰ f|z   › d�¦  «        ‚t          ‰ t          ¦  «        r>t          ‰ t          ¦  «        s)t          ˆ fd„|D ¦   «         ¦  «        rd S t
          j        S t          ˆ fd„|D ¦   «         ¦  «        st          d‰ f|z   › d�¦  «        ‚d S )Nc              3   óT   •K  — | ]"}t          ‰¦  «        t          |¦  «        u V — Œ#d S r4   )r/   )r›   rZ   Úvs     €r,   rœ   zJAdditionalInputs.dynamic_shapes.<locals>._mark_dynamism.<locals>.<genexpr>�  s4   øè è € ÐDÐD°%•t˜A‘w”w¥$ u¡+¤+Ð-ÐDÐDÐDÐDÐDÐDr+   z^The following inputs were found to have differing types, so they cannot be marked as dynamic: ú.c              3   ó$   •K  — | ]
}|‰k    V — Œd S r4   r*   ©r›   Úother_vr\  s     €r,   rœ   zJAdditionalInputs.dynamic_shapes.<locals>._mark_dynamism.<locals>.<genexpr>ˆ  s'   øè è € Ð<Ð<¨�w !’|Ð<Ð<Ð<Ð<Ð<Ð<r+   c              3   ó$   •K  — | ]
}|‰k    V — Œd S r4   r*   r_  s     €r,   rœ   zJAdditionalInputs.dynamic_shapes.<locals>._mark_dynamism.<locals>.<genexpr>�  s'   øè è € Ð@Ð@¨G˜7 aš<Ð@Ð@Ð@Ð@Ð@Ð@r+   z`The following inputs were found to have differing values, but they cannot be marked as dynamic: )Úallr,  rè   rH   rI   r   r)   )r\  Úother_vss   ` r,   Ú_mark_dynamismz7AdditionalInputs.dynamic_shapes.<locals>._mark_dynamism€  s  ø€ ÝÐDÐDÐDÐD¸8ÐDÑDÔDÑDÔDð Ý ðOØ=>¸DÀ8¹OðOð Oð Oñô ð õ
 ˜!�SÑ!Ô!ð ­*°Q½Ñ*=Ô*=ð ÝÐ<Ð<Ð<Ð<°8Ð<Ñ<Ô<Ñ<Ô<ð 'Ø˜4åœ;Ð&åÐ@Ð@Ð@Ð@°xÐ@Ñ@Ô@Ñ@Ô@ð Ý$ðTØBCÀÈÁðTð Tð Tñô ð ð �tr+   rÿ   c                 ó.   — t          | ¦  «        t          u S r4   )r/   rH   )r  s    r,   r[   z1AdditionalInputs.dynamic_shapes.<locals>.<lambda>˜  s   € �d 1™gœg­˜n€ r+   )rU  r   )r=   rQ  r-  r:  rû   Úother_dynamic_shapesrd  s    `     r,   rû   zAdditionalInputs.dynamic_shapesq  s‹   ø€ ð1
ð 1
ð 1
ð 1
ð
 #'¨ Ð A°$´.Ð Að1
ñ 1
ô 1
Ð-ˆÐ-ð	ð 	ð 	õ( ØØð
ð "ð
ð 
ð 
ð -Ð,ð	
ð 
ð 	
r+   c                 ó˜   — |                      ¦   «         }| j        D ]-\  }}t          j        j                             |||pi ¦  «         Œ.dS )zW
        Verifies that an exported program is valid for each additional input.
        N)r2  rU  rê   ÚexportÚ_unliftÚ#_check_input_constraints_for_module)r=   ÚepÚepmr-  r:  s        r,   ÚverifyzAdditionalInputs.verify›  s]   € ð
 �iŠi‰kŒkˆØ œNð 	ð 	‰LˆD�&ÝŒLÔ ×DÒDØ�T˜6˜< Rñô ð ð ð	ð 	r+   r4   )r#   r$   r%   r&   rT   rñ   rû   rm  r*   r+   r,   r    r    F  se   € € € € € ðð ð4ð ð ð.ð .ð .ð .ð(
ð (
ð (
ð (
ðT	ð 	ð 	ð 	ð 	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_dimensionrq  §  s&   € ð	(ð õ
 ‡K‚K�ÑÔÐÐÐr+   rR  c                 óh  ‡‡‡‡	‡
— 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t          dt          |¦  «        › �¦  «        ‚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#   r0   r1   r   r|   r  )r¡   rx   ry   Ú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          |¦  «        t          |j        ¦  «        k    rT ‰‰j        d|› dt          | ¦  «        › d	|j        › d
t          |j        ¦  «        › dt          |¦  «        › d�d¬¦  «        ‚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Expected dynamic shape spec z5` to have the same length as the actual tensor shape z (expected z
, but got 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   rq  rH   r.   r  r   r�   r	  rI  rC  r%  )r  ÚtensorrC  r  r¡   r  r  rx  s        €€€r,   Úcheck_symbolsz,_check_dynamic_shapes.<locals>.check_symbolsÏ  s
  ø€ Ý�e�TÑ"Ô"ð -	ØŸ+š+™-œ-ð ð ‘��3Ý˜c¥3Ñ'Ô'ð Ø%Ð% cÑ*Ô*Ð*Ð*Ø�[Ý9Ñ;Ô;Ð;Ð;Ý$ S­3µ¨/Ñ:Ô:ð Ø#˜)Ø%Ô3ð5Àð 5ð 5ÐZ_ð 5ð 5Ý7=¸d±|´|ð5ð 5ð %(ð5ð 5ð 5ð #>ðñ ô ð ððð õ ˜¥¥t˜}Ñ-Ô-ñ 	Ý�5‰zŒz�S ¤Ñ.Ô.Ò.Ð.Ø�iØ!Ô/ðT°5ð Tð TÕW]Ð^bÑWcÔWcð Tð TØJPÌ,ðTð Tå!$ V¤\Ñ!2Ô!2ðTð Tå>AÀ%¹j¼jðTð Tð Tð :ðñ ô ð õ $ EÑ*Ô*ð ð ‘��3Ý˜c¥3Ñ'Ô'ð Ø%Ð% cÑ*Ô*Ð*Ð*Ø�[Ý9Ñ;Ô;Ð;Ð;Ý$ S­3µ¨/Ñ:Ô:ð Ø#˜)Ø%Ô3ð4°ð 4ð 4È5ð 4ð 4Ý7=¸d±|´|ð4ð 4ð $'ð4ð 4ð 4ð #>ðñ ô ð ððð ð ÐØ�)ØÔ+ða°ð að aÕU[Ð\`ÑUaÔUað að að að 6ðñ ô ð ð Ðr+   z8expected dynamic_shapes to be dict, tuple, or list, got 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          |t          ¦  «        ret          |t          ¦  «        rt          d¦  «        ‚|�;t          |t          t          f¦  «        s!t          dt          |¦  «        › �¦  «        ‚d S d S |�<t          | ¦  «        } ‰‰j        d|› d|› dt          |¦  «        › d|› d�	d¬	¦  «        ‚d S )
NzdUnable to specify input integers as dynamic through named Dims. Please use Dim.AUTO/DYNAMIC instead.zIexpected dynamic_shape to be None, int, or _DimHint for _IntWrapper, got zCannot associate shape rz  z` to non-tensor type z at `inputsz` (expected None)r  r  )rè   rê   rA  rÒ   Ú_Dimr,  rH   r.   r<   r/   r   r  )r  rþ   Údynamic_shaper&  r  r  r}  s       €€€r,   Úcheck_shapez*_check_dynamic_shapes.<locals>.check_shape  sN  ø€ Ý�a�œÑ&Ô&ð 	ØˆM˜$  =Ñ1Ô1Ð1Ð1Ð1Ý˜�;Ñ'Ô'ð 	Ý˜-­Ñ.Ô.ð Ý ðAñô ð ð Ð(µØ¥¥X˜ñ2ô 2Ð(õ %ØuÕ`dÐerÑ`sÔ`sÐuÐuñô ð ð )Ð(Ð(Ð(ð Ð(Ý & t¡¤�Ø�iØ!Ô/ð_¨mð _ð _ÐZgð _ð _Ý*.¨q©'¬'ð_ð _Ø>Kð_ð _ð _à9ð	ñ ô ð ð )Ð(r+   Úinputsr÷   )r  r  r  rI  rè   r�   r	  r/   Úvaluesr  r<   ÚkeysÚsortedr  r0  )rR  rû   Úgot_keysÚexpected_arg_namesr  r�  r  r  rw  rx  r}  s         @@@@@r,   Ú_check_dynamic_shapesrˆ  °  s`  øøøøø€ ð ;Ð:Ð:Ð:Ð:Ð:Ð:Ð:àÐ¥ ^Ñ!4Ô!4¸Ò!9Ð!9ØˆÝ�.¥5­$ -Ñ0Ô0ð EØ,�˜^Ñ,Ô,¨]×-AÒ-AÑ-CÔ-CÑDÔDˆà)+€Fð6ð 6ð 6ð 6ð 6ð 6ð 6ð.ð .ð .ð .ð .ð .ð .õ` �n¥t­UµDÐ&9Ñ:Ô:ð 
ÝØ]ÅtÈNÑG[ÔG[Ð]Ð]ñ
ô 
ð 	
õ �.¥$Ñ'Ô'ð Ý˜×+Ò+Ñ-Ô-Ñ.Ô.ˆÝ! -×"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ðñ ô ð ðð ð ð ð ð ð õ2 ˜ ]°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„Šdˆ	ˆˆ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                 óL  •‡ ‡‡‡
‡— 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¬¦  «        ¦  «        }	nxt          ‰ t0          ¦  «        st3          d
t5          ‰ ¦  «        › �¦  «        ‚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   r‰   r#   rs   ÚEqrC  rH   ÚCONSTRAINT_VIOLATION)
ÚsymbolÚexprÚsolutionr  r  r¡   r  rq   r|  r‹  s
      €€€€€€€r,   Ú
root_valuezB_process_dynamic_shapes.<locals>.to_constraint.<locals>.root_valueX  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¬   )rA   r¤   rÉ   zexpected dim to be Dim, got )rq   r¯   r   Útorch.utils._sympy.solver‹  r°   r¨   rè   rv   r‰   r#   rŸ   r    r¡   rÈ   r0   r1   rË   rB  rs   rB   r€   r£   r�   r   r<   r/   )r¡   r|  r  r   r¨   r“  Údim_rootÚroot_constraintr‰   rØ   rq   r‹  r  r  Ú%derived_constraints_with_phantom_rootÚphantom_rootsÚsymbolss   ```       @@€€€€€r,   Úto_constraintz._process_dynamic_shapes.<locals>.to_constraintQ  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Ø#ðñ ô ñ	ô ˆJˆJõ ˜c¥3Ñ'Ô'ð QÝ$Ð%OÅDÈÁIÄIÐ%OÐ%OÑPÔPÐPÝ$Ý�6‘
”
ØØ”Ø&Ð&Ø"�{¨¬¸¼Ð@Ñ@Ô@Ø#ðñ ô ñ	ô ˆJð Ðr+   r7   c                 ó   •— d„ }t          |t          t          f¦  «        rQt          |t          ¦  «        r || ||¦  «        } ‰|| |¦  «        }‰|j                                      |¦  «         d S t          |t
          ¦  «        rÓ|j        t          j        k    r!t          j
                             | |¦  «         nk|j        t          j        k    r!t          j
                             | |¦  «         n5|j        t          j        k    r t          j
                             | |¦  «         ‰                     t!          t#          | ¦  «        |¦  «        ¦  «         d S |€"t          j
                             | |¦  «         d S d S )Nc                 ó    — t          |¦  «        S r4   )r€   )r|  r  r�   s      r,   Ú_create_static_dimzN_process_dynamic_shapes.<locals>._parse_tensor_dim.<locals>._create_static_dim¨  s   € Ý˜eÑ$Ô$Ð$r+   )rè   rH   r   r#   rB   r.   r/   r"   r'   rê   rë   Úmaybe_mark_dynamicr(   Úmark_staticr)   Úmark_dynamicrÎ   rB  )r|  Úidxr¡   r�  rØ   Úconstraintsr™  rš  s        €€€r,   Ú_parse_tensor_dimz2_process_dynamic_shapes.<locals>._parse_tensor_dim§  si  ø€ ð	%ð 	%ð 	%õ �c�C¥˜:Ñ&Ô&ð 	3Ý˜#�sÑ#Ô#ð ;Ø(Ð(¨°°cÑ:Ô:�Ø&˜ s¨F°CÑ8Ô8ˆJØ�C”LÔ!×(Ò(¨Ñ4Ô4Ð4Ð4Ð4Ý˜�XÑ&Ô&ð 		3ØŒx�<Ô,Ò,Ð,Ý”×0Ò0°¸Ñ=Ô=Ð=Ð=Ø”�\Ô0Ò0Ð0Ý”×)Ò)¨&°#Ñ6Ô6Ð6Ð6Ø”�\Ô1Ò1Ð1Ý”×*Ò*¨6°3Ñ7Ô7Ð7Ø×ÒÕ1µ"°V±*´*¸cÑBÔBÑCÔCÐCÐCÐCØˆ[ÝŒM×%Ò% f¨cÑ2Ô2Ð2Ð2Ð2ð ˆ[r+   c                 ó,  •— t          ¦   «         |_        t          ¦   «         |_        t          ¦   «         |_        t          ¦   «         |_        t          ¦   «         |_        t          |t          ¦  «        r)|                     ¦   «         D ]\  }} ‰|||¦  «         Œd S t          |t          t          f¦  «        r$t          |¦  «        D ]\  }} ‰|||¦  «         Œd S |€1t          |                     ¦   «         ¦  «        D ]} ‰||d ¦  «         Œd S d S r4   )r"  Ú_dynamo_weak_dynamic_indicesÚ_dynamo_dynamic_indicesÚ_dynamo_dynamic_rangeÚ_dynamo_static_indicesÚ_dynamo_unbacked_indicesrè   r  r{  r�   r	  r%  Úranger¡   )r  r|  rC  r  r¡   r£  s        €r,   Úupdate_symbolsz/_process_dynamic_shapes.<locals>.update_symbols»  s0  ø€ õ /2©e¬eˆÔ+Ý),©¬ˆÔ&Ý'*¡u¤uˆÔ$Ý(+©¬ˆÔ%Ý*-©%¬%ˆÔ'å�e�TÑ"Ô"ð 	3ØŸ+š+™-œ-ð 2ð 2‘��3Ø!Ð! &¨!¨SÑ1Ô1Ð1Ð1ð2ð 2å˜¥¥t˜}Ñ-Ô-ð 	3Ý# EÑ*Ô*ð 2ð 2‘��3Ø!Ð! &¨!¨SÑ1Ô1Ð1Ð1ð2ð 2àˆ]Ý˜6Ÿ:š:™<œ<Ñ(Ô(ð 3ð 3�Ø!Ð! &¨!¨TÑ2Ô2Ð2Ð2ð ˆ]ð3ð 3r+   c                 ó–   •— t          |t          j        ¦  «        r ‰| ||¦  «         d S t          |t          ¦  «        r	||_        d S d S r4   )rè   rê   rA  rÒ   rÕ   )r  rþ   r€  r«  s      €r,   Úassoc_shapez,_process_dynamic_shapes.<locals>.assoc_shapeÎ  sZ   ø€ Ý�a�œÑ&Ô&ð 	'ØˆN˜4  MÑ2Ô2Ð2Ð2Ð2Ý˜�;Ñ'Ô'ð 	'ð 'ˆAŒJˆJˆJð	'ð 	'r+   r‚  r÷   )r7   N)r  r  r  rI  rè   r�   r	  r/   rƒ  r   r0  r‰   rA   rç   )rR  rû   r­  Ú$derived_constraint_with_phantom_rootÚphantom_root_nameÚdynamic_dimsr  r  r£  r¢  r—  r˜  r™  rš  r«  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ðTð Tð Tð Tð Tð Tð Tð Tð Tðl3ð 3ð 3ð 3ð 3ð 3ð 3ð 3ð(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                 ó`  — i }t          | d„ ¬¦  «        D ]˜}|€Œt          |t          ¦  «        rŒt          |t          ¦  «        r4|||j        <   t          |t
          ¦  «        r|j        ||j        j        <   Œdt          |t          ¦  «        st          dt          |¦  «        › �¦  «        ‚Œ™|S )Nc                 ó,   — t          | t          ¦  «        S r4   )rè   r   )rY   s    r,   r[   z'_get_dim_name_mapping.<locals>.<lambda>ñ  s   € ½:ÀaÍÑ;MÔ;M€ r+   r+  z!expected dim to be _DimHint, got )
r   rè   rH   r   r#   rv   r‰   r.   r<   r/   )rû   Úname_to_dimr¡   s      r,   Ú_get_dim_name_mappingrµ  í  sÈ   € ð €KÝ˜Ð1MÐ1MÐNÑNÔNð Vð VˆØˆ;àÝ�c�3ÑÔð 	VØÝ˜�SÑ!Ô!ð 	VØ(+ˆK˜œÑ%Ý˜#�{Ñ+Ô+ð :Ø14´�˜CœHÔ-Ñ.øå˜c¥8Ñ,Ô,ð VÝ$Ð%TÍÈcÉÌÐ%TÐ%TÑUÔUÐUðVàÐ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"t/          d|›dt1          |¦  «        › �¦  «        ‚t!          |‰j        ¦  «        rd ||¦  «        st/          d|› d�¦  «        ‚|‰|<   |                     t5          t7          t9          |j        ¦  «        ¦  «        ¦  «        ¦  «         t!          |t*          ¦  «        r|                     |j        j        ¦  «         Œý‰D ]}|‰vr||vrt/          d|›d�¦  «        ‚Œi Šˆˆˆˆfd„}tA          |||¦  «        S )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\('(.*)'.*\)rF   z!.* = Dim\('.*', min\=([0-9]+).*\)z.* = Dim\('.*'.*max\=([0-9]+)\)rL   z = zexpected shape_fixes[z2] to be int, Dim, _DerivedDim, or sympy.Expr, got zsympy.Expr z is not a supported equivalencezshape_fixes key z" not found in name_to_dim or rootsc                 óT  •— |�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rt          d|j        ›d�¦  «        ‚‰
|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 )Nzsymbol.name z not found in name_to_dimr   r   )rè   rH   r#   ÚExprrr   ÚnextÚiterÚfree_symbolsrA   r<   ÚpolysÚ	polytoolsÚdivrv   r‰   rs   )r  r¡   ÚdummyÚfixr�  r‰   ÚmodulusÚ	remainderÚ_dimÚderived_dim_cacher´  Úshape_fixesrq   s            €€€€r,   Úapply_fixesz?refine_dynamic_shapes_from_suggested_fixes.<locals>.apply_fixesa  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Ý"0Ø W¨v¬{Ð WÐ WÐ Wñ#ô #ð ð  +¨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+   )!Úrerq   r  r  r  r¯   r·  ÚsplitÚstripÚ	Exceptionr  ÚmatchÚgrouprH   r   rp   rè   ÚNumberrµ  r"  r{  rv   rº  r<   r/   rñ   rr   r»  r¼  r½  r‰   r#   r0  )r  rû   rÉ  r  r  r·  Úshape_fixes_msgÚexcrÂ  rÍ  rA   rR   rS   Ú	match_minÚ	match_maxr‘  Úrootsr  ÚcrÈ  rÆ  r´  rÇ  rq   s                       @@@@r,   r   r     s¦  øøøø€ ð@ €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¥3­°U´ZÐ@ÑAÔAð 	Ý Øh¨ÐhÐhÕ_cÐdeÑ_fÔ_fÐhÐhñô ð õ �a˜œÑ$Ô$ð 	7Ø,Ð,¨QÑ/Ô/ð WÝ$Ð%U°1Ð%UÐ%UÐ%UÑVÔVÐVØˆK˜‰NØ�IŠI•c�$�t A¤NÑ3Ô3Ñ4Ô4Ñ5Ô5Ñ6Ô6Ð6Ý�a�Ñ%Ô%ð 	'Ø�IŠI�a”f”oÑ&Ô&Ð&øð ð ð ˆØ�KÐÐ A¨U N NÝ ØJ 1ÐJÐJÐJñô ð øð
 13Ðð&ð &ð &ð &ð &ð &ð &ð &õP ˜{¨N¸NÑKÔKÐKs   œ-A
 Á

A+ÁA&Á&A+)IrÖ   r5  Úloggingr’   Úcollectionsr   Úcollections.abcr   Úenumr   r   Útypingr   r   r	   rê   Útorch.utils._pytreer
   r   r   r   r   r   r   r   r   r   r   r   Úexported_programr   rq   r   Útorch._guardsr   r¯   r   r   Ú__all__Ú	getLoggerr#   ro  r"   Ú	dataclassr.   r   r  r€   rv   rr   rH   r�   r   rŸ   r£   rÈ   rË   rÎ   r   rÒ   r	  r  r"  rö   r0  r;  r=  r    rq  rˆ  r±  rµ  r   r*   r+   r,   ú<module>rá     sœ  ðà Ð Ð Ð Ø €€€Ø €€€Ø 
€
€
€
Ø #Ð #Ð #Ð #Ð #Ð #Ø $Ð $Ð $Ð $Ð $Ð $Ø Ð Ð Ð Ð Ð Ð Ð Ø ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,à €€€ðð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð .Ð -Ð -Ð -Ð -Ð -ð ð WØÐÐÐÐÐà$Ð$Ð$Ð$Ð$Ð$ØVÐVÐVÐVÐVÐVÐVÐVðð ð €ð €gÔ˜Ñ!Ô!€ð
ð 
ð 
ð 
ð 
�4ñ 
ô 
ð 
ð Ôð,.ð ,.ð ,.ð ,.ð ,.ñ ,.ô ,.ñ Ôð,.ð^S@ð S@ð S@ð S@ð S@ñ S@ô S@ð S@ðl €ðð ð ð ð �ñ ô ð ð*Jð Jð Jð Jð J�#ñ Jô Jð Jð\ $(¸4ð	@ð 	@ð 	@Øð	@Ø˜D‘jð	@Ø.1°D©jð	@à
ˆ3�ˆ8„_ð	@ð 	@ð 	@ð 	@ð Ôðð ð ð ð ñ ô ñ Ôðð ÔðD
ð D
ð D
ð D
ð D
Ð#ñ D
ô D
ñ ÔðD
ðN Ôðð ð ð ð ñ ô ñ Ôðð" Ôð
ð 
ð 
ð 
ð 
Ð*ñ 
ô 
ñ Ôð
ð4 Ôð
ð 
ð 
ð 
ð 
Ð*ñ 
ô 
ñ Ôð
ð  Ð-Ñ-Ð0BÑB€
ð Ôð	Rð 	Rð 	Rð 	Rð 	Rñ 	Rô 	Rñ Ôð	Rð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$ð~ !ð	Dð Dð DØ
�3˜�8Ô
ðDà
ðDð ðDð �T‰zð	Dð
 	ðDð Dð Dð DðN5 d¨3°¨8¤nð 5ð 5ð 5ð 5ð^ð ^ð ^ð ^ð ^ñ ^ô ^ð ^ðB^ð ^ð ^ð ^ð ^ñ ^ô ^ð ^ðBð ð ðGXØ˜˜S˜”>ðGXà˜˜c˜”N U¨3¤ZÑ/°$°s´)Ñ;¸dÑBðGXð GXð GXð GXðTpØ˜˜S˜”>ðpà˜˜c˜”N U¨3¤ZÑ/°$°s´)Ñ;¸dÑBðpð 
ˆ*Ôðpð pð pð pðfØ˜˜c˜”N U¨3¤ZÑ/°$°s´)Ñ;¸dÑBðð ð ð ð(HLØ	ðHLà˜˜c˜”N U¨3¤ZÑ/°$°s´)Ñ;ðHLð 
ˆ#ˆsˆ(„^�e˜C”jÑ  4¨¤9Ñ,ðHLð HLð HLð HLð HLð HLr+   