ó
    CC˜jö  ã                   óê  • S r SSKrSSKrSSKrSSKrSSKrSSKJr  SSKJ	r	J
r
JrJrJr  SSKrSSKrSSKJr  SSKJr  SSKJrJrJrJrJr  SSKJr  SS	KJrJr  SS
KJ r   SSK!J"r"  SSK#J$r$  SSK%J&r&  SSK'J(r(J)r)  SSK*J+r+  SSK,J-r-J.r.  SSK/J0r0  SSK1J2r2J3r3J4r4J5r5  SSK6J7r7  SSK8J9r9  SSK:J;r;  SSK<J=r>  SSK?J@r@  \(       a  SSKAJBrB  SSK%JCrC  \Rˆ                  " \E5      rF\RŽ                  R‘                  \ES5      rI " S S\R”                  5      rK " S S\5      rLS\	S \\"\0-     4S! jrMS\	S \KS-  4S" jrNS#S$S%\	S&\O\P\	4   S \L4S' jrQS%\	S \L4S( jrRS#S$S%\	S&\O\P\	4   S \L4S) jrSS*\	S \	4S+ jrTS,\LS \U\;   4S- jrV\ " S. S/5      5       rW\ " S0 S15      5       rX\ " S2 S35      5       rY\ " S4 S55      5       rZ\W\X-  \Y-  \Z-  r[S6\	S \R¸                  S-  4S7 jr]S#S$S8\@\5   S \^4S9 jr_  S]S#S$S:\	S,\LS;S<S8\@\5   S-  S=\^S \^4S> jjr`S#S$S,\LS8\@\5   S \3S-  4S? jraS@\U\5S-     SA\U\5S-     S \O\5\54   4SB jrbS#S$SCSDS,\LSE\4S \^4
SF jrcS#S$S6\	S \^4SG jrdS#S$S6\	S,\LS \4S-  4SH jre   S^S#S$S6\	S,\LSI\PSJ\RÌ                  Rr                  SK\7S-  SL\g\	SM4   S:\ SN\	SO\hSCSPSQ\hS-  S S4SR jjriS#S$SS\	S%STS&\O\P\ 4   S \h4
SU jrjS#S$S6\	SQ\hS \4S-  4SV jrkS#S$S,\LSW\4S \ 4SX jrlS#S$SL\g\	SM4   SY\U\g\K\ 4      S \U\[   4SZ jrm " S[ S\\&5      rng)_z°
This module contains the InvokeSubgraphHigherOrderVariable class and its
supporting helpers for subgraph reuse (auto-cache) in Dynamo's invoke_subgraph
higher-order operator.
é    N)Ú	dataclass)ÚAnyÚcastÚ
NamedTupleÚTYPE_CHECKINGÚ	TypeGuard)Úgraph_break_hints)Úunimplemented)Úextract_tensor_metadataÚGUARD_VALUE_DISPATCHÚGuardCheckSpecÚ
SKIP_GUARDÚUnsupportedGuardCheckSpec)ÚSyntheticLocalSource)Ú_make_inlinedÚunpack_iterable)ÚVariableTracker)ÚConstantVariable)ÚUserFunctionVariable)ÚWrapHigherOrderVariable)ÚListVariableÚTupleVariable)ÚUnspecializedNNModuleVariable)ÚSymNodeVariableÚTensorVariable)ÚUserDefinedObjectVariable)ÚGuardÚInvokeSubgraphReuseConditionÚInvokeSubgraphReuseEntryÚSource)ÚNestedCompileRegionOptions)ÚGraphModule)ÚProxy)Ú_pytree)Ú
OrderedSet)ÚInstructionTranslatorBase)ÚSubgraphTracingInfoÚhierarchical_compilec                   ó$   • \ rS rSrSrSrSrSrSrg)ÚInputTagé®   ÚtensorÚsymnodeÚconstantÚobject© N)	Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__ÚTENSORÚSYMNODEÚCONSTANTÚOBJECTÚ__static_attributes__r0   ó    ÚµC:\Users\johnn\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\torch/_dynamo/variables/invoke_subgraph.pyr*   r*   ®   s   † Ø€FØ€GØ€HØƒFr:   r*   c                   ó|   • \ rS rSr% \\\\4      \S'   \\	S-     \S'   Sr
\\S'   Sr\R                  S-  \S'   Srg)	ÚInputFingerprintéµ   Úflat_vtsNÚarg_sourcesFÚhas_unknownÚtreespecr0   )r1   r2   r3   r4   ÚlistÚtupler*   r   Ú__annotations__r    rA   ÚboolrB   ÚpytreeÚTreeSpecr9   r0   r:   r;   r=   r=   µ   sC   ‡ à�5˜ ?Ð2Ñ3Ñ4Ó4à�f˜t‘mÑ$Ó$à€K�Óà'+€Hˆf�o‰o Ñ$Ö+r:   r=   ÚvtÚreturnc                 ó¤   • [        U [        5      (       a  g[        U [        5      =(       a$    [        U R                  [        R
                  5      $ )zêWhether a leaf VT is compared by value, via ``vt.value``.

Enum members are UserDefinedObjectVariable (not ConstantVariable) in
Dynamo, but they are immutable singletons, so value comparison is as
sound as it is for ConstantVariable.
T)Ú
isinstancer   r   ÚvalueÚenumÚEnum©rI   s    r;   Úis_constant_likerQ   À   s7   € ô �"Ô&×'Ñ'ØÜ�bÔ3Ó4×X¼ÀBÇHÁHÌdÏiÉiÓ9XÐXr:   c                 ó<  • [        U [        5      (       a  [        R                  $ [        U [        5      (       a  [        R
                  $ [        U 5      (       a  [        R                  $ [        U [        5      (       a  U R                  b  [        R                  $ g)z5Return the tag for a leaf VT, or None if unsupported.N)rL   r   r*   r5   r   r6   rQ   r7   r   Úsourcer8   rP   s    r;   Úclassify_vtrT   Î   so   € ä�"”n×%Ñ%Ü�‰ÐÜ	�Bœ×	(Ñ	(Ü×ÑÐÜ	˜"×	Ñ	Ü× Ñ Ð Ü	�BÔ1×	2Ñ	2°r·y±yÑ7Lô �‰ÐØr:   Útxr&   Ú
fn_args_vtÚkwargsc                 ó‚   • U(       d-  SnU H  n[        U5      b  M  Sn  O   U(       a  [        U5      $ [        XU5      $ )a†  Build an InputFingerprint by flattening (args, kwargs) via pytree.

Flattens the argument structure into leaf VTs, classifying each leaf as
tensor/symnode/constant/module. Also records the TreeSpec so that
cache lookups can verify structural equivalence.

Fast path: when kwargs is empty and all args are already leaf VTs
(tensor/symnode/constant/module), skip the pytree flatten entirely.
TF)rT   Úbuild_fingerprint_fastÚbuild_fingerprint_with_pytree)rU   rV   rW   Úall_leafrI   s        r;   Úbuild_input_fingerprintr\   à   sE   € ö ØˆÛˆBÜ˜2‹Ó&Ø �Ùñ ö Ü)¨*Ó5Ð5ä(¨¸Ó@Ð@r:   c                 óî   • / n/ nU  Ha  n[        U5      nUc"  [        S[        U5      R                   S35      eUR	                  XC45        UR	                  [        USS5      5        Mc     [        X5      $ )zCBuild fingerprint for the common case of flat leaf args, no kwargs.Nzclassify_vt returned None for z in fast pathrS   )rT   ÚAssertionErrorÚtyper1   ÚappendÚgetattrr=   )rV   r?   r@   rI   Útags        r;   rY   rY   û   s~   € à79€HØ')€KÛˆÜ˜"‹oˆØ‰;Ü Ø0´°b³×1BÑ1BÐ0CÀ=ÐQóð ð 	�‰˜˜	Ô"ð 	×Ñœ7 2 x°Ó6Ö7ñ ô ˜HÓ2Ð2r:   c                 óò   ^ ^^^^	^
• SSK Jn  / m/ mSm
S[        SS4UUU
4S jjmS[        S[        R                  4UU	U
U 4S	 jjm	UR                  T [        U5      U45      nT	" U5      n[        TTT
U5      $ )
aØ  Build fingerprint via pytree flatten for nested/kwargs cases.

Recurses over the pytree structure natively (untraced), inlining/tracing
only each container node's own ``flatten_fn`` rather than the full
recursive tree_flatten dispatch around it. This is safe because node-type
classification only depends on ``type()``, never on tensor values.

Note: skipping the traced registry dispatch also means we no longer
install guards on the pytree registry itself, for the plain-function
flatten_fn case (the non-FunctionType fallback below still traces the
full tree_flatten and so still installs them). That's fine either way:
this fingerprint is built fresh from the live registry on every
reuse-lookup (register_pytree_node isn't traceable, so the registry
can't change mid-trace), and reuse is separately gated on treespec/tag
equality. So a registry change between compiles can only make a cached
subgraph ineligible for reuse (has_unknown / treespec mismatch), never
silently wrong.
r   ©ÚSourcelessBuilderFrI   rJ   Nc                 ó„   >• [        U 5      nUc  Smg TR                  X45        TR                  [        U SS 5      5        g )NTrS   )rT   r`   ra   )rI   rb   r@   r?   rA   s     €€€r;   Úadd_leafÚ/build_fingerprint_with_pytree.<locals>.add_leaf)  s;   ø€ ä˜"‹oˆØ‰;Ø‰Kà�O‰O˜S˜IÔ&à×Ñœw r¨8°TÓ:Õ;r:   Únode_vtc                 ó*  >•  U R                  5       n[        R                  " U5      (       a  [
        R                  nU[        R                  ;  a  T" U 5        [        R                  " 5       $ [        R                  U   R                  n[        U[        R                  5      (       dW  [        T[        T[        R                  5      " U 5      5      u  p4[        TU5       H  nT" U5        M     UR                  5       $ [        T[        TU5      " U 5      5      u  pgUR                  5       n[        TU5       V	s/ s H  n	T" U	5      PM     n
n	[        R                   " XU
5      $ ! [         a    Sm[        R                  " 5       s $ f = fs  sn	f )NT)Úpython_typeÚNotImplementedErrorrG   Útreespec_leafÚis_namedtuple_classÚcollectionsÚ
namedtupleÚSUPPORTED_NODESÚ
flatten_fnrL   ÚtypesÚFunctionTyper   r   Útree_flattenÚas_python_constantrH   )ri   Ú	node_typerr   Ú	leaves_vtÚtreespec_vtÚleaf_vtÚchildren_vtÚ
context_vtÚcontextÚchildÚchild_specsrg   ÚflattenrA   rU   s              €€€€r;   r€   Ú.build_fingerprint_with_pytree.<locals>.flatten3  s\  ø€ ð	*Ø×+Ñ+Ó-ˆIô
 ×%Ò% i×0Ñ0Ü#×.Ñ.ˆIàœF×2Ñ2Ó2Ù�WÔÜ×'Ò'Ó)Ð)ä×+Ñ+¨IÑ6×AÑAˆ
Ü˜*¤e×&8Ñ&8×9Ñ9ô &5Ø”M "¤f×&9Ñ&9Ô:¸7ÓCó&Ñ"ˆIô +¨2¨yÖ9�Ù˜Ö!ñ :à×1Ñ1Ó3Ð3ä"1Ø”˜b *Ô-¨gÓ6ó#
Ñˆð ×/Ñ/Ó1ˆÜ3BÀ2À{Ô3SÓTÒ3S¨%‘w˜u–~Ñ3SˆÐTÜ�Š˜y°;Ó?Ð?øô? #ó 	*ØˆKÜ×'Ò'Ó)Ò)ð	*üò< Us   ƒE) Ä>FÅ)!FÆF)Útorch._dynamo.variables.builderre   r   rG   rH   ÚcreaterC   r=   )rU   rV   rW   re   Úcontainer_vtrB   rg   r@   r?   r€   rA   s   `     @@@@@r;   rZ   rZ     sŠ   ý€ õ. Bà79€HØ')€KØ€Kð<”_ð <¨÷ <ñ <ð#@œð #@¬V¯_©_÷ #@ò #@ðJ %×+Ñ+¨B´°jÓ1AÀ6Ð0JÓK€LÙ�|Ó$€Hä˜H k°;ÀÓIÐIr:   Úsym_numc                 ó.   • U R                   R                  $ )a2  Key for matching a symbolic input against a cached one.

Compares the symbolic expression rather than the SymInt object. Each tensor
holds its own SymInt objects, so two arguments carrying the same symbol
(e.g. the atom count threaded through successive layers) are distinct
objects. Equal expressions mean the same value, which is what reuse needs;
distinct symbols still have distinct expressions.

``expr`` rather than ``_expr`` on purpose: it has the ShapeEnv's
replacements applied, so a symbol that was specialized keys on the value it
was specialized to.
)ÚnodeÚexpr)r…   s    r;   Úsym_num_keyr‰   ^  s   € ð �<‰<×ÑÐr:   Úfingerprintc                 ó0  • [        5       n/ nU R                   Hy  u  p4U[        R                  [        R                  4;   d  M+  UR                  5       nUR                  U;  d  MM  UR                  UR                  5        UR                  U5        M{     U$ )z8Collect deduplicated proxies from tensor/symnode leaves.)	Úsetr?   r*   r5   r6   Úas_proxyr‡   Úaddr`   )rŠ   ÚseenÚflat_proxiesrb   rI   Úproxys         r;   Úget_flat_proxiesr’   n  st   € ä"›u€DØ "€LØ×'Ô'‰ˆØ”8—?‘?¤H×$4Ñ$4Ð5Õ5Ø—K‘K“MˆEØ�z‰z Õ%Ø—‘˜Ÿ™Ô$Ø×#Ñ# EÖ*ñ (ð Ðr:   c                   ó$   • \ rS rSr% Sr\\S'   Srg)ÚLiftedUserArgi{  zVLifted arg that came from a user argument (intermediate activation or explicit input).Úindexr0   N)r1   r2   r3   r4   Ú__doc__ÚintrE   r9   r0   r:   r;   r”   r”   {  s
   ‡ á`à†Jr:   r”   c                   ó$   • \ rS rSr% Sr\\S'   Srg)ÚLiftedCapturedSourcei‚  zRLifted arg that is a captured variable (e.g. a weight or parameter) with a Source.rS   r0   N©r1   r2   r3   r4   r–   r   rE   r9   r0   r:   r;   r™   r™   ‚  s
   ‡ á\à†Kr:   r™   c                   óR   • \ rS rSr% Sr\\S'   \\S4   \S'   \\S4   S-  \S'   Srg)	ÚLiftedSyntheticObjecti‰  zCLifted arg that is a TorchScriptObject with a SyntheticLocalSource.Úctor_fn.Ú	ctor_argsNÚctor_arg_sourcesr0   )	r1   r2   r3   r4   r–   r   rE   rD   r9   r0   r:   r;   rœ   rœ   ‰  s+   ‡ áMàƒLØ�S˜#�X‰ÓØ˜C ˜H‘o¨Ñ,Ö,r:   rœ   c                   ó$   • \ rS rSr% Sr\\S'   Srg)ÚLiftedBoundSymboli’  a‰  Lifted arg that is a SymInt already bound as a graph input.

SymInt graph inputs are created during tensor wrapping (not through
VariableBuilder.wrap_symint), so they aren't registered in
unspec_variable_map or variable_tracker_cache. Using LiftedCapturedSource
for these would resolve the source to a concrete Python int via
source.get_value() instead of reusing the existing symbolic proxy.
rˆ   r0   Nrš   r0   r:   r;   r¡   r¡   ’  s   ‡ ñð †Ir:   r¡   Úfn_varc                 óà   • [        U [        5      (       a  U R                  5       R                  $ [        U [        5      (       a*  U R
                  R                  R                  R                  $ g ©N)rL   r   Úget_functionÚ__code__r   rM   ÚforwardÚ__func__)r¢   s    r;   Úget_fn_coder©   ¥  sV   € Ü�&Ô.×/Ñ/Ø×"Ñ"Ó$×-Ñ-Ð-Ü	�FÔ9×	:Ñ	:à�L‰L× Ñ ×)Ñ)×2Ñ2ð	
ð r:   Útraced_sourcesc                 ó†   • U R                   R                  R                  U-  nU(       a  [        R	                  SU5        gg)a  Check if any source accessed by the subgraph has been mutated.

SideEffects.mutated_sources records the exact AttrSource for every
store_attr call. A simple set intersection with traced_sources tells
us whether any source the subgraph read was later written to.
z.subgraph_reuse: mutated sources detected -- %sTF)ÚoutputÚside_effectsÚmutated_sourcesÚhc_logÚdebug)rU   rª   Úoverlaps      r;   Úhas_mutated_varsr²   ¯  s;   € ð �i‰i×$Ñ$×4Ñ4°~ÑE€GÞÜ�‰Ø<Øô	
ð Ør:   Úbody_rÚtracing_infor'   Úhas_reuse_hash_fnc                 óÆ  • U(       dn  UR                   bI  SSR                  [        R                  " UR                   5      5      -   n[        R                  SU5        gU(       a  [        X5      (       a  g[        U[        5      (       a  Oª[        U[        [        45      (       ae  UR                   Vs/ s H/  n[        U[        5      (       a  M  [        U5      R                  PM1     nnU(       a  [        R                  SU5        gO*[        R                  S[        U5      R                  5        gUR                  (       a  [        R                  S5        ggs  snf )	u?  Best-effort check for whether a traced subgraph result can be reused.

It is possible that a subgraph is morally reusable but does not fall
into the limited support that Dynamo has today. Current limitations:
  - The subgraph must not have side effects.
  - No sourceful variable accessed by the subgraph may have been
    mutated, because guards are snapshotted on source values at trace
    time â€” if the underlying object changed since then, the cached
    guards would silently evaluate against stale values.
  - Output must be a single tensor, or a tuple/list of plain tensors.
  - All flattened inputs must be one of: tensor, symnode, constant
    (including enum members), or a sourceful user-defined object
    (nn.Modules included) â€” for sourceless or other input types we
    rely on the treespec and tags for structural matching, so only
    types with well-defined comparison semantics are supported.

When ``has_reuse_hash_fn`` is True, side-effect and mutation checks are
skipped because the hash key replaces guards â€” there are no guards to
go stale from mutations.
Ú
Ú z;subgraph_reuse: not eligible -- subgraph has side effects%sFzDsubgraph_reuse: not eligible -- output contains non-tensor types: %szJsubgraph_reuse: not eligible -- output type %s is not tensor or tuple/listz:subgraph_reuse: not eligible -- unsupported input VT typesT)Úside_effect_stackÚjoinÚ	tracebackÚformat_listr¯   r°   r²   rL   r   r   r   Úitemsr_   r1   rA   )	rU   r³   rŠ   r´   rª   rµ   Ú	stack_msgÚitemÚ
non_tensors	            r;   Úis_reuse_eligiblerÁ   Ã  s-  € ö8 Ø×)Ñ)Ñ5Ø˜rŸw™wÜ×%Ò% l×&DÑ&DÓEó ñ ˆIô �L‰LØMØôð æÔ.¨r×BÑBØä�&œ.×)Ñ)ØÜ	�Fœ]¬LÐ9×	:Ñ	:ð Ÿšó
â$�Ü˜d¤N×3ó  ŒD�‹J×ÔÙ$ð 	ð 
ö
 Ü�L‰LØVØôð ð ô 	�‰ØXÜ�‹L×!Ñ!ô	
ð à××Ü�‰ØHô	
ð àùò1
s   Â5EÃEc           	      óÂ  • SSK Jn  / nUR                   GH)  u  pVU[        R                  :X  a¬  [        U[        5      (       d!  [        S[        U5      R                   35      eUR                  R                  R                  R                  SS5      nUc  [        R                  S5          gUR!                  [        R                  [#        U5      45        MÆ  U[        R$                  :X  am  [        U[&        5      (       d!  [        S[        U5      R                   35      eUR!                  [        R$                  [)        UR*                  5      45        GMG  U[        R,                  :X  at  [/        U5      (       d!  [        S[        U5      R                   35      eUR!                  [        R,                  [        UR0                  5      UR0                  445        GMÏ  U[        R2                  :X  a$  UR!                  [        R2                  S45        GM  [        S	U S
[        U5      R                   S35      e   [5        U5      nUR7                  S UR8                   5       5        [5        5       n	U H7  n
U	R7                  U R:                  R<                  R?                  U
5      5        M9     / nU	 HÅ  nUR@                  n
URC                  5       n[D        R                  " U5      nU[F        L a  M@  Ub  [        U[H        5      (       a  [K        SU SU
RL                   S35      e U R:                  RO                  U
5      n[S        [T        U5      nURW                  XÏ5      nUR!                  X®UU45        MÇ     [        R                  S[Y        U5      5        U" UUURZ                  US9$ ! [P         a    [K        SU
RL                   S
U S35      Sef = f)a¸  Build an InvokeSubgraphReuseCondition from a traced subgraph.

A reuse condition is a mix of two kinds of checks:

1. **Input tag checks** (from flat_vts): For each flattened leaf VT,
   we record its tag (InputTag.TENSOR/SYMNODE/CONSTANT/OBJECT) and
   metadata (e.g. tensor shape/stride/dtype/device/requires_grad).
   At lookup time, the treespec ensures structural equivalence, and
   then we compare tags and metadata leaf-by-leaf.

2. **Guard checks** (from traced_sources): During the subgraph trace,
   every source accessed via VariableBuilder is recorded. We look up
   all guards installed on those sources (and on the arg_sources) to
   build the set of guards that must be re-evaluated on cache hit.
   This is more robust than guard diffing because it catches guards
   that were already installed before the subgraph trace began.

Raise if any guard type is unsupported, as a feedback for compiler
developers to support that guard type.
r   )r   ú,expected TensorVariable for TENSOR tag, got Úexample_valueNzKsubgraph_reuse: cannot build condition -- tensor input has no example_valueú.expected SymNodeVariable for SYMNODE tag, got ú0expected constant-like VT for CONSTANT tag, got zUnexpected input tag 'z' for z/ -- is_reuse_eligible should have rejected thisc              3   ó.   #   • U  H  oc  M  Uv •  M     g 7fr¤   r0   )Ú.0Úss     r;   Ú	<genexpr>Ú(build_reuse_condition.<locals>.<genexpr>N  s   é € ÐKÒ"9˜Q—q‘qÒ"9ùs   ‚Œ	z(subgraph_reuse: unsupported guard type 'z' on source 'Ú'z*subgraph_reuse: failed to resolve source 'z guardzNumber of guards %s)Úinput_checksÚguardsrB   rª   ).Útorch._guardsr   r?   r*   r5   rL   r   r^   r_   r1   r‘   r‡   ÚmetaÚgetr¯   r°   r`   r   r6   r   r‰   r…   r7   rQ   rM   r8   rŒ   Úupdater@   r¬   rÎ   Úget_guards_for_sourceÚoriginating_sourceÚcreate_fn_namer   r   r   ÚRuntimeErrorÚnameÚresolve_source_valueÚ	Exceptionr   r   Úget_metadata_fnÚlenrB   )rU   rŠ   rª   r   rÍ   rb   rI   ÚexampleÚall_sourcesÚall_relevant_guardsrS   Úguard_tuplesÚguardÚtype_strÚhandlerrM   Úexpecteds                    r;   Úbuild_reuse_conditionrä     sc  € õ2 ;à24€LØ×'Õ'‰ˆØ”(—/‘/Ó!Ü˜b¤.×1Ñ1Ü$ØBÄ4ÈÃ8×CTÑCTÐBUÐVóð ð —h‘h—m‘m×(Ñ(×,Ñ,¨_¸dÓCˆGØ‰Ü—‘Øaôñ Ø×Ñ¤§¡Ô2IÈ'Ó2RÐ SÖTØ”H×$Ñ$Ó$Ü˜b¤/×2Ñ2Ü$ØDÄTÈ"ÃX×EVÑEVÐDWÐXóð ð ×Ñ¤×!1Ñ!1´;¸r¿z¹zÓ3JÐ K×LØ”H×%Ñ%Ó%Ü# B×'Ñ'Ü$ØFÄtÈBÃx×GXÑGXÐFYÐZóð ð ×Ñ¤×!2Ñ!2´T¸"¿(¹(³^ÀRÇXÁXÐ4NÐ O×PØ”H—O‘OÓ#Ø×Ñ¤§¡°$Ð 7×8ä Ø(¨¨¨V´D¸³H×4EÑ4EÐ3Fð G>ð ?óð ñ? (ôL �nÓ%€KØ×ÑÑK +×"9Ò"9ÓKÔKÜ&)£eÐÛˆØ×"Ñ" 2§9¡9×#3Ñ#3×#IÑ#IÈ&Ó#QÖRñ ð HJ€LÛ$ˆØ×)Ñ)ˆØ×'Ñ'Ó)ˆÜ&×*Ò*¨8Ó4ˆà”jÒ Ùà‰?œj¨Ô2K×LÑLÜØ:¸8¸*ÀMÐRX×R]ÑR]ÐQ^Ð^_Ð`óð ð	Ø—I‘I×2Ñ2°6Ó:ˆEô ”~ wÓ/ˆØ×*Ñ*¨5Ó8ˆØ×Ñ˜V¨h¸Ð>Ö?ñ7 %ô: ‡L�LÐ&¬¨LÓ(9Ô:á'Ø!ØØ×%Ñ%Ø%ñ	ð øô! ó 	ÜØ<¸V¿[¹[¸MÈÐPXÈzÐY_Ð`óàðð	ús   Ì0N6Î6(OÚold_arg_sourcesÚnew_arg_sourcesc                 óp   • [        X5       VVs0 s H  u  p#Uc  M
  Uc  M  X#:w  d  M  X#_M     snn$ s  snnf )zOMap old arg sources to new arg sources for remapping captured variable sources.)Úzip)rå   ræ   ÚoldÚnews       r;   Úbuild_source_replacementrë   {  sI   € ô ˜OÔ=ôâ=‰HˆCØó 	à"ó 	à36±:ó 	ˆŠÙ=òð ùó s   �	2œ2¡2¨2Ú	conditionr   Úcached_entryc                 ó0  ^^• UR                   b0  UR                   UR                   :w  a  [        R                  S5        g[        UR                  5      [        UR
                  5      :w  a>  [        R                  S[        UR                  5      [        UR
                  5      5        g[        [        UR                  UR
                  5      5       GH³  u  nu  u  pVu  pxXW:w  a  [        R                  SUUU5          gU[        R                  :X  a«  [        U[        5      (       d!  [        S[        U5      R                   35      eUR                  R                   R"                  R%                  SS5      n	U	c  [        R                  SU5          g['        U	5      n
X¦:w  a  [        R                  S	U5          gMì  U[        R(                  :X  av  [        U[*        5      (       d!  [        S
[        U5      R                   35      e[-        UR.                  5      U:w  a$  [        R                  SUUUR.                  5          gGMv  U[        R0                  :X  d  GM�  [3        U5      (       d!  [        S[        U5      R                   35      e[5        [6        [        [8        4   U5      u  p¼[        UR:                  5      ULa-  [        R                  SUU[        UR:                  5      5          gUR:                  U:w  d  GM5  U[        UR<                  5      :  a  UR<                  U   OSnU[        UR<                  5      :  a  UR<                  U   OSnUb  Ub  GM’  [        R                  SUUUR:                  5          g   [?        UR<                  UR<                  5      mS[@        S[@        4U4S jjmT(       a   [C        U4S jURD                   5       5      nOURD                  n[G        X5      (       a  gT(       d  gU RH                  RJ                  RL                  U RH                  RJ                  RN                  S.n0 n0 nURP                   H»  u  nnnnURS                  T5      nUU:X  a  M!   URU                  UUU5      nURc                  UU5      (       a  MN  [        R                  SURY                  5       UURZ                  UUUR\                  (       a)  SR_                  UR\                  Ra                  5       5      OS5          g   g! [V         ao    [        R                  SURY                  5       UURZ                  UR\                  (       a)  SR_                  UR\                  Ra                  5       5      OS5           gf = f)ul  Check if a cached subgraph can be reused for the current call.

Three-phase check:
(1) Verify that intermediates (tensor metadata, symnode types, constant
    values) match the cached input_checks â€” these are lightweight
    structural comparisons that don't require source resolution.
(2) Check for mutations on the remapped traced_sources â€” if any source
    the subgraph read has been mutated since the original trace, the
    cached guards would evaluate against stale values.
(3) Build a source replacement mapping (old sources â†’ new sources) and
    re-evaluate the snapshotted guards under the new sources.
Nz1subgraph_reuse: reuse failed -- treespec mismatchFzMsubgraph_reuse: reuse failed -- input count mismatch: cached %d vs current %dzRsubgraph_reuse: reuse failed -- input %d tag mismatch: cached '%s' vs current '%s'rÃ   rÄ   zDsubgraph_reuse: reuse failed -- input %d tensor has no example_valuezAsubgraph_reuse: reuse failed -- input %d tensor metadata mismatchrÅ   zVsubgraph_reuse: reuse failed -- input %d symnode mismatch: cached '%s' vs current '%s'rÆ   z\subgraph_reuse: reuse failed -- input %d constant type mismatch: cached '%s' vs current '%s'zqsubgraph_reuse: reuse failed -- input %d constant mismatch with no source to replace: cached '%s' vs current '%s'rÉ   rJ   c                 ó&   >• TR                  X 5      $ r¤   ©rÑ   ©rÉ   Úsource_replacements    €r;   Úreplacement_fnÚ#is_reusable.<locals>.replacement_fn
  s   ø€ Ø!×%Ñ% aÓ+Ð+r:   c              3   óD   >#   • U  H  oR                  T5      v •  M     g 7fr¤   )Úclone)rÈ   rÉ   ró   s     €r;   rÊ   Úis_reusable.<locals>.<genexpr>  s   øé € ÐXÒ?W¸!Ÿg™g n×5Ð5Ò?Wùs   ƒ T©ÚGÚLz‚subgraph_reuse: reuse failed -- cannot resolve source
  guard type: %s
  guard source: %s
  guard source name: %s
  user stack:
%sr¸   z
<no stack>z…subgraph_reuse: reuse failed --
  guard type: %s
  guard source: %s
  guard source name: %s
  expected: %s
  got: %s
  user stack:
%s)2rB   r¯   r°   rÛ   rÍ   r?   Ú	enumeraterè   r*   r5   rL   r   r^   r_   r1   r‘   r‡   rÐ   rÑ   r   r6   r   r‰   r…   r7   rQ   r   rD   r   rM   r@   rë   r    r%   rª   r²   r¬   Úroot_txÚ	f_globalsÚf_localsrÎ   rö   Ú	get_valuerÙ   rÕ   r×   Ú
user_stackrº   ÚformatÚeval_fn)rU   rì   rŠ   rí   ÚiÚ
cached_tagÚ
cached_valÚcur_tagÚcur_vtrÜ   Úcur_metaÚcached_typeÚcached_valueÚ
cached_srcÚnew_srcÚremappedÚresolve_globalsÚresolve_localsÚresolve_cacherS   râ   rã   rà   Ú
new_sourcerM   ró   rò   s                            @@r;   Úis_reusabler  ‡  s   ù€ ð& ×ÑÑ%¨+×*>Ñ*>À)×BTÑBTÓ*TÜ�‰Ø?ô	
ð ô ˆ9×!Ñ!Ó"¤c¨+×*>Ñ*>Ó&?Ó?Ü�‰Ø[Ü�	×&Ñ&Ó'Ü�×$Ñ$Ó%ô	
ð
 ä<EÜˆI×"Ñ" K×$8Ñ$8Ó9÷=Ñ8ˆÑ8Ñ$ˆZÑ&7 wð Ó Ü�L‰LØdØØØô	ñ ØœŸ™Ó(Ü˜f¤n×5Ñ5Ü$ØBÄ4ÈÃ<×CXÑCXÐBYÐZóð ð —l‘l×'Ñ'×,Ñ,×0Ñ0°À$ÓGˆGØ‰Ü—‘ØZØôñ Ü.¨wÓ7ˆHØÓ%Ü—‘ØWØôñ ñ &ð œ8×+Ñ+Ó+Ü˜f¤o×6Ñ6Ü$ØDÄTÈ&Ã\×EZÑEZÐD[Ð\óð ô ˜6Ÿ>™>Ó*¨jÓ8Ü—‘ØlØØØ—N‘Nô	ñ ò 9ð œ8×,Ñ,Ö,Ü# F×+Ñ+Ü$ØFÄtÈFÃ|×G\ÑG\ÐF]Ð^óð ô )-¬U´4¼°9Ñ-=¸zÓ(JÑ%ˆKÜ�F—L‘LÓ!¨Ò4ô —‘ð<àØÜ˜Ÿ™Ó&ôñ Ø�|‰|˜|Ö+ð
 œ3˜|×7Ñ7Ó8Ó8ð !×,Ñ,¨QÒ/àð ð œ3˜{×6Ñ6Ó7Ó7ð  ×+Ñ+¨AÒ.àð ð
 Ñ%¨¬Ü—L‘LðQàØ"ØŸ™ôñ !ñc=ôf 2Ø× Ñ  +×"9Ñ"9óÐð,œ&ð ,¤V÷ ,ö ÜÔX¸y×?WÒ?WÓXÓX‰à×+Ñ+ˆÜ˜×%Ñ%Øö Øð
 �Y‰Y×Ñ×(Ñ(Ø�Y‰Y×Ñ×'Ñ'ñ'€Oð &(€NØ')€Mà,5×,<Ô,<Ñ(ˆ�˜ 5Ø—\‘\ .Ó1ˆ
ð ˜ÓÙð	Ø×(Ñ(¨¸.È-ÓXˆEð" �‰˜u h×/Ó/Ü�L‰Lð$ð ×$Ñ$Ó&ØØ—‘ØØà×#×#ð —‘˜×(Ñ(×/Ñ/Ó1Ô2à!ôñ" ñW -=ðZ øôI ó 	Ü�L‰Lð$ð
 ×$Ñ$Ó&ØØ—‘à×#×#ð —‘˜×(Ñ(×/Ñ/Ó1Ô2à!ôò ð	ús   Ñ>TÔA5VÖVc                 ó  • SSK Jn  U R                  R                  R                  R                  [        R                  R                  5      n[        X25      (       d  g[        U5      nUSL=(       a    XCR                  ;   $ )z?Cheap check: does the cache have any entries for this function?r   ©ÚInvokeSubgraphCacheFN)rÏ   r  r¬   Útracing_contextÚhop_dispatch_set_cacheÚ	get_cacheÚtorchÚ_higher_order_opsÚinvoke_subgraphrL   r©   Úsubgraph_reuse_cache)rU   r¢   r  Úinvoke_subgraph_cacheÚfn_codes        r;   Úhas_reuse_entriesr  S  sk   € õ
 2àŸI™I×5Ñ5×LÑL×VÑVÜ×Ñ×/Ñ/óÐô Ð+×AÑAØÜ˜&Ó!€GØ˜$Ð×X 7×.XÑ.XÑ#XÐXr:   c                 ó0  ^ ^• SSK Jn  T R                  R                  R                  R                  [        R                  R                  5      n[        XC5      (       d  g [        U5      nUc  g SSS[        S[        4UU 4S jjnUR                  XV5      $ )Nr   r  Úcondr   ÚentryrJ   c                 ó    >• [        TU TU5      $ r¤   )r  )r!  r"  rŠ   rU   s     €€r;   Ú	evaluatorÚ#find_reuse_match.<locals>.evaluatorv  s   ø€ ô ˜2˜t [°%Ó8Ð8r:   )rÏ   r  r¬   r  r  r  r  r  r  rL   r©   r   rF   Úfind_reuse_entry)rU   r¢   rŠ   r  r  r  r$  s   ` `    r;   Úfind_reuse_matchr'  c  s�   ù€ õ
 2àŸI™I×5Ñ5×LÑL×VÑVÜ×Ñ×/Ñ/óÐô Ð+×AÑAØÜ˜&Ó!€GØ�Øð
9Ø,ð9Ü5Mð9ä	÷9ð 9ð
 !×1Ñ1°'ÓEÐEr:   Ú	body_nameÚ	body_gmodÚconfigÚp_args.rÄ   Úmax_reuse_entriesz#InvokeSubgraphReuseCondition | NoneÚhash_keyc                 ó0  ^• SSK Jn  U
SL USL :w  d  [        S5      eU R                  R                  R
                  R                  [        R                  R                  5      n[        XÜ5      (       d  g[        U5      nUc  g[        XUR                  5      n[        U[        5      n/ m[        R                   " U4S jU5        [#        T5      nU Vs/ s Ha  n[        U[        R$                  5      (       d  M$  UR&                  UR)                  5       UR*                  UR,                  UR.                  4PMc     nn[1        UUUUUUUR2                  US9nU
b  UR5                  XêUU	5        gUc  [        S5      eUR7                  XëUU	5        gs  snf )a  Save a traced subgraph into the reuse cache for future cache hits.

Builds an InvokeSubgraphReuseEntry with the freevar mapping (how each
lifted arg maps back to user inputs or captured variables), output
metadata, and arg sources. On a future cache hit, stamp_out_subgraph
uses this entry to emit a new invoke_subgraph call without re-tracing.

Exactly one of ``condition`` or ``hash_key`` must be provided.
``condition`` stores the entry in the guard-based cache (linear scan);
``hash_key`` stores it in the hash-key cache (O(1) lookup).
r   r  Nz5Exactly one of condition or hash_key must be providedc                 ó~   >• U R                  5       (       d  [        U [        5      (       a  TR                  U 5      $ S $ r¤   )Ú	is_tensorrL   r   r`   )rI   Úuser_output_vtss    €r;   Ú<lambda>Ú"save_reuse_entry.<locals>.<lambda>°  s7   ø€ Ø�<‰<�>‰>œZ¨¬O×<Ñ<ð #×)Ñ)¨"Ó-ð àðr:   )r(  r)  r*  Úsubgraph_input_mappingÚsingle_tensor_outputÚoutput_metadatar@   Únum_user_outputsz0hash_key must not be None when condition is None)rÏ   r  r^   r¬   r  r  r  r  r  r  rL   r©   Úbuild_subgraph_input_mappingr?   r   r   ÚvisitrÛ   ÚTensorÚshapeÚstrideÚdtypeÚdeviceÚrequires_gradr   r@   Úadd_reuse_entryÚadd_reuse_entry_by_key)rU   r¢   rŠ   r(  r)  r*  r+  r³   rÄ   r,  rì   r-  r  r  r  r4  r5  r7  Útr6  r"  r1  s                        @r;   Úsave_reuse_entryrC  ~  s—  ø€ õ2 2à˜$Ð H°Ð$4Ó5ÜÐTÓUÐUàŸI™I×5Ñ5×LÑL×VÑVÜ×Ñ×/Ñ/óÐô Ð+×AÑAØä˜&Ó!€GØ�Øä9Ø
�K×(Ñ(óÐô & f¬nÓ=Ðð
 .0€OÜ×Òô	ð 	ô	ô ˜?Ó+Ðñ óâˆAÜ�aœŸ™×&ó 	Bˆ�‰�!—(‘(“*˜aŸg™g q§x¡x°·±ÓAÙð ð ô %ØØØØ5Ø1Ø'ð  ×+Ñ+Ø)ñ€Eð ÑØ×-Ñ-Ø Ð'8õ	
ð ÑÜ Ð!SÓTÐTØ×4Ñ4Ø˜uÐ&7õ	
ùò5s   Ã#FÃ=AFÚreuse_hash_fnúlist[VariableTracker]c                 óš  • SSK Jn  U R                  R                  R                  R                  5           [        X5      " U0 UD6n SSS5        [        W[        5      (       a  [        UR                  [        5      (       d  [        SU 35      eUR                  $ ! U a  n[        SU 35      UeSnAff = f! , (       d  f       Ny= f)uÂ   Trace the user's reuse_hash_fn to get a constant integer hash key.

Guards installed during the hash function tracing are skipped â€” the hash
key itself is the reuse condition, not the guards.
r   )ÚUnsupportedzAreuse_hash_fn must be fully traceable without graph breaks. Got: Nz2reuse_hash_fn must return a constant integer, got )Útorch._dynamo.excrG  r¬   r  Úguards_contextÚskip_guard_installr   rÖ   rL   r   rM   r—   )rU   rD  rV   rW   rG  ÚresultÚes          r;   Útrace_reuse_hash_fnrM  Ü  s¾   € õ .à	�‰×	"Ñ	"×	1Ñ	1×	DÑ	DÕ	Fð	Ü" 2Ô5°zÐLÀVÑL‰F÷ 
Gô �fÔ.×/Ñ/´zÀ&Ç,Á,ÔPS×7TÑ7TÜØ@ÀÀÐIó
ð 	
ð �<‰<Ðøð ó 	ÜØSÐTUÐSVÐWóàðûð	ú÷ 
GÕ	Fús(   µB<·BÂB9Â%B4Â4B9Â9B<Â<
C
c                 óþ   • SSK Jn  U R                  R                  R                  R                  [        R                  R                  5      n[        XC5      (       d  g [        U5      nUc  g UR                  XR5      $ )Nr   r  )rÏ   r  r¬   r  r  r  r  r  r  rL   r©   Úfind_reuse_entry_by_key)rU   r¢   r-  r  r  r  s         r;   rO  rO  ù  sk   € õ
 2àŸI™I×5Ñ5×LÑL×VÑVÜ×Ñ×/Ñ/óÐô Ð+×AÑAØÜ˜&Ó!€GØ�ØØ ×8Ñ8¸ÓKÐKr:   Úcachedc                 ó¨  ^ • SSK Jn  SSKJnJn  [        U5      nUR                  n[        UR                  U5      m / nU R                  R                  R                  U R                  R                  R                  S.n	0 n
0 nUR                   GHX  n[        U[        5      (       a  UR                  XlR                      5        M8  [        U["        5      (       a‰  SSKJn  U R                  R(                  R*                  UR,                     n[        Xí5      (       a3  U" 5       nXàR                  R(                  R*                  UR,                  '   UR                  U5        MÖ  [        U[.        5      (       aí  UR0                  nUR2                  nU(       a…  T (       a~  / n/ n[5        UU5       HT  u  nnUb)  UR7                  U 4S j5      nUR9                  XšU5      nUnUR                  U5        UR                  U5        MV     [;        U5      n[;        U5      nU R                  R=                  UR>                  UU5      nUR                  URA                  5       5        GMØ  [        U[B        5      (       d  GMð  URD                  nT (       a  UR7                  U 4S j5      nUR9                  XšU5      nU" U U5      " U5      nUR                  URA                  5       5        GM[     U RF                  c  [I        S	5      eU RF                     [;        S
 URJ                   5       5      nSSS5        U" XRL                  5      nUURL                  /UQ7nU" U [N        RP                  RR                  [;        U5      0 WURT                  5      nURV                  (       aM  URX                  n[        US   [Z        5      (       d$  [I        S[]        US   5      R^                   35      eUS   $ URX                  nUR`                  nUS:”  a3  U[c        U5      :  a$  SSK2J3n  URi                  U [;        USU 5      5      $ U$ ! , (       d  f       GN= f)a.  Emit a new invoke_subgraph call by stamping out a cached subgraph.

Sources in the cached entry are parameterized: they refer to the original
call's sources and must be rewritten to the current call's sources via
source replacement before we can look up or create the corresponding
graph placeholders.
r   )ÚVariableBuilder)Úadd_call_functionÚ	make_attrrø   )Ú	LazyProxyNc                 ó&   >• TR                  X 5      $ r¤   rð   rñ   s    €r;   r2  Ú$stamp_out_subgraph.<locals>.<lambda>=  s   ø€ Ð:L×:PÑ:PÐQRÔ:Vr:   c                 ó&   >• TR                  X 5      $ r¤   rð   rñ   s    €r;   r2  rW  M  s   ø€ Ð8J×8NÑ8NÈqÔ8Tr:   z4tx.fake_mode must not be None for stamp_out_subgraphc           	   3   óZ   #   • U  H!  u  pp4n[         R                  " UUUUUS 9v •  M#     g7f))r=  r>  r?  N)r  Úempty_strided)rÈ   r;  r<  r=  r>  Úreq_grads         r;   rÊ   Ú%stamp_out_subgraph.<locals>.<genexpr>X  s>   é € ð 	
ò ;QÑ6�˜u¨hô ×ÒØØØØØ&öò ;Qùs   ‚)+zExpected tensor output but got é   rd   )5r‚   rR  Ú(torch._dynamo.variables.higher_order_opsrS  rT  r’   r@   rë   r¬   rü   rý   rþ   r4  rL   r”   r`   r•   r¡   Útorch._dynamo.output_graphrU  Úcurrent_tracerÚbound_symbolsrˆ   rœ   rž   rŸ   rè   rö   rÿ   rD   Úsynthetic_graph_inputr�   r�   r™   rS   Ú	fake_moder^   r6  r(  r  r  r  r*  r5  r½   r   r_   r1   r7  rÛ   Úbuilderre   rƒ   )!rU   rŠ   rP  rR  rS  rT  r�   ræ   Únew_lifted_argsr  r  r  Úsubgraph_inputrU  r‘   rž   rŸ   Únew_ctor_argsÚnew_ctor_arg_sourcesÚvalÚarg_srcr  rI   r  rM   rÄ   Ú	body_noder+  Úflat_variabler½   Únre   rò   s!                                   @r;   Ústamp_out_subgraphrn    sµ  ø€ õ @ßUä# KÓ0€LØ!×-Ñ-€Oä1°&×2DÑ2DÀoÓVÐà€Oð �Y‰Y×Ñ×(Ñ(Ø�Y‰Y×Ñ×'Ñ'ñ'€Oð &(€NØ')€Mð !×7Õ7ˆÜ�n¤m×4Ñ4Ø×"Ñ" <×0DÑ0DÑ#EÖFÜ˜Ô(9×:Ñ:Ý<à—I‘I×,Ñ,×:Ñ:¸>×;NÑ;NÑOˆEÜ˜%×+Ñ+Ù›�ØNS—	‘	×(Ñ(×6Ñ6°~×7JÑ7JÑKØ×"Ñ" 5Ö)Ü˜Ô(=×>Ñ>Ø&×0Ñ0ˆIØ-×>Ñ>ÐÞÖ$6Ø "�Ø')Ð$Ü$'¨	Ð3CÖ$D‘L�C˜ØÑ*Ø")§-¡-Ô0VÓ"W˜Ø%×/Ñ/Ø+¸]ó˜ð #*˜Ø!×(Ñ(¨Ô-Ø(×/Ñ/°Ö8ñ %Eô " -Ó0�	Ü#(Ð)=Ó#>Ð Ø—‘×0Ñ0Ø×&Ñ&¨	Ð3CóˆBð ×"Ñ" 2§;¡;£=×1Ü˜Ô(<×=Ô=Ø'×.Ñ.ˆJÞ!Ø'×-Ñ-Ô.TÓU�
ð ×(Ñ(¨È-ÓXˆEÙ   ZÔ0°Ó7ˆBØ×"Ñ" 2§;¡;£=×1ñQ 8ðV 
‡|�|ÑÜÐSÓTÐTØ	�‹Üñ 	
ð ;A×:PÒ:Pó	
ó 	
ˆ÷ 
ñ ˜"×.Ñ.Ó/€IØ˜×)Ñ)Ð<¨OÑ<€FÙ%Ø
Ü×Ñ×/Ñ/Üˆf‹Ø
ØØ�‰ó€Mð ×"×"Ø×#Ñ#ˆÜ˜% ™(¤N×3Ñ3Ü Ø1´$°u¸Q±x³.×2IÑ2IÐ1JÐKóð ð �Q‰xˆà×Ñ€EØ×Ñ€AØˆ1ƒu�”S˜“Z“Ý.à ×'Ñ'¨¬E°%¸¸°)Ó,<Ó=Ð=ØÐ÷S 
Žús   ÌQÑ
Qr?   c                 óH  • 0 nSnU HU  u  pVU[         R                  [         R                  4;   d  M+  UR                  5       R                  nXs;  d  ML  XCU'   US-  nMW     / nUSS  GH¶  n	UR                  U	R                  S5      n
U
S:¼  a  UR                  [        U
5      5        MB  U	R                  R                  R                  SS5      nUb  UR                  OSnUb  UR                  O%U	R                  R                  R                  SS5      n[        U[        R                  5      (       a0  UR                  [        UR                  R                  5      5        Mý  Uc:  [!        SU	R                  R"                   S	U	R                  R$                   S
35      e[        U[&        5      (       aM  U R(                  R*                  R                  U5      nUb%  Uu  nnnUR                  [-        UUU5      5        GMœ  UR                  [/        U5      5        GM¹     U$ )a3  Build a mapping that records the origin of each lifted arg for a subgraph.

On a cache hit, we stamp out a new invoke_subgraph call and need to
reconstruct its argument list in the correct order. Each lifted arg
(p_args[2:], skipping body_node and body_name) comes from one of:

- LiftedUserArg: a user argument (intermediate activation or explicit input)
- LiftedCapturedSource: a captured variable (e.g. a weight or parameter)
- LiftedSyntheticObject: a TorchScriptObject with a SyntheticLocalSource
- LiftedBoundSymbol: a SymInt already bound as a graph input
r   r]  é   NéÿÿÿÿÚgraphargrÄ   zFreevar has no source: node.op=z node.name=zP -- this likely means a function argument was not included in the proxy matching)r*   r5   r6   r�   r‡   rÑ   r`   r”   rÐ   rS   rÜ   rL   r  ÚSymIntr¡   Ú_exprr^   Úopr×   r   r¬   Úsynthetic_source_ctor_inforœ   r™   )rU   r+  r?   Úproxy_node_to_idxÚidxrb   rI   r‡   r4  Úouter_proxyÚmatched_idxrr  rS   rÜ   Ú	ctor_infor�   rž   rŸ   s                     r;   r8  r8  ƒ  s  € ð  35ÐØ
€CÛ‰ˆØ”8—?‘?¤H×$4Ñ$4Ð5Õ5Ø—;‘;“=×%Ñ%ˆDØÕ,Ø*- $Ñ'Ø�q‘’ñ ð 57ÐØ˜a˜b”zˆØ'×+Ñ+¨K×,<Ñ,<¸bÓAˆØ˜!ÓØ"×)Ñ)¬-¸Ó*DÖEà"×'Ñ'×,Ñ,×0Ñ0°¸TÓBˆHØ(0Ñ(<�X—_’_À$ˆFð Ñ'ð × Ò à ×%Ñ%×*Ñ*×.Ñ.¨ÀÓEð ô
 ˜'¤5§<¡<×0Ñ0ð
 '×-Ñ-Ô.?ÀÇÁ×@RÑ@RÓ.SÔTÙØ‰~Ü$Ø5°k×6FÑ6F×6IÑ6IÐ5Jð K!Ø!,×!1Ñ!1×!6Ñ!6Ð 7ð 8OðPóð ô
 ˜&Ô"6×7Ñ7ØŸI™I×@Ñ@×DÑDÀVÓL�	ØÑ(Ø;DÑ8�G˜YÐ(8Ø*×1Ñ1Ü-¨g°yÐBRÓSôò Ø"×)Ñ)Ô*>¸vÓ*F×GñQ "ðR "Ð!r:   c                   óŽ   ^ • \ rS rSrSrSrSrSrSrSr	SSS\
SS	S
\\\
4   S\S\S\4U 4S jjrSSSS	S
\\\
4   S\
4S jrSrU =r$ )Ú!InvokeSubgraphHigherOrderVariableiÉ  z&torch.ops.higher_order.invoke_subgraphFTrU   r&   Úfn_vtrV   rE  rW   r)  Ú	attr_namerJ   c           	      ó¢  >• [        U[        [        45      (       d%  [        S[	        U5      S/ [
        R                  QS9  UR                  R                  R                  R                  [        R                  R                  5      n[        U[        5      (       a5  UR                  5       R                  nUR                  5       R                   n	O€[        U[        5      (       d!  [#        S[%        U5      R                    35      eUR&                  R(                  R*                  R                  nUR&                  R(                  R                   n	/ n
U(       a¤  UR-                  U5      n
Un[/        U
5       H‚  nXÁR                  R0                  ;  a  [#        SU S35      eUR                  R0                  U   nUR2                  (       d  [#        S5      eSS	KJn  U" X�X±R2                  5      (       d  M€  Us  $    [8        TU ]u  XX4US
5      n[<        R?                  SU	UU	[A        U
5      S-   5        U(       a  URC                  X�5        U$ )NzIEncountered non user function variable during invoke_subgraph HOP tracingz;invoke_subgraph does not support non user function variable©Úgb_typer}   ÚexplanationÚhintsz,expected UnspecializedNNModuleVariable, got zsubmodule 'z' not found in nn_modulesz0tx.fake_mode must be set for subgraph comparisonr   )Úare_same_graph_modulesÚsubgraphzZ%s: Installing subgraph with identifier '%s', bringing total count for '%s' function to %sr]  )"rL   r   r   r
   Ústrr	   ÚSUPPORTABLEr¬   r  r  r  r  r  r  r¥   r¦   r1   r^   r_   rM   r§   r¨   Úget_dynamo_installed_submodulesÚreversedÚ
nn_modulesrc  r^  r…  ÚsuperÚ install_subgraph_in_output_graphr¯   r°   rÛ   Úadd_dynamo_installed_submodule)ÚselfrU   r~  rV   rW   r)  r  r  r  Úfn_nameÚpreviously_installed_submodulesÚcurrent_modÚsubmodule_nameÚprevious_modr…  r(  Ú	__class__s                   €r;   r�  ÚBInvokeSubgraphHigherOrderVariable.install_subgraph_in_output_graphÕ  s  ø€ ô ˜%Ô"?ÔAUÐ!V×WÑWÜØcÜ˜E›
ØYØ6Ô)×5Ñ5Ð6ò	ð �I‰I×%Ñ%×<Ñ<×FÑFÜ×'Ñ'×7Ñ7óð 	ô �eÔ1×2Ñ2Ø×(Ñ(Ó*×3Ñ3ˆGØ×(Ñ(Ó*×3Ñ3‰Gä˜eÔ%B×CÑCÜ$ØBÄ4ÈÃ;×CWÑCWÐBXÐYóð ð —k‘k×)Ñ)×2Ñ2×;Ñ;ˆGØ—k‘k×)Ñ)×2Ñ2ˆGà*,Ð'Þ à%×EÑEÀgÓNð ,ð $ˆKô #+Ð+JÖ"K�Ø!¯©×)=Ñ)=Ó=Ü(Ø% nÐ%5Ð5NÐOóð ð  "Ÿy™y×3Ñ3°NÑC�Ø—|—|Ü(ØJóð õñ *Ø¨;¿¹÷ó ð *Ò)ñ# #Lô& ‘GÑ<Ø�z¨9°jó
ˆ	ô 	�‰ØhØØØÜÐ/Ó0°1Ñ4ô	
ö !Ø!×@Ñ@ÀÔTàÐr:   Úargsc                 óö  • SSK Jn  SSKJn  US   nUSS  nS nSn	S n
[	        US5      (       a8   UR                  5       n[        USS 5      n[        USS5      n	[        US	S 5      n
UR                  R                  (       + nU(       a|  U
by  U" S5         [        XXs5      nS S S 5        [        XW5      nUbL  [        R                  SUUUR                   5        [#        XU5      nU" S5         [%        XU5      sS S S 5        $ O„U(       a}  ['        X5      (       am  U" S5         [#        XU5      n[)        UUU5      nS S S 5        Wb@  [        R                  SUUR                   5        U" S5         [%        UWU5      sS S S 5        $ U R*                  c  [-        S5      eU" S5         U R/                  XXsU R*                  5      u  nnnnnnnnS S S 5        [1        W5      S:”  a"  [3        SSU SU 3S/ [4        R6                  QS9  [9        U[:        5      (       a  UWR<                  S'   WS   W/USS  Q7nU(       a�  [#        XU5      nU
b>  WR>                  n[A        UWUUUSS9(       d  [C        S5      e[E        UUUUWUUUWU	WS9  OCWR>                  n[A        UWUUU5      (       a#  [G        UUU5      nUb  [E        UUUUWUUUWU	US9  U" U[H        RJ                  RL                  [O        U5      UWWWUS9$ ! [         a    [        R                  S
SS9  e f = f! , (       d  f       GNˆ= f! , (       d  f       GNº= f! , (       d  f       GN= f! , (       d  f       GNÞ= f! , (       d  f       GN¡= f)Nr   )Údynamo_timed)Ú*_call_function_with_auto_output_flatteningr]  é   r¥   Ú __marked_compile_region_config__Ú+__marked_compile_region_max_reuse_entries__Ú'__marked_compile_region_reuse_hash_fn__zYFailed to extract nested_compile_region() config from InvokeSubgraphHigherOrderVariable. T)Úexc_infoÚinvoke_subgraph_reuse_hash_fnz?subgraph_reuse: hash key %d hit for '%s', reusing subgraph '%s'Úinvoke_subgraph_reuse_stamp_outÚinvoke_subgraph_reuse_lookupz9subgraph_reuse: cache hit for '%s', reusing subgraph '%s'z_HOP_NAME must not be NoneÚinvoke_subgraph_tracez"invoke_subgraph: kwargs unexpectedzargs: z
, kwargs: z3kwargs should have been flattened into lifted args.r�  Únested_region_config)rµ   zŠreuse_hash_fn was provided but the subgraph is not eligible for reuse. Check the logs with TORCH_LOGS='+hierarchical_compile' for details.)r-  )rì   )r*  )(Útorch._dynamo.utilsr™  r^  rš  Úhasattrr¥   ra   rÙ   ÚlogÚwarningr¬   ÚexportrM  rO  r¯   r°   r(  r\   rn  r  r'  Ú	_HOP_NAMEr^   Úcreate_wrapped_noderÛ   r
   r	   Ú
DYNAMO_BUGrL   r!   rÐ   rª   rÁ   rÖ   rC  rä   r  r  r  rD   )r�  rU   r—  rW   r™  rš  r¢   rV   r*  r,  rD  ÚfnÚreuser-  rP  rŠ   Úmatchr+  Úp_kwargsrÄ   r³   r)  r(  Úbody_graph_output_vtsr´   rª   rì   s                              r;   Ú_call_functionÚ0InvokeSubgraphHigherOrderVariable._call_function&  sö  € õ 	5õ	
ð �a‘ˆØ˜!˜"�Xˆ
àˆØÐØˆÜ�6˜>×*Ñ*ðØ×(Ñ(Ó*�Ü  Ð%GÈÓN�Ü$+ØÐEÀqó%Ð!ô !(ØÐAÀ4ó!�ð —I‘I×$Ñ$Ô$ˆö �]Ñ.ÙÐ=Õ>Ü.¨rÀ*ÓU�÷ ?ô -¨R¸ÓBˆFØÑ!Ü—‘ØUØØØ×$Ñ$ô	ô 6°bÀfÓM�Ù!Ð"CÕDÜ-¨b¸vÓF÷ EÑDð "ö Ô(¨×4Ñ4ÙÐ<Õ=Ü5°bÀfÓM�Ü(ØØØó�÷ >ð Ñ Ü—‘ØOØØ—O‘Oôñ
 "Ð"CÕDÜ-¨b°+¸uÓE÷ EÑDð �>‰>Ñ!Ü Ð!=Ó>Ð>ÙÐ1Õ2ð ×(Ñ(¨°ZÈÏÉÓXñ	ØØØØØØØ%Ø÷ 3ô ˆx‹=˜1ÓÜØ<Ø    j°°Ð9ØQðÜ&×1Ñ1ðò	ô �fÔ8×9Ñ9Ø5;ˆI�N‰NÐ1Ñ2ð �1‰IØð
ð �A�BˆZñ
ˆö Ü1°"À&ÓIˆKØÑ(Ø!-×!<Ñ!<�Ü(ØØØØ Ø"Ø&*÷ô 'ðJóð ô
 !ØØØØØØØØØ!Ø%Ø%óð ".×!<Ñ!<�Ü$Ø˜ ¨\¸>÷ñ ô !6ØØ#Ø&ó!�Ið
 !Ñ,Ü(ØØ"Ø'Ø%Ø%Ø"Ø"Ø"Ø)Ø-Ø&/òñ :ØÜ×#Ñ#×3Ñ3Ü�&‹MØØØØ!Øñ	
ð 		
øôU ó Ü—‘ØoØ!ð ñ ð ðú÷ ?Ö>ú÷ EÖDú÷ >Ö=ú÷ EÖDú÷
 3Ö2úsG   ¯7K> ÂL!Ã-L3Ä#MÅ1MÆ('M)Ë> LÌ!
L0Ì3
MÍ
MÍ
M&Í)
M8r0   )r1   r2   r3   r4   rª  Ú_ALLOW_FALLBACK_TO_EAGERÚsupports_input_mutationÚsupports_aliasingÚallow_side_effectsÚfilter_aliased_intermediatesr   Údictr‡  r"   r�  r²  r9   Ú__classcell__)r•  s   @r;   r}  r}  É  sÄ   ø† Ø8€IØ$ÐØ"ÐØÐØÐð $(Ð ðOà'ðOð ðOð ,ð	Oð
 �S˜/Ð)Ñ*ðOð ðOð ðOð 
÷Oðbn
à'ðn
ð &ðn
ð �S˜/Ð)Ñ*ð	n
ð
 
÷n
ò n
r:   r}  )NF)r›  NN)or–   ro   rN   Úloggingr»   rs   Údataclassesr   Útypingr   r   r   r   r   r  Útorch._higher_order_opsÚtorch._dynamor	   rH  r
   Útorch._dynamo.guardsr   r   r   r   r   Útorch._dynamo.sourcer   r¥  r   r   Útorch._dynamo.variables.baser   Ú torch._dynamo.variables.constantr   Ú!torch._dynamo.variables.functionsr   r^  r   Útorch._dynamo.variables.listsr   r   Ú!torch._dynamo.variables.nn_moduler   Útorch._dynamo.variables.tensorr   r   Ú$torch._dynamo.variables.user_definedr   rÏ   r   r   r   r    Ú'torch._higher_order_ops.invoke_subgraphr!   Útorch.fx.graph_moduler"   Útorch.fx.proxyr#   Útorch.utilsr$   rG   Útorch.utils._ordered_setr%   Útorch._dynamo.symbolic_convertr&   r'   Ú	getLoggerr1   r§  Ú_loggingÚgetArtifactLoggerr¯   rO   r*   r=   rQ   rT   r¹  r‡  r\   rY   rZ   r‰   rC   r’   r”   r™   rœ   r¡   ÚLiftedArgOriginÚCodeTyper©   rF   r²   rÁ   rä   rë   r  r  r'  ÚfxrD   r—   rC  rM  rO  rn  r8  r}  r0   r:   r;   Ú<module>rÕ     sˆ  ðñó Û Û Û Û Ý !ß BÕ Bã Û Ý +Ý +÷õ õ 6ß >Ý 8Ý =Ý BÝ Lß EÝ Kß JÝ J÷ó õ OÝ -Ý  Ý )Ý /ö ÝHÝLà×Ò˜Ó!€Ø	�‰×	)Ñ	)¨(Ð4JÓ	K€ôpˆt�y‰yô ô,�zô ,ðYØðYàÐÐ";Ñ;Ñ<ôYð�Cð ˜H t™Oô ð$AØ#ðAàðAð ��c�‰NðAð ô	Að63 sð 3Ð/?ô 3ð"OJØ#ðOJàðOJð ��c�‰NðOJð ô	OJðd˜ð  ô ð 
Ð"2ð 
°t¸E±{ô 
ð ÷ð ó ðð ÷ð ó ðð ÷-ð -ó ð-ð ÷
ð 
ó ð
ð Ð(Ñ(Ð+@Ñ@ÐCTÑTð ð
˜ð  §¡°Ñ 5ô ðØ#ðà˜vÑ&ðð 
ôð2 15Ø#ñEØ#ðEàðEð "ðEð (ð	Eð
 ˜vÑ&¨Ñ-ðEð ðEð 
õEðPmØ#ðmà!ðmð ˜vÑ&ðmð " DÑ(ô	mð`	Ø˜& 4™-Ñ(ð	à˜& 4™-Ñ(ð	ð 
ˆ&�&ˆ.Ñô	ðIØ#ðIà-ðIð "ðIð +ð	Ið
 
ôIðXYØ#ðYàðYð 
ôYð FØ#ðFàðFð "ðFð  Ñ$ô	FðJ Ø7;Øñ[
Ø#ð[
àð[
ð "ð[
ð ð	[
ð
 �x‰x×#Ñ#ð[
ð '¨Ñ-ð[
ð �#�s�(‰Oð[
ð ð[
ð ð[
ð ð[
ð 5ð[
ð �D‰jð[
ð 
õ[
ð|Ø#ðàðð (ðð ��oÐ%Ñ&ð	ð
 	ôð:LØ#ðLàðLð ðLð  Ñ$ô	Lð$uØ#ðuà!ðuð %ðuð ô	uðpC"Ø#ðC"à�#�s�(‰OðC"ð �5˜ ?Ð2Ñ3Ñ4ðC"ð 
ˆ/Ñô	C"ôLK
Ð(?õ K
r:   