
    ^jL                      U d Z ddlmZ ddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlmZmZ ddlmZmZmZmZmZm Z  ddl!m"Z" ddl#Z#ddl$Z#ddl%m&Z&m'Z' ddl(m)Z)m*Z* dd	l+m,Z,m-Z-m.Z. dd
l/m0Z0 ddl1m2Z2 ddl3m4Z4 ddl5m6Z6m7Z7m8Z8mZ9m:Z:m;Z; ddl<m=Z=m>Z>m?Z?m@Z@ ddlAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZKmLZLmMZMmNZNmOZOmPZPmQZQ ddlRmRZR ddlSmTZT ddlUmVZV ddl7mWZWmXZXmYZYmZZZm[Z[m\Z\m]Z]m^Z^m_Z_m`Z`maZa ddlbmcZc ddldmeZemfZf ddlgmhZhmiZimjZjmkZk ddllmmZmmnZnmoZompZp ddlqmrZrmsZs ddltmuZumvZvmwZw ddlxmyZymzZzm{Z{m|Z|m}Z}m~Z~mZmZ ddl:mZmZ ddlmZmZmZmZmZmZmZmZmZmZ ddlmZmZmZmZ ddlmZmZmZ dd lmZmZ dd!lmZ dd"lmZmZmZmZ dd#lmZ dd$lmZmZmZmZmZmZmZmZ dd%lmZmZ dd&lmZ dd'lmZmZmZmZmZ dd(lmZmZmZmZmZmZ dd)lmZmZ dd*lmZmZmZmZ dd+lmZ dd,lmZ dd-lmZmZmZ dd.lmZmZ dd/lmZmZmZmZmZ erdd0lmZmZ dd1lmZ dd2lmZ  ej                  eޫ      Ze#j                  j                  ed3      Ze#j                  j                  ed4      Ze#j                  j                  ed5      Ze#j                  j                  ed6      Z ej                         Z eːj                         D  ci c]  \  } }|  e|      j                   c}} Zd7ed8<    eej                        j                  Z eej                        j                  Zd9 ed:<   d; ed<<   e;jr                  ez  ez  Zd=ed><   e
j                  drd?       Zej                   G d@ dA             Zej                   G dB dC             Zej                   G dD dE             Zej                   G dF dG             Z G dH dI      Ze
j                  dsdJ       Zej                  	 	 	 	 dtdL       Zej                  	 	 	 	 dtdM       Zej                   G dN dO             Z G dP dQe      Z G dR dSe       Z G dT dUe       ZdudVZdvdWZe
j                  dwdX       Z	 	 	 	 	 	 	 	 dxdYZdZZdyd[Zdzd{d\Z		 	 	 	 	 	 d|d]Z
	 	 	 	 	 	 	 	 d}d^Zd~d_Z	 	 	 	 	 	 dd`Z G da dbe      Zej                   G dc dd             Z G de dKef      Z G dg dhe      Zej&                  dik\  r9e	j(                  D cg c]  \  }} eedj|v r|dkd ndl|dkd        ! c}}Zej                  	 	 	 	 	 	 	 	 ddm       Z G dn doe      Z G dp dqe      Zyc c}} w c c}}w )a  
Core module responsible for converting Python bytecode into TorchDynamo's symbolic execution format.

This module implements the bytecode-level tracing system that allows TorchDynamo to analyze
and transform Python code. It converts Python bytecode instructions into a symbolic format
that tracks the flow of tensors and other values through the program.

Key components:
- InstructionTranslatorBase: Base class for converting bytecode to symbolic execution
- InstructionTranslator: Main translator for function bytecode
- InliningInstructionTranslator: Handles inlining of called functions
- SpeculationLog: Manages state for speculative execution and rollback

The symbolic conversion process handles:
- Control flow (loops, conditionals, etc.)
- Function inlining and call stack management
- Tracking of program values and side effects
- Graph breaks and resumption points
- Exception handling and stack frame management

This is a core part of TorchDynamo's tracing system that enables ahead-of-time
optimization of PyTorch programs.
    )annotationsN)defaultdictdeque)AnycastNoReturnTYPE_CHECKING	TypeAliasTypeVar)TypeIs)DynamoProfilerStateFunctionTraceTiming)ObservedExceptionTensorifyScalarRestartAnalysis)InlinedCodeCachetracingTracingContext)	dump_file)
guard_bool)cache_method   )configexcgraph_break_hintsloggingtrace_rules	variables)get_indexofJUMP_OPNAMESlivevars_analysispropagate_line_nums)cleaned_instructionscreate_binary_slicecreate_call_functioncreate_call_function_excreate_copycreate_dup_topcreate_instructioncreate_jump_absolutecreate_rot_ncreate_swapget_call_callable_depthget_code_keysInstructionis_generatoris_jump_absolute	unique_id)code_context)	PyCodegen)%maybe_setup_comprehension_speculation)!augment_exc_message_with_hop_nameBackendCompilerFailedcollapse_resume_framesformat_frame_infoget_stack_above_dynamoraise_value_errorResumePrologueTracingErrorStepUnsupportedunimplementedUnsupported	UserError)get_funcname)GuardBuilderinstall_guard)CodeOptionsGraphCompileReasonOutputGraphStackLocalsMetadata)impl_IS_MAPPINGimpl_MATCH_CLASSimpl_MATCH_KEYSimpl_MATCH_SEQUENCE)DummyModuleExecutionRecorder)ContinueExecutionCache"IS_TRACING_RESUME_PROLOGUE_VARNAMEReenterWith)
AttrSourceDictGetItemSourceGlobalSourceGlobalWeakRefSourceLocalCellSourceLocalSourceSkipGuardSourceSource)is_builtin_constantis_forbidden)
_get_error_on_graph_breakcountersget_fake_valueget_instruction_source_311get_metrics_contextgraph_break_dup_warning_checkeristype
LazyStringproxy_args_kwargsunpack_iterable)SourceLocationtypestrValueMutationNewVariableTracker)FrameStateSizeEntryVariableBuilderwrap_fx_proxy)BuiltinVariableDictBuiltinVariable)ConstantVariable)ContextWrappingVariableGenericContextWrappingVariableWithEnterFunctionVariableWithExitFunctionVariableConstDictVariable)BaseUserFunctionVariable
CO_VARARGSCO_VARKEYWORDSLocalGeneratorFunctionVariableLocalGeneratorObjectVariableNestedUserFunctionVariableSkipFunctionVariableUserFunctionVariable)IteratorVariableMAX_ITERATOR_LIMIT)LazyVariableTracker)BaseListVariableListIteratorVariableListVariableSliceVariableTupleVariable)CellVariableExceptionVariableNullVariablePythonModuleVariableTracebackVariableUnknownVariable)NNModuleVariableUnspecializedNNModuleVariable)generic_boolgeneric_containsgeneric_getitervirtual_iterator_next)SetVariable)SymbolicStreamState)supported_comparison_opsSymNodeVariableTensorVariable)SymbolicTorchFunctionStateTorchFunctionModeVariable)RemovableHandleVariableUserDefinedClassVariable!UserDefinedExceptionClassVariable"UserDefinedExceptionObjectVariableUserDefinedObjectVariable)Callable	Generator)FakeTensorMode)CompilePackagegraph_breaks
trace_calltrace_sourcetrace_bytecodedict[str, Any]compare_op_handlersc                2    t        | g t        |      i       S N)handle_containsreversedtxargs_s      i/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/torch/_dynamo/symbolic_convert.py<lambda>r      s    (4.21     inc           
     J    t        | t        | g t        |      i       gi       S r   )
handle_notr   r   r   s      r   r   r      s(    J.x~.	34b5 r   znot inr
   ExceptionValsc                ,    t        j                  |       S )z
    Import the named module and cache the result. importlib.import_module()
    seems to do some filesystem checking to validate the name so not caching
    this can be slow.
    )	importlibimport_module)names    r   _import_moduler      s     ""4((r   c                  p    e Zd ZU ded<   ded<   ded<   ded<   dZd	ed
<   dZded<   dZded<   ddZddZy)SpeculationEntrystrfilenameintlinenoinstruction_pointerr.   instFbool_failedNzbool | Noneerror_on_graph_breakzGraphCompileReason | Nonereasonc                    d| _         || _        | j                  | j                  j                  }nd}t        j                  |      )z\
        Start tracing of the current frame over again, and don't take this branch.
        Tz!Unknown fail_and_restart_analysis)restart_reason)r   r   r   r   SpeculationRestartAnalysis)selfr   r   s      r   fail_and_restart_analysisz*SpeculationEntry.fail_and_restart_analysis  sB     $8!;;"![[//N@N,,NKKr   c                n    | j                   r)| j                  t        d      | j                  |_        yy)Nz9expected self.error_on_graph_break is not None to be trueTF)r   r   AssertionError)r   r   s     r   failedzSpeculationEntry.failed  s;    <<((0$O  '+&?&?B#r   )r   r   returnNone)r   InstructionTranslatorBaser   r   )	__name__
__module____qualname____annotations__r   r   r   r   r    r   r   r   r      sC    MK
GT(,+,(,F%,
Lr   r   c                      e Zd ZU dZ ej
                  e      Zded<   dZ	ded<   dZ
d	ed
<    ej
                  e      Zded<   dZd	ed<   ddZddZ	 	 	 	 	 	 	 	 	 	 ddZy)SpeculationLoga3  
    SpeculationLog replaces the prior copy_graphstate/restore_graphstate
    checkpointing.  Rather than saving/restoring state, we restart the
    dynamo conversion process over from the beginning -- but when we
    hit the start of the speculation that failed, we instead generate
    a graph break.
    default_factoryzlist[SpeculationEntry]entriesr   r   indexFr   graph_break_on_autograd_grad	list[str]autograd_grad_leaked_tensorsgraph_break_on_requires_grad_c                    d| _         y Nr   )r   r   s    r   restartzSpeculationLog.restart8  s	    
r   c                F    | j                   j                          d| _        y r   )r   clearr   r   s    r   r   zSpeculationLog.clear;  s    
r   c                6   t        | j                        | j                  k(  r'| j                  j                  t	        ||||             | j                  | j                     }d}| j                  dk7  r]| j                  | j                  dz
     }d|j
                   d|j                   d|j                  j                   d|j                   d	}|j                  |k(  r|j
                  |k(  r|j                  |k(  st        d	| j                   d
t        | j                         d|j
                   d|j                   d|j                  j                   d|j                   d| d| d|j                   d| d| d      | xj                  dz  c_        |S )z
        Lookup or create a SpeculationEntry() that is shared across
        RestartAnalysis calls.  Args are used only for debug checks.
         r   r   zPrevious instruction: :(z @ z)
z"
SpeculationLog diverged at index z
 (log had z entries):
- Expected:  (z at ip=z)
- Actual: a  
There are two usual reasons why this may have occurred:
- When Dynamo analysis restarted, the second run took a different path than
  the first.  If this occurred, the previous instruction is the critical instruction that
  behaved differently.
- Speculation entries are only added under certain conditions (as seen in
  step()), e.g., there must exist operators in the graph; those conditions may
  have changed on restart.

If this divergence was intentional, clear the speculation log before restarting (do NOT
do this for graph breaks, you will infinite loop).

Otherwise, please submit a bug report, ideally including the contents of TORCH_LOGS=+dynamo
)lenr   r   appendr   r   r   r   opnamer   SpeculationLogDivergence)r   r   r   r   r   entryprev_entry_msg
prev_entrys           r   nextzSpeculationLog.next?  s    t||

*LL 63FM TZZ(::?djj1n5J()<)<(=Qz?P?P>QJOO**+3z/M/M.NcS 
 %%)<<(*&*""&**ZDLL8I7J K^^Aell^2ejj.?.?-@HaHaGb c*AfXR}G4G3H I  	 ( 	

a
r   Nr   r   )
r   r   r   r   r   r   r   r.   r   r   )r   r   r   __doc__dataclassesfieldlistr   r   r   r   r   r   r   r   r   r   r   r   r   r   "  s     '8k&7&7&MG#ME3N */ $..?k.?.?PT.U )U +0!4/--%(-?B-JU-	-r   r   c                  F    e Zd ZU  ej                  e      Zded<   ddZy)
LocalStater   zdict[str, FrameStateSizeEntry]automatic_dynamicc                b    dj                  d | j                  j                         D              S )N
c              3  L   K   | ]  \  }}| d |j                            yw): N)render).0kvs      r   	<genexpr>z$LocalState.render.<locals>.<genexpr>v  s*      
%)QqcAHHJ< 
s   "$)joinr   itemsr   s    r   r   zLocalState.renderu  s/    yy 
-1-C-C-I-I-K
 
 	
r   Nr   r   )	r   r   r   r   r   dictr   r   r   r   r   r   r   r   o  s%    8I8I8I95 
r   r   c                  0    e Zd ZU ded<   ded<   dZded<   y)DistributedStater   
compile_pgr   local_stateNzlist[LocalState] | None
all_states)r   r   r   r   r  r   r   r   r	  r	  |  s    O*.J'.r   r	  c                  n    e Zd ZU  e       Zded<   edd       Zed	d       Zed
d       Z	edd       Z
y)TensorifyStatezset[str]force_specializationsc                :    | j                   j                  |       y r   )r  addclsr   s     r   
specializezTensorifyState.specialize  s    !!%%e,r   c                    || j                   v S r   )r  r  s     r   should_specializez TensorifyState.should_specialize  s    1111r   c                8    | j                   j                          y r   )r  r   r  s    r   r   zTensorifyState.clear  s    !!'')r   c                2    t        | j                        dk(  S r   )r   r  r  s    r   emptyzTensorifyState.empty  s    3,,-22r   N)r   r   r   r   )r   r   r   r   r   r   r   )r   r   r   setr  r   classmethodr  r  r   r  r   r   r   r  r    s_     '*e8+- - 2 2 * * 3 3r   r  c                 4    t        j                  t              S r   )torchdynamo_loggingget_step_loggerlogr   r   r   _step_loggerr"    s    ..s33r   r   c              #  D  K   | j                   j                  }| j                   j                  }	 g | j                   _        d| j                   _        d  || j                   _        || j                   _        y # || j                   _        || j                   _        w xY wwr   )speculation_logr   r   )r   r   r   s      r    save_and_restart_speculation_logr%    s        ((G$$E)%'"#$ %,"#(  &-"#( s   -B &A9 #B 9$BB c              #     K   	 | j                   j                  }d| j                   _        d  || j                   _        y # | j                   _        w xY wwNF)outputshould_exit)r   tmps     r   (temporarely_allow_writes_to_output_graphr+    sA     $ii## %		 #				s   A+A AAAc                  ^    e Zd ZU ded<   ded<   ded<   dZded	<   dd
ZddZ	 	 	 	 	 	 ddZy)BlockStackEntryr.   r   zInstruction | Nonetargetr   stack_indexNz?ContextWrappingVariable | GenericContextWrappingVariable | Nonewith_contextc                    | j                   d uS r   )r0  r   s    r   can_restorezBlockStackEntry.can_restore  s      ,,r   c                <   | j                   t        d      | j                  rbt        | j                  d      rL| j                  j                  r6t        | j                   dz
  t        | j                  j                              S t        | j                   dz
        S )Nz0expected self.stack_index is not None to be truetarget_valuesr   )r/  r   r0  hasattrr4  rO   tupler   s    r   	resume_fnzBlockStackEntry.resume_fn  s    # !STT))?;!!//  1$eD,=,=,K,K&L  t//!344r   c                    | j                   t        d      |r| j                   j                         s|s| j                   j                  |      S y )Nz1expected self.with_context is not None to be true)r0  r   exit_on_graph_breakexit)r   r   is_graph_breaks      r   r:  zBlockStackEntry.exit  sM     $ !TUUt00DDF$$))"--r   r  )r   rO   )r   r   r;  r   r   VariableTracker | None)r   r   r   r   r0  r2  r7  r:  r   r   r   r-  r-    sH     TXLQX-5	+	=A			r   r-  c                      e Zd Zy)r   Nr   r   r   r   r   r   r   r         r   r   c                      e Zd Zy)ReturnValueOpNr>  r   r   r   rA  rA    r?  r   rA  c                      e Zd ZdZy)YieldValueOpzY
    Signal to the symbolic tracer to stop and return control flow to the
    caller
    N)r   r   r   r   r   r   r   rC  rC    s    r   rC  c                    t        t        j                  |       j                        t	        |       t        j                  |       dfd       }|S )Nc                h    | j                  j                  | | j                        i              y r   )pushcall_functionpopn)r   r   fn_varnargss     r   implzstack_op.<locals>.impl  s'    		&&&tTYYu-=rBCr   )r   InstructionTranslatorr   r.   r   r   )r   inspect	signature
parametersrk   	functoolswraps)fnrK  rI  rJ  s     @@r   stack_oprS    sL    !!"%001ER F__RD D Kr   c                    t        | t        j                        sy| j                  j	                  d      d   t
        j                  v S )NF.r   )
isinstancetypes
ModuleTyper   splitsysstdlib_module_names)mods    r   	is_stdlibr]    s:    c5++,<<c"1%)@)@@@r   c                    | rdd}ndd}t        j                  |      D cg c]  }|j                   }}t        d t	        |      D              }|j                  d      }||dz   |dz    S c c}w )Nc                    | sJ d       y )Nmsgr   xs    r   rR  z(get_assert_bytecode_sequence.<locals>.fn  s    OeO1r   c                    | sJ y r   r   ra  s    r   rR  z(get_assert_bytecode_sequence.<locals>.fn  s	    H1r   c              3  J   K   | ]  \  }}|j                  d       s|  yw)POP_JUMPN)
startswith)r   ir   s      r   r  z/get_assert_bytecode_sequence.<locals>.<genexpr>  s     V71d$//*:UQVs   ##RAISE_VARARGSr   )rb  r   r   r   )disget_instructionsr   r   	enumerater   )with_msgrR  r   insts	begin_idxend_idxs         r   get_assert_bytecode_sequencerp    sr    		 &)%9%9"%=>TT[[>E> Vi&6VVIkk/*GQ1-- ?s   A/c                   |t         j                  us|ryt        | j                  t              st        d      | j                  }dD ]  }t        |      }| j                  ||t        |      z    }|D cg c]  }|j                   }}||k(  sH|r.|j                  d      }| j                  ||z      j                  }	nd}	| j                  t        j                  | |	              y yc c}w )NF=expected isinstance(self.instruction_pointer, int) to be true)FT
LOAD_CONSTzassertion errorT)operatortruthrV  r   r   r   rp  instructionsr   r   r   argvalrF  rg   build)
r   truth_fnrF  current_instruction_pointerrl  assert_insts	cur_instsr   load_const_idx	error_msgs
             r   &_detect_and_normalize_assert_statementr    s     	&4d..4K
 	
 #'":":! 3H=%%'*E,+ 
	 .77TT[[7	7$!-!3!3L!A --/.@&  .	IIo++D)<=!$  8s   6C,Fc                   | j                   j                  dd      xs t        | dd      }|sy|j                         j	                  d      }d}t        |      D ]'  \  }}|j                         j                  d      s&|}) |dk  ry||   j                         }d}|dz   t        |      k  r||dz      j                         }| |rd| z   S dz   S )	zIExtract the innermost user source location from an FX node's stack trace.stack_tracer   r   zFile r   r   z, code: )metagetgetattrstriprY  rk  rf  r   )nsttrace_lineslast_file_idxrg  line	file_linecodes           r   get_node_source_infor  f  s    	
M2	&	G'!]B*GB((*""4(KM[) 4::<""7+M qM*002IDq3{++=1,-335[$xv.??B??r   c                  	 t        | t              sy	 | j                  j                  }g g t	               d
dd	fd	 	|       ssyg }t        t                    z   D ]$  }|j                  |       |j                  d       & ddj                  d |D              z   S # t        $ r t        j                  dd	       Y yw xY w)zWalk the FX graph backwards from a TensorVariable to show how it was
    computed, with user source locations. Graph inputs (placeholders) are always
    shown first, followed by operations in dataflow order ending at the branch
    condition.r   c                x    t        | t        j                  j                        r| j                  S t        |       S r   )rV  torchfxNoder   repr)as    r   fmt_argz0format_tensor_computation_trace.<locals>.fmt_arg  s&    '588==9166FtAwFr   c                (   | j                   
v ry 
j                  | j                          t        |       }| j                  dk(  rUg }|r|j	                  d|        |j	                  | j                    d| j
                   d       	j	                  |       y | j                  dk(  rt              k  rt        | j
                  dt        | j
                              }dj                  fd| j                  D              }g }|r|j	                  d|        |j	                  | j                    d	| d
| d       j	                  |       | j                  D ]/  }t        |t        j                  j                        s( |       1 y y y )Nplaceholderz# z: graph input ()rG  r   z, c              3  .   K   | ]  } |        y wr   r   )r   r  r  s     r   r  z@format_tensor_computation_trace.<locals>.walk.<locals>.<genexpr>  s     $@AWQZ$@s   z = r   )r   r  r  opr   r.  r   r  r   r  r   rV  r  r  r  )r  sourceblocktarget_nameargs_strr  r  	max_lines	op_blocksplaceholder_blocksvisitedwalks         r   r  z-format_tensor_computation_trace.<locals>.walk  sM   vv KK)!,Ftt}$LL2fX/xqxxjBC"))%0tt&3y>I+E%ahh
CMJ99$@$@@LL2fX/xs;-q
!DE  '  A!!UXX]]3Q  ,F&r   z@

  The branch condition involves a tensor computed as follows:
r   c              3  &   K   | ]	  }d |   yw)    Nr   )r   r  s     r   r  z2format_tensor_computation_trace.<locals>.<genexpr>  s     <$$tf<s   z&format_tensor_computation_trace failedT)exc_info)r  objectr   r   )r  torch.fx.Noder   r   )rV  r   proxynoder  r   r   extendr   r  	Exceptionr!  debug)
valuer  r  	all_linesr  r  r  r  r  r  s
    `   @@@@@r   format_tensor_computation_tracer  y  s    
 e^,9{{ &(	.0E	G	  	 6 	T
!3  "	'$x	/B*CC 	!EU#R 	!
 Rii<)<<=	
  		:T	Js   ?B4 AB4 4 CCc                L     dd	 d	 	 	 	 	 	 	 	 	 dfdd fd}|S )Nc                "   t        |       }g }t        | t              r	 | j                  j                  }|j
                  j                  d      }|P|j                         dk(  r=|j                  t        j                  t        j                  fv r|j                  d       |A|j                         dk(  r.|j                  t        j                  k(  r|j                  d       t        |j                  dd       xs( t        |j                  t               r|j                  nd }|dv r|j                  d       |j%                  t&        j(                         |j                  d       t+        d	d
|  d|z   |       y # t"        $ r Y Qw xY w)Nexample_valuer   zThe branch condition uses a scalar integer tensor. Consider rewriting the computation to use plain Python ints (e.g. use int attributes instead of tensor buffers) so the condition becomes a shape guard instead of data-dependent branching.a,  For the common pattern `if tensor_cond: x = transform(x)` (e.g. clamping inf/nan values), consider making the code branchless by always applying the transform. Operations like torch.clamp, torch.nan_to_num, and torch.where are typically no-ops on well-behaved inputs and compile without graph breaks.r   )anyallbitwise_and
bitwise_orzNote: Python `or`/`and` between tensor expressions (e.g. `tensor.any() or other_tensor.any()`) triggers implicit bool conversion. Use `torch.logical_or`/`torch.logical_and` or the `|`/`&` operators instead.z1Use `torch.cond` to express dynamic control flow.zData-dependent branchingzattempted to jump with zyDetected data-dependent branching (e.g. `if my_tensor.sum() > 0:`). Dynamo does not support tracing dynamic control flow.gb_typecontextexplanationhints)r  rV  r   r  r  r  r  dimdtyper  int32int64r   r   r  r.  r   r  r  r   FUNDAMENTALr=   )r  
trace_infor  r  exampler  s         r   raise_jump_graph_breakz,generic_jump.<locals>.raise_jump_graph_break  sj   4U;
e^,.{{''))--8'* LL4 '*3LLZ &dkk:tD #-dkk3#?DKKT  "MMLL5 	&223HI.-eW5DFPQ	
	  s   DF 	FFc           	     p   | j                         st        d      d }	  |       |t        d      | j	                         r| j                  | j                  |       | j                  | j                  t        |      |       | j                  |       t        j                  d       | j                  j                  | t        dt!        |       | | j#                         g      d      }| j%                          | j'                  | j(                  |      }r| j                  |       |j*                  t        d      | j'                  |j*                  |      }t,        j.                  d	k\  r%| j                  j1                  t3        d
      g       t3        |j4                  |d         }	| j6                   | j                  j8                  j:                  n|}
|	j=                  |
       | j                  j1                  |	g|z   |z          y # t        t        f$ r}|}Y d }~d }~ww xY w)Nz7expected self.should_compile_partial_graph() to be truez#expected exc is not None to be truer   r   zgeneric_jump triggered compilezgeneric_jump r   r   
stack_pops+expected inst.target is not None to be true      TO_BOOLr   )r.  )should_compile_partial_graphr   r>   r?   maybe_has_backedgeraise_loop_graph_breakf_codelog_graph_breakcode_optionsr   rF  r!  r  r(  compile_subgraphrD   re   frame_summarypopcreate_call_resume_atnext_instructionr.  rZ  version_infoadd_output_instructionsr(   r   parentroot_txcurrent_instructioncopy_positions)r   r   r  	extra_msgr   eall_stack_locals_metadataif_nextif_jump	jump_instpositions_instrF  r  s              r   jump_graph_breakz&generic_jump.<locals>.jump_graph_break  s    002 I  	"5) ; !FGG ""$''S9s8 	 	
 			%		23$(KK$@$@%/	{;d>P>P>R=S  %A %
! 	
,,!!%
 IIe;; !NOO,,KK%

 w&KK//1CI1N0OP&t{{71:F	 8<{{7NDKK33TX 	 	  0++YK',AG,KLg Y' 	C	s   H H5(H00H5c                   | j                         }t        j                  r`t        j                  j
                  dk(  rBt        |       r4| j                         }|j                         rmt        |j                               r| j                  |      S | j                         r | ||       y t        dd| dg t        j                  ddd       |j                         rJ | j                   j"                  d	t$        j&                  gt)        ||fi         | j                  |       y t+        |t,              r|j.                  }t+        |t$        j0                        s|dk7  }t$        j2                  j4                  j6                  j9                  |      }|s(t        d
t;        |      dg t        j<                         | j                  |       y  | j                   j"                  d	t$        j>                  gt)        |fi        }tA        | |tC        |jD                  |             } | j                   j"                  d	t$        j&                  gt)        ||fi         | j                  |       y |j                         rt+        |tF              r>|jH                  r2tK        |jH                  jM                  tN        jP                                |j                               r%r| jS                  |       | j                  |       y y |j                         r| j                         r | ||       y t+        |tT              rS| j                   jW                  |jX                        } |      r%r| jS                  |       | j                  |       y y t+        |tZ              rt]        | |      }|j                         r; |j                               rr| jS                  |       | j                  |       y t+        |t,              r; |j_                               r;r| jS                  |       | j                  |       y t        dd| d| dg        y y y t+        |t,              r	 t+        |j.                  t$        j0                        r|j_                  | j                         }	nta        |j.                  dk7        }	 |	      r%r| jS                  |       | j                  |       y y |j                         s:t]        | |      } |      r%r| jS                  |       | j                  |       y y t+        |tf        jh                        r. d      r%r| jS                  |       | j                  |       y y ddl$m5} |jH                  N ||jH                        r< |jm                               r%r| jS                  |       | j                  |       y y  |       y # tb        jd                  $ r*}
| j                         r | ||d|
       cY d }
~
S  d }
~
ww xY w)Nr   z>Data-dependent assertion failed (cannot compile partial graph)zvalue: zuDynamo has determined when encountering a data-dependent assert failure that it should not compile the partial graph.zUse `torch._assert()` to raise a hard AssertionError when the check fails. This error will propagate back the user code that called the compiled function (i.e. Dynamo will not trace any exception handling).zRemove the assert statement.zMove the assert statement outside of any context managers in order to graph break with partial graph compilation (if fullgraph=False).r  rG  z#Assertion failed on symbolic shapesr   )r  z3Data-dependent branching with non-constant __bool__z
, result: zdAttempted to perform data-dependent branching on a user-defined object with non-constant truthiness.r   )r  Tr   )is_constant_source)7r  r    rewrite_assert_with_torch_assertrZ  flagsoptimizer  is_python_constantr   as_python_constantjumpr  r=   r   r  	is_tensorr(  create_proxyr  _assert_asyncrb   rV  r   sym_numSymBoolr  experimentalsymbolic_shapesexpect_truer   
USER_ERRORscalar_tensorrj   r\   r  rs   r  rB   
make_guardrA   SEQUENCE_LENGTHrF  r   get_submodule
module_keyr   r   evaluate_exprr   r   r?   r   BackwardHookVariabler  get_real_value)r   r   r  r~  sym_exprresultscalar_to_tensor_proxyscalar_to_tensorr\  eval_resultr  r  r  rF  r  ry  s               r   innerzgeneric_jump.<locals>.inner?  sS   !%33		""a'6tXtL)-I'')002399T?*668$T47! `")% 1%H.::u
 ;N*  (((#'' 'y'92>
 		$%1 !==!(EMM:'1}H..>>JJ8T! E #H$&= 1 < <=	 		$%=T[[%=%=!4!4&7H%SU7V&"  -&,-C-H-H$O  %DKK$$## #$4i#@"E
 IIdO##% %!23ell55l6R6RST0023IIe$		$ 4 __4#D#D#FT4//0++++E,<,<=C}IIe$		$  89!$.F((*F5578		%(IIdOFO4F0023		%(IIdOQ%eWJvh?!; 4 9" / emmU]];"'"5"5dkk"BK",U]]a-?"@K
 $IIe$		$ % "!$.FIIe$		$   y==>~IIe$		$ 
 3||',>u||,LE0023		%(IIdO 4
 'u-9 == 446+D$2aSRRs%   AX YX?8Y>X??Y)r  rg   r   r   )r   )
r   r   r   r.   r  rg   r  r   r   r   r   r   r   r.   r   r   r   )ry  rF  r  r  r  s   `` @@r   generic_jumpr    sb    ;
B 	AM'AMAM AM 	AM
 
AMF`. `.D Lr   c                Z   g }| }| |j                  |       |j                  }| t        |      D ]  } | j                  D ]  }t	        |j
                  t              r:|j                  |j                         j                  |j                  |             W|j
                  t        d      t	        |j
                  t              st        d      |j
                  j                  |       |j                  |j                         j                  |j                  |               y)zsGenerates bytecode to restore the block stack for running the unsupported instruction
    in the compiled bytecode.Nz.expected b.with_context is not None to be truezIexpected isinstance(b.with_context, (ContextWrappingVariable)) to be true)r   r  r   block_stackrV  r0  r   extend_outputr7  try_except_torch_function_moder  r   rn   reconstruct_typetry_finally)r   cgcleanupall_txescur_txbs         r   _reconstruct_block_stackr    s    13H/1F

 
 x  R 	RA !..*CD  KKM@@
 ~~%$%UVVann/FH$_  NN++B/Q[[]66rPQ%	RRr   c                ^    ddl fd}|j                  j                  | |      |_        |S )a  Create a wrapper for warnings.warn that reports the given source location.

    When warnings.warn (stacklevel=1) inspects its caller frame, it sees the
    wrapper's code object -- whose co_filename and line table point to the
    original leaf-frame location.  This preserves Python's per-location
    warning dedup even when the call is inlined into a different frame by
    nested graph breaks.
    r   Nc                 (     j                   | i |S r   )warn)r   kwargswarningss     r   r   z-_make_warnings_warn_wrapper.<locals>.<lambda>  s    -(--:XQW:X r   )co_filenameco_firstlineno)r  __code__replace)r   r   wrapperr  s      @r   _make_warnings_warn_wrapperr    s;      #YG''// 0 G Nr   c                      	 	 	 	 d fd}|S )Nc                j     t        j                         d fd       }	 	 	 	 	 	 	 	 dfd|S )Nc           
     4   | j                   }| _         | j                         }|j                  |       r+|j                  t	        d       | ||j                        S 	  | |      || _         S # t
        t        f$ rd}| j                  rg| j                  s| j                  r t        |t
              r|j                          t        dd| j                   ddgt        j                  |       t        |dd      r | j!                         s | j#                         r| j%                  | j&                  |       | j)                  | j*                   d	t-        |       |
       t        |t
              r!|j                          |j/                  d       t1        t        |dt-        |            t        |d| j3                         g            |_        Y d }~nd }~ww xY w	 || _         n# || _         w xY w|j5                  | j                         y )Nz2expected speculation.reason is not None to be truez0Graph break under GenericContextWrappingVariablez!Active generic context managers: z]Attempted to graph break in an active context manager(s) that doesn't support graph breaking.zEMove the offending context manager(s) to outside the compiled region.r  r  r  r  from_exc
skip_frameFz:

r  graph_breakr`  
real_stack)current_instruction_push	speculater   r   r   r>   r?   active_generic_context_managers	one_graphr   rV  remove_from_statsr=   r   CAUSED_BY_EARLIER_GRAPH_BREAKr  r  r  r  r  r  r  r   add_to_statsrD   r  r   )	r   r   	prev_pushspeculationexcphandle_graph_breakinner_fn
msg_prefixrF  s	        r   r  z>break_graph_if_unsupported.<locals>.decorator.<locals>.wrapper'  s   55I,0D)..*K!!$'%%-(L  *$k6H6HII.:d+Z 1:-Y  + *77~~)B)B "$4..0! R"CDDhDhCi j %Dc.LL "&	 4u588:**,//TB$$%%(\s4yk: %  dK0**,%%m4%7D%T3D,1C1C1E0FG&""O*N #
 1:-	-11$2K2KLs+   "A2 2G&EG!G2 !G&&G2 2	G;c                *   t         j                  dk\  rt         j                  dk  rs|j                  dk(  rdt        j                  t        j
                  d   |j                        t        j                  t        j
                  d   |j                        z   }n*t        j                  |j                  |j                        }| j                  | j                  |       t        j                  d|j                         | j                  j                  | |t              |z
        }t        | j                  j                         }g }t#        | ||       | j                  j%                  |j'                                ~| j                   | j                  j                   j(                  n|}t         j                  dk\  r|j                  dk(  r| j*                  | j*                  j-                         nd}t/        |      dkD  rEt         j                  d	k  st1        d
      | j                  j%                  t3        d|      g       |j                  t1        d      t5        |j                  d      }	|	d   j7                  |       | j                  j%                  |	       n`|j8                  t1        d      t;        j:                  |      }
d |
_        |
j7                  |       | j                  j%                  |
g       | j                  j%                  |       | j?                  t              |z
         r| jA                  tC                      | j                  j%                  | jE                  | jF                  |             y )Nr     r     CALLPRECALLz%s triggered compiler  r   r   r  z.expected sys.version_info < (3, 13) to be trueKW_NAMESrw  (expected inst.arg is not None to be trueFr  z'expected inst.target is None to be true)$rZ  r  r   ri  stack_effectopmapargopcoder  %_maybe_replace_warnings_warn_on_stackr!  r  r(  r  r   r3   r  r  r  rj  r  kw_namesr  r   r   r(   r$   r  r.  copyexn_tab_entryrH  rF  r   r  r  )r   r   r   r?  r  r  r  r  rD  
call_insts	inst_copyrF  s              r   r2  zIbreak_graph_if_unsupported.<locals>.decorator.<locals>.handle_graph_breakd  s      G+$$w.KK6)  #//IIi($(( $$SYYv%6A B  #//TXXF
 {{&::4@II,dkk:(,(D(DVD	L0H )E )% 4;;../B)+G$T2w7KK//0C0C0EF ;;* ##77  7*t{{f/D }}0 MM446 
 x=1$,,w6,L  KK77+JxHI 88#()STT1$((EB
2--n=33J? ;;*()RSS IIdO	*.	'((833YK@KK//8IIc$i,./		/+,KK//**))-r   r  )r   r   r   r.   r   rD   r   r   )rP  rQ  )r3  r  r2  r4  rF  s   ` @r   	decoratorz-break_graph_if_unsupported.<locals>.decorator$  sY     
	":	M 
#:	MxR	+R	R	 'R	 	R	h r   )r3  Callable[..., None]r   8Callable[[InstructionTranslatorBase, Instruction], None]r   )rF  r4  rI  s   `` r   break_graph_if_unsupportedrL    s$    
T%T	ATl r   c                  $     e Zd ZdZd fdZ xZS )BytecodeDispatchTableMetazTInstalls a `cls.dispatch_table` on every subclass to speed up calls to self.OPCODE()c                @   t         	|   |||       dd}t        j                  j	                         D ci c]'  \  }}|t        | |t        j                  ||            ) }}}t        d      D cg c]  }|j                  |       c}| _
        y c c}}w c c}w )Nc                ^    t        d|  d| d|  dd|  dgt        j                         y )NzMissing bytecode handlerz with args z=Dynamo does not know how to handle the bytecode instruction ``.z%Do not trace code that produces the `z_` bytecode instruction (see https://docs.python.org/3/library/dis.html for bytecode semantics).r  )r=   r   SUPPORTABLE)r   r   s     r   _missingz4BytecodeDispatchTableMeta.__init__.<locals>._missing  sS    2!(+dV4[\b[ccef;F8 D_ _ '22		r      )r   r   r   r   r   r   )super__init__ri  r@  r  r  rP  partialranger  dispatch_table)
r  r   basesdctrS  r   r  rY  rg  	__class__s
            r   rV  z"BytecodeDispatchTableMeta.__init__  s    uc*
	 "iioo/
 VY%6%6x%HII
 
 >C4[In003I	
 Js   ,B4B)
r  typer   r   rZ  r   r[  r   r   r   )r   r   r   r   rV  __classcell__r\  s   @r   rN  rN    s    ^J Jr   rN  c                      e Zd ZU dZ ej
                  e      Zded<    ej
                  d      Z	ded<   dd	Z
	 d	 	 	 	 	 dd
ZddZddZ	 	 	 	 	 	 ddZddZ	 	 	 	 ddZddZddZddZddZddZeZy)ExceptionStackzU
    Exception stack that it is shared among all InstructionTranslator instances
    r   zlist[ExceptionVals]
_exc_stackN)defaultzExceptionVals | None_current_exceptionc                    d | _         y r   )rd  r   s    r   clear_current_exceptionz&ExceptionStack.clear_current_exception  s
    "&r   c                8    |r| j                  |       || _        y r   )._set_context_and_break_context_reference_cyclerd  )r   valset_contexts      r   set_current_exceptionz$ExceptionStack.set_current_exception  s     ??D"%r   c                    | j                   t        d      | j                  | j                          | j                          y Nz7expected self._current_exception is not None to be true)rd  r   r   rf  r   s    r   move_current_exception_to_stackz.ExceptionStack.move_current_exception_to_stack  s>    ""* I  	D++,$$&r   c                H    | j                   t        d      | j                   S rm  )rd  r   r   s    r   get_current_exceptionz$ExceptionStack.get_current_exception  s,    ""* I  &&&r   c                    |j                   x}r|j                         s|S t        | j                        |z   dkD  r9| j                  |   }| j	                  ||dz
         ||ur|j                  |       |S )Nr   r   )__context__is_constant_noner   rb  _set_context_recursiverj  )r   ri  prev_idxctxprevs        r   rt  z%ExceptionStack._set_context_recursive  ss     ??"C"C,@,@,BJt(*Q.??8,D''hl;3%
r   c                    |x}}d}	 |j                   }|j                         ry ||u r%|j                  t        j                  d              y |}||u ry |r|j                   }| }_r'  )rr  rs  rj  rm   create)r   ri  oslow_oslow_update_toggler  s         r   _break_context_reference_cyclez-ExceptionStack._break_context_reference_cycle  s~    
 F"mmG'')#~.55d;<AF{ !++%7!7% r   c                v    | j                  |t        | j                        dz
         | j                  |       y Nr   )rt  r   rb  r}  r   ri  s     r   rh  z=ExceptionStack._set_context_and_break_context_reference_cycle*  s0     	##CT__)=)AB++C0r   c                6    | j                   j                         S r   )rb  r  r   s    r   r  zExceptionStack.pop1  s    ""$$r   c                :    | j                   j                  |       y r   )rb  r   r  s     r   r   zExceptionStack.append4  s    s#r   c                ,    t        | j                        S r   )r   rb  r   s    r   __len__zExceptionStack.__len__7  s    4??##r   c                     | j                   |   S r   )rb  )r   r   s     r   __getitem__zExceptionStack.__getitem__:  s    u%%r   c                :    d| j                   d| j                  S )Nzself._exc_stack=z - self._current_exception=)rb  rd  r   s    r   __str__zExceptionStack.__str__=  s"    "$//##?t'>'>&@AAr   r   )T)ri  r   rj  r   r   r   )r   r   )ri  r   ru  r   r   r   )ri  r   r   r   )r   r   )r   r   r   r   r  )r   r   r   r   r   r   r   rb  r   rd  rf  rk  rn  rp  rt  r}  rh  r  r   r  r  r  __repr__r   r   r   ra  ra    s     '8k&7&7&MJ#M/@{/@/@/N,N' 7;& &/3&	&''
 
,/
	
861 1	1%$$&B Hr   ra  c                      e Zd ZU ded<   ded<   ded<   ded<   ded	<   d
ed<   ded<   ded<   ded<   ded<   ded<   ded<   ded<   ded<   ded<   ded<   ded<   ded <   d!ed"<   d#ed$<   d%ed&<   d'ed(<   ded)<   ded*<   d+ed,<   ded-<   d.ed/<   d0ed1<   d2ed3<   dd4Zdd5Zdd6Zdd7Zdd8Zdd9Z	dd:Z
dd;Zdd<Z	 	 	 	 	 	 	 	 d d=Z	 	 	 	 	 	 	 	 dd>Z	 d	 	 	 	 	 	 	 	 	 dd@ZdddBZddCZddDZddEZej*                  dFk\  rddGZnddHZed	dI       Zd
dJZddKZddLZddMZddNZddOZddPZddQZ ddRZ!ddSZ"ddTZ#ddUZ$ddVZ%e Z&ddWZ'ddXZ(ddYZ)e*jV                  ddZ       Z,dd[Z-dd\Z.e/dd]       Z0dd^Z1dd_Z2dd`Z3e3Z4ddaZ5e/ddb       Z6ddcZ7dddZ8e8Z9e8Z: e;e<jz                  d?      Z> e;e<j~                  d?      Z@ e;e<jz                  de      ZA e;e<j~                  de      ZBddfZCddgZDddhZEddiZFddjZGddkZHddlZIddmZJ	 	 	 	 	 	 ddnZKddoZLddpZMddqZNddrZOddsZPddtZQdduZRddvZSddwZTddxZUddyZV eWdedz{      dd|       ZXdd}ZY eWded~{      dd       ZZ eWded{      dd       Z[ eWded{      dd       Z\ddZ]ddZ^ddZ_ddZ`ddZaddZb eWd?d{      dd       ZcddZdddZeef	 	 	 	 	 	 dd       Zg	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZhddZi	 	 	 	 	 	 ddZjef	 	 	 	 	 	 	 	 d d       ZkddZl eWd?d{      dd       ZmddZn	 	 	 	 	 	 d!dZoddZpddZqddZrddZsddZteufd"dZvddZwewZxddZyddZzezZ{ddZ|ddZ}ddZ~ddZddZddZddZddZ eWd?d{      dd       ZddZddZddZddZddZddZddZd#dZd$dZddZddZddZddZddZddZddZddZeZddZddZddZddZddZddZddZddÄZ ee<j@                        Z ee<jD                        Z ee<jz                        Z ee<jJ                        Z ee<jN                        Z ee<jR                        Z ee<jV                        Z ee<jZ                        Z ee<j^                        Z ee<jb                        Z ee<jb                        Z ee<jh                        Z ee<jl                        Z  eWdedĬ{       ee<jp                              Z ee<jt                        Z ee<jx                        Z ee<j|                        Z ee<j                        Z ee<j                        Z ee<j                        Z ee<j                        Z ee<j                        Z ee<j                        Z ee<j                        Z ee<j                        Z ee<j                        Z ee<j                        Z ee<j                        Z ee<j                        Z ee<j                        Z ee<j                        Z ee<j                        Z ee<j                        ZސddńZej*                  dFk\  rddƄZddǄZddȄZddɄZdd%dʄZ eWdedˬ{      dd̄       Zdd̈́Zdd΄Ze8Ze8Z e;e<j~                  d?      Z e;e<j~                  d?      Z e;e<jz                  d?      Z e;e<jz                  d?      ZddτZddЄZ	 	 	 	 	 	 d&dфZefd'd҄       ZddӄZddԄZddՄZddքZddׄZdd؄ZddلZddڄZddۄZdd܄Zdd݄ZddބZ eWded߬{      dd       ZddZddZ ddZddZddZe ZeZddZdZddZddZ	e
eeeeeedAdded?dfZddZddZ	 d	 	 	 d(dZd)dZddZd*dZed+d       Zej4                  	 	 	 	 d,d       Zd-dZ	 	 	 	 	 	 	 	 d.dZ	 	 	 	 d/dZddZ	 	 	 	 	 	 	 	 d0dZ ef	 	 	 	 	 	 d1d       Z!	 	 	 d2	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d3 fdZ" xZ#S (4  r   rE   r(  dict[str, VariableTracker]symbolic_localssymbolic_globalsr   symbolic_torch_function_stater   symbolic_stream_statez!dict[str, VariableTracker] | Nonepost_prune_cell_and_freevarslist[VariableTracker]stack
int | Noner   r.   r  r   r(  zlist[BlockStackEntry]r
  r   r   zConstantVariable | NonerD  accept_prefix_instlist[Instruction]prefix_instsinline_depthinconsistent_side_effectszSpeculationEntry | Nonecurrent_speculationz	list[Any]rY  ra  exn_vt_stackzExecutionRecorder | Noneexec_recorderz(Callable[[VariableTracker], bool] | Nonestrict_checks_fnstart_pointhas_no_inlined_callsz InstructionTranslatorBase | Noner  is_child_tracer_activez3list[tuple[VariableTracker, list[VariableTracker]]]debug_localsCompilePackage | Nonepackagez
deque[str]latest_bytecode_queuec                    d| _         y)z
        InstructionTranslator has encountered instructions which may cause
        dynamo to see a different version of history from eager
        See: https://github.com/pytorch/pytorch/issues/110765
        TN)r  r   s    r   mark_inconsistent_side_effectsz8InstructionTranslatorBase.mark_inconsistent_side_effectsh  s     *.&r   c                ,   | }||j                   j                  }|j                  t        d      |j                  |j                  d  D ]8  }|j
                  dv r n(|j
                  t        v s&|j                  }||k  s8 y |j                  }|y)Nz:expected cur_tx.instruction_pointer is not None to be true)RETURN_VALUERETURN_CONSTTF)	r  offsetr   r   rv  r   r   rw  r  )r   r  
cur_offsetr   jump_offsets        r   r  z,InstructionTranslatorBase.maybe_has_backedgep  s    * 48 33::J))1$P  ++F,F,F,HI $;;"BB;;,."&++K"Z/#$ ]]F   r   c                     | j                   d   S )Nco_cellvarsr  r   s    r   cellvarsz"InstructionTranslatorBase.cellvars        //r   c                     | j                   d   S )Nco_freevarsr  r   s    r   freevarsz"InstructionTranslatorBase.freevars  r  r   c                ^    d| t        | j                  |          }|| j                  |<   |S )zIGenerate a fresh, unique pycode-local variable name for the given prefix.__)r   _pycode_varname_counter_pycode_last_varname)r   prefixr   s      r   new_pycode_varnamez,InstructionTranslatorBase.new_pycode_varname  s8    F8D!=!=f!EFGH,0!!&)r   c                H    t        j                  d      | j                  |<   y r   )	itertoolscountr  r   r  s     r   reset_pycode_varname_counterz6InstructionTranslatorBase.reset_pycode_varname_counter  s    /8q/A$$V,r   c                     | j                   |   S )zGReturn the most recently generated pycode varname for the given prefix.)r  r  s     r   get_pycode_last_varnamez1InstructionTranslatorBase.get_pycode_last_varname  s    ((00r   c                ~    t        | d      s&| j                         | j                         z   | _        | j                  S )N_cell_and_freevars)r5  r  r  r  r   s    r   cell_and_freevarsz+InstructionTranslatorBase.cell_and_freevars  s2    t12&*mmo&GD#&&&r   c                V   | j                   j                         D ci c]  \  }}|| j                         v r|| c}}| _        t	        | j
                  | j                        }| j                   j                         D ci c]  \  }}||v s|| c}}| _         y c c}}w c c}}w r   )r  r  r  r  r    rv  r  )r   r  r  readss       r   prune_dead_localsz+InstructionTranslatorBase.prune_dead_locals  s     ,,224-
1D**,, qD-
) "$"3"3T5M5MN!11779 
QQ%ZAqD 
-
 
s   BB%B%c                   t        |t              st        d      t        |t              st        d      t        |t              st        d      t        d t        j                  ||j                               D              st        d      d }t        |d      r|j                  }t        |d      r|j                  }|$t        |      rt        |      rt        d|       | j                  |j                  | ||             y )	Nz3expected isinstance(fn, VariableTracker) to be truez*expected isinstance(args, list) to be truez,expected isinstance(kwargs, dict) to be truec              3  <   K   | ]  }t        |t                y wr   )rV  rg   )r   rb  s     r   r  z:InstructionTranslatorBase.call_function.<locals>.<genexpr>  s      
 q/*
   ziexpected all( isinstance(x, VariableTracker) for x in itertools.chain(args, kwargs.values()) ) to be truer  rR  z$Attempt to trace forbidden callable )rV  rg   r   r   r  r  r  chainvaluesr5  r  rR  callablerY   rF  rG  )r   rR  r   r  r3  s        r   rG  z'InstructionTranslatorBase.call_function  s     "o. !VWW$% !MNN&$' !OPP 
__T6==?;
 
 !{  2wxxH2tuuHHX$6<;Q #Gz!RSS		"""4v67r   c                ^    t        |t              st        |      }|j                  | ||      S )zD
        Redirect the call to the generator "call_function"
        )rV  rw   rG  )r   rR  r   r  s       r   inline_generator_functionz3InstructionTranslatorBase.inline_generator_function  s.     "<=/3BdF33r   Fc                    t         j                  r,t        |j                               r| j	                  |||      S t
        j                  | ||||      S )zF
        A call to some user defined function by inlining it.
        allow_nested_graph_breaks)r   "enable_faithful_generator_behaviorr/   get_coder  InliningInstructionTranslatorinline_call)r   rR  r   r  r  s        r   inline_user_function_returnz5InstructionTranslatorBase.inline_user_function_return  sV     44bkkm9T11"dFCC0<<*C =  r   Nc                    || j                   }| j                  dkD  rd| j                   dnd}t        | j                  j                  |      }|dnd| d}| j                  j                   d| d| j                  j
                   | | S )Nr   z (inline depth: r  r   r   r   z in )r   r  r@   r  r  co_name)r   r   inline_depth_strfuncnamefuncname_strs        r   get_line_of_code_headerz1InstructionTranslatorBase.get_line_of_code_header  s    >[[F7;7H7H17Lt0013RT 	   7 7@%-rRz3C++))*!F848K8K7L\N[kZlmmr   c                    d| j                          d}t        j                  | j                  j                  | j
                        j                         }|d| z  }|S )NzTRACE starts_line r   r  )r  	linecachegetliner  r  r   rstrip)r   log_strr  s      r   get_log_starts_line_log_strz5InstructionTranslatorBase.get_log_starts_line_log_str  sX    &t'C'C'E&FbI  !8!8$++FMMOT$= r   c                   | j                   |k(  ry || _         t        j                  | j                  j                  || j                  j
                         | j                  r*t        j                  dt        | j                               y y )N%s)r   r   set_current_locr  r  r  is_trace_source_log_enabledtrace_source_logr  ra   r  )r   r   s     r   starts_linez%InstructionTranslatorBase.starts_line	  sl    ;;& &&KK##VT[[-@-@	
 ++""4D4T4T)UV ,r   c                   t               | _        | j                  }|y| j                  |   x| _        }|dz   | _        |j
                  r| j                  |j
                         t        j                         }||j                  |_	        | j                  sb| j                         rR| j                         rB| j                         | _        | j                  j                  |       r| j!                  |       y| j"                  r?t$        j'                  d|j(                  |j*                  t-        | j                               t.        j0                  rW	 t-        | j                        }| j4                  j7                  d|j(                   dt-        |j*                         d|        | j9                  |       	  | j:                  |j<                     | |       | j>                  j@                   S # t2        $ r d}Y w xY w# tB        $ r  tD        jF                  $ r}| jI                  |       Y d}~yd}~wtJ        tL        f$ r Y ytN        tP        tR        f$ r}| jT                  s%| j                  s| jV                  stY        |d	d      r2t[        |tR              r!t]        d
ddddgt^        j`                          | j                  Otb        j'                  d       t[        |tR              r"t]        dddddgt^        j`                  d       d|_2         dtg        |       }| ji                  | jj                  ||       Y d}~nd}~ww xY w| j                  jm                  | j                         y)z<Process exactly one instruction, return False we should exitNFr   zTRACE %s %s %sz0<self.stack repr truncated due to large integer>zTRACE  Tr%  z3cannot resume from torch._dynamo.step_unsupported()r   ztraced torch._dynamo.step_unsupported(), but Dynamo is instructed to error on graph break. This graph break is used for debugging only.z1Remove the torch._dynamo.step_unsupported() call.z9Make sure fullgraph=False and error_on_graph_break=False.r  z1empty checkpoint - cannot resume from graph breakz6torch._dynamo.step_unsupported() with empty checkpointztraced torch._dynamo.step_unsupported(), but there is no checkpoint to step_graph_break from. This graph break is used for debugging only.zInclude at least one checkpoint: (1) include at least 2 ops and (2) make sure there is some line of code that is not in a try/with block, and has an empty Python stack.)r  r  r  r  r%  zEncountered graph break that we cannot resume from. Compiling up to the previous resumable state, then skipping the rest of the function. Graph break encountered:

r  )7rZ   r   r   rv  r  r  r   try_get	positionsloc_in_frame_positionsr  r  is_non_empty_graphr)  r  r   step_graph_breakis_trace_bytecode_log_enabledtrace_bytecode_logr  r   rw  r  r   verbose
ValueErrorr  r   update_block_stackrY  rB  r(  r)  r   r   r   exception_handlerrA  rC  r>   r?   r<   r+  is_tracing_resume_prologuer  rV  r=   r   
DYNAMO_BUGr!  r%  r   r  r  r   )r   ipr   tc
stack_reprr  r   s          r   stepzInstructionTranslatorBase.step  sA   $=$?!%%:*.*;*;B*?? 4#%6 T--.##%>(,B% 

113'')'+~~'7D$''..t4%%d+--$$ $++t{{D<L >>P!$**-
 &&--QtDKK'8&9:,G 	%A	,D,T48{{....  PO
P . 	$$ 	""1%|, 	Y8 7	 ,,221lE2a1! U "%` PW /99
 ''/		MNa1! X "%a Pk /99	 $(  $/ 031vh8    !! !  g7	r 	  ::4;T;TUs=   G6 ?6H 6HHM#H99MM C*MMr6  c                   |j                   }|rt        | j                        dk\  rg|j                  | j                  d   j                  urA|j                  | j                  d   j                  u r| j                  j	                          y y y y | j                  rM|j
                  dvr>t        | j                        dk7  rt        d      | j                  j	                          y y y )N   r  )NOPJUMP_BACKWARD	NOT_TAKENr   z.expected len(self.block_stack) == 1 to be true)rF  r   r
  r.  r  r   r   )r   r   r   s      r   r  z,InstructionTranslatorBase.update_block_stack  s     &&E (()Q.D,<,<R,@,G,GG(8(8(<(C(CC $$((* D H /" ## < ) 4++,1,L  $$((*)#r   c                     y r   r   r   r   s     r   r  z,InstructionTranslatorBase.update_block_stack  s    r   c                b    | j                   t        d      | j                  | j                      S )N8expected self.instruction_pointer is not None to be true)r   r   rv  r   s    r   r  z*InstructionTranslatorBase.next_instruction  s7    ##+ J    !9!9::r   c           	     r
   | j                   j                  rt        d      | j                  t        d      | j                  rt        d      t
        j                  d       | j                   j                  | t        d| j                         g            }| j                  rSddlm} t        j                  st        d	      t        | j                   j                         }|j#                  g t%        d
      |j'                  d      |j)                         t+        dd      t%        d
      |j'                  d      |j)                         t+        dd             | j-                  d||d   g |dd      \  }} ||       g }t/        | j                  ||       | j1                  |g|g|       |j#                  |       |j#                  g t%        d
      |j'                  d      t+        d      t%        d      |j'                  d      t+        d             |d   j2                  }|j#                  g t%        d
      |j'                  d      |j)                         t5        d|             |j#                  g t7        d
      t+        dd             | j                  j9                  t;                      |d   xj2                  dz  c_        |dkD  rp|j#                  g t%        d
      |j'                  d      |j)                         t5        |d       t%        d      |j'                  d      t+        d             |j#                  t+        d|dz         t+        d|dz         t+        d|dz         g       | j                   j=                  |j?                         | j                  jA                  | j                  jB                  |dd        z          y | j                   j=                  g t7        d
      t+        d             t        | j                   j                         }| j                   j=                  |j'                  d      |j)                         g       |d   jD                  jG                         D ]X  \  }	}
| j                   j=                  tI               |j'                  |
      |j)                         |jK                  |	      g       Z | j                   j=                  t+        d      tM        |      g| jN                         y )Nz7expected not self.output.output_instructions to be truez8expected self.current_speculation is not None to be truez"expected not self.stack to be truezstep triggered compilestep_unsupported)r   r   )	skip_codez.expected config.nested_graph_breaks to be truer  r   
BUILD_LISTrA  TFDELETE_SUBSCRr  LIST_APPENDSTORE_SUBSCRUNPACK_SEQUENCEPOP_TOPr  )(r(  output_instructionsr   r  r  r!  r  r  rD   r  r  
eval_framer  r   nested_graph_breaksr3   r  r  r&   create_load_constcreate_binary_subscrr(   create_resumer  codegen_call_resume	num_stackr#   r+   rF  r   r  rj  r  r  locals_namesr  r'   create_storer)   rv  )r   continue_instr  r  r  leaf_resume_codeleaf_resume_namer  r  localidxs              r   r  z*InstructionTranslatorBase.step_graph_break  s\   ;;** I  ##+ J  :: !EFF 			*+$(KK$@$@%&84;M;M;O:PQ %A %
! ;;- --$%UVV4;;../B 	 ^	((+	 ++-	 '|;		
 !^	 ((+	 ++-	 '|;	 261C1C=";A">Be2.. &')+G$T[["g> $$&6%7:J9KRPW%  ^((+ '7 !^	
 ((+ '7	 2!4>>I ^((+ ++- )I6	  ^&}!< KK_./%a(22a72
 1}  $Q,,Q/ //1 -Y=	
 %Q ,,Q/ +>:  &'8i!mL&|QG&'8i!mL" KK//##%++33KK002KAB2O KK// ^&y1 4;;../BKK//((,++- 8;HHNNP 
s33&(,,S1//1.	 KK//&y1(7 &&r   c                ,    t        j                  d       S r   )r   current_framer   s    r   run_ctx_mgrz%InstructionTranslatorBase.run_ctx_mgr  s     ++D11r   c           
        | j                         5  t        | j                  j                         	 | j                  j                  |        | j                  | _        	 | j                         r	 | j                         r| j                  jY                          t)        | t.              r5| j                  j[                          | j                  j]                          	 d d d        y # t        $ rY}| j                  rGt        dt        |      j                   dt        |             j                  |j                         d  d }~ww xY w# t"        $ r  t$        $ r  t&        $ r*}t)        |t*        t,        f      rTt)        | t.              rD| j0                  s8| j2                  s,dt        |       }| j5                  | j6                  ||       t)        |t8        j:                        s$| j                  j<                  j?                          tA        |d      rpd|jB                  v rbtD        jF                  jI                  | j                  jJ                  | j                  jL                        jO                  ddd	      }||_(          d }~wt        $ ro}| jR                  r| jR                  jU                         |_+        t)        |t8        j:                        s$| j                  j<                  j?                           d }~ww xY w# | j                  jY                          t)        | t.              r5| j                  j[                          | j                  j]                          w w xY w# 1 sw Y   y xY w)
NzError while tracing through a Dynamo-generated resume function prologue. Errors are not allowed when tracing resume function prologues.
r   ztFailed to handle graph break gracefully. Skipping the function and falling back to eager. Graph break encountered:

r  r`  zData-dependentFT)print_outputinclude_strideinclude_device)/r!  r   r  r  r(  push_txr   r  r  r  r  r;   r]  r   r   with_traceback__traceback__r   r6   RuntimeErrorrV  r>   r?   rL  r   r+  r  r  r   RestartAnalysisside_effectslog_side_effects_summaryr5  r`  r  r  GraphModule
nn_modulesgraphprint_readablepartial_fx_graphr  
get_recordexec_recordpop_txr  mark_bytecode_tracing_stop)r   r  r   readable_graphs       r   runzInstructionTranslatorBase.run  s    L	=dkk--.J=##D)#'#;#; 
))+ ))+t ""$ d$9:KK'')
 KK::<YL	= L	= ! 668_#Aw334Bs1vh@ ).9t	D
  2 (  # q;	":;"4)>? 55 NN77:1vh@ 
 (())% )  "!S%8%89KK,,EEG1e$)9QUU)B%*XX%9%9..0A0A&$n%*4PT %  #
 *8A& %%$($6$6$A$A$CAM!!S%8%89KK,,EEG ""$ d$9:KK'')
 KK::< ;ML	= L	=si    M1,E!C)AM1)	E2AEEEL
*D%JL
A*LL

LA!M..M11M:c           	        t        |t              st        dt        |             |j                  | j
                  }|j                  |j                  j                  |j                  t        | j                  j                  |j                  j                  |j                  j                  |j                  j                  |j                  j                               nF|j                  :|j                  t        | j                  j                  |j                               | j                   j#                  |       y )Nz"push expects VariableTracker, got )r   r   
end_lineno
col_offsetend_col_offset)r   r   )rV  rg   r   re   source_locationr  r  r   set_source_locationrd   r  r  r9  r:  r;  r  r  r   )r   ri  r   s      r   rF  zInstructionTranslatorBase.push  s    #/ #Egcl^!TUU&++D~~)dnn.C.C.O''"!%!8!8#~~44#'>>#<#<#'>>#<#<'+~~'D'D !!-''"!%!8!8#// 	

#r   c                4    |D ]  }| j                  |        y r   )rF  )r   valsri  s      r   	push_manyz#InstructionTranslatorBase.push_many  s     	CIIcN	r   c                6    | j                   j                         S r   )r  r  r   s    r   r  zInstructionTranslatorBase.pop  s    zz~~r   c                p    g t        t        |      D cg c]  }| j                          c}      S c c}w r   )r   rX  r  )r   r  r   s      r   rH  zInstructionTranslatorBase.popn  s*    :uQx8!488:89::8s   3
c           	        |j                   }| j                  r7|| j                  v r)| j                  j                  || j                  |          	 | j	                  | j
                  |   j                                |j                  d      r| j
                  j                  |       y y # t        $ r |j                  d      rh	 |j                  dd      }| j	                  | j
                  |          n\# t        $ r* t        dd| d| ddgt        j                         Y n*w xY wt        d	d| d
| dg t        j                         Y w xY w)NrU  implicitz5Attempted to read undefined local variable (implicit)z
LOAD_FAST z5Could not find an implicit local variable with name ``z(This happens in dict/list comprehensionsr  z*Attempted to read undefined local variablez+Could not find a local variable with name `__stack)rw  r  f_localsadd_local_varrF  r  unwrapKeyErrorrf  r  r=   r   r  r  )r   r   r   new_names       r   	LOAD_FASTz#InstructionTranslatorBase.LOAD_FAST  sP   {{$$--"7,,T4==3FG	IId**40779:4 ??9%  $$T* &3  	s##||C<HIId228<= 	! W",TF 3&[\`[aab$cF.99		 H(/"MdVST U9-889	#	s6   ,B+ +E0C76E70D*'E)D**)EEc                   |j                   | j                         vrt        d      | j                  |j                      }| j                  j
                  j                  |      }| j                  |       | j                  rW|j                   | j                  v r>| j                  j                  |j                   | j                  |j                             y y y )N;expected inst.argval in self.cell_and_freevars() to be true)rw  r  r   r  r(  r+  	load_cellrF  r  rG  rH  )r   r   cellcontents_vars       r   
LOAD_DEREFz$InstructionTranslatorBase.LOAD_DEREF+  s    ;;d4466 M  ##DKK0{{//99$?		,$++">,,T[[$--:TU #?r   c                    |j                   }| j                         }|j                  |       || j                  |<   |t        k(  r4|j                         }t        |      t        urt        d      || _	        y y )Nz%expected type(val) is bool to be true)
rw  r  set_name_hintr  rN   r  r]  r   r   r  )r   r   r   	loaded_vtri  s        r   
STORE_FASTz$InstructionTranslatorBase.STORE_FAST7  sp    {{HHJ	%%.T"55..0CCy$$%LMM.1D+	 6r   c                    |j                   }| j                  j                  |      }t        |t              r| j                  |       | j                  |= y r   )rw  r  r  rV  r   _maybe_emit_sync_dealloc)r   r   r   vars       r   DELETE_FASTz%InstructionTranslatorBase.DELETE_FASTB  sG    {{""&&t,c>*))#.  &r   c                ^   ddl m}m} |j                  }||j                  dvry |j
                  j                  }|j                  j                  di       j                  dd       }t        |j                  j                               }|sy d }| j                  j                  j                  D ]	  }	|	|v s|	} ||j                  dk(  ry |j                  j                  di       j                  dd       }
||
k(  ry | ||      }|
 ||      }
 |       }| j                  j!                  dt"        j$                  j&                  j(                  ||
fi        | j                  j!                  dt"        j$                  j&                  j*                  |||j-                         fi        y )Nr   )get_current_stream	new_event)cudaxpucustomstreamr(  rG  )variables.streamsr\  r]  devicer]  r  r  r  r  r  userskeysr(  r/  nodesr  r  r  opsstreamsrecord_eventsync_deallocas_proxy)r   rY  r\  r]  rc  r  alloc_streamrd  	last_userr  last_use_stream	event_idxs               r   rX  z2InstructionTranslatorBase._maybe_emit_sync_deallocI  su   D>V[[?yy~~yy}}Xr266xFDJJOO%&	""(( 	AEz		 	 8#..,,Xr:>>xN?*-f5L"08OK	  II**(		
 	  II**clln5		
r   c                v   |j                   | j                         vrt        d      | j                  |j                      }| j	                         }| j
                  j                  j                  ||       t        |t              st        d      |j                  |j                  |j                         y y )NrN  z2expected isinstance(cell, CellVariable) to be true)rw  r  r   r  r  r(  r+  
store_cellrV  r   
local_namerT  )r   r   rP  ri  s       r   STORE_DEREFz%InstructionTranslatorBase.STORE_DEREFt  s    ;;d4466 M  ##DKK0hhj  ++D#6$- D  ??&doo. 'r   c                   |j                   }| t        j                  |j                        S | j                  |   }|s<t        j                  |j                        | j                  |<   | j                  |   }|t        d      |S )Nr  z#expected val is not None to be true)rA  rm   ry  rw  _constants_cacher   )r   r   rg  ri  s       r   _load_constz%InstructionTranslatorBase._load_const  s}    HH9#**==##A&'7'>'>T[['QD!!!$''*C; !FGG
r   c                D    | j                  | j                  |             y r   )rF  rw  r  s     r   rs  z$InstructionTranslatorBase.LOAD_CONST  s    		$""4()r   c           	        |j                   }| j                  rw|| j                  v r*| j                  j                  || j                  |          n?|| j                  vrt        d      | j                  |   | j                  j                  |<   || j                  vr| j                  |      S || j                  v r\| j                  j                  | j                  |      }| j                  | j                  j                  j                  ||             y | j                  |   }| j                  t        j                  | |t        |                   y )Nz+expected name in self.f_builtins to be true)rw  r  	f_globalsadd_global_var
f_builtinsr   builtinsload_builtinr  r(  r+  rF  load_globalrg   rx  rR   )r   r   r   variabler  s        r   _load_globalz&InstructionTranslatorBase._load_global  s   {{t~~%""11$t8LMt.()VWW48OOD4I""++D1t~~%$$T**4((({{//0E0Ed0KLHIIdkk..::8TJKt$		/''e\$5GHIr   c                l    d}| j                  |      }t        |      }t        j                  | ||      S )Nztorch.nn.modules.module)import_sourcer   rg   rx  )r   module_namemodule_sourcefglobals_values       r   nn_modules_globals_vtz/InstructionTranslatorBase.nn_modules_globals_vt  s6    /**;7'4$$T>=IIr   c                J   |j                   t        d      t        j                  dk\  r3t        j                  dk  r |j                   dz  r| j	                  |       | j                  |       t        j                  dk\  r"|j                   dz  r| j	                  |       y y y )Nr>  r6  r  r  )rA  r   rZ  r  	PUSH_NULLr  r  s     r   LOAD_GLOBALz%InstructionTranslatorBase.LOAD_GLOBAL  s    88 !KLLw&3+;+;g+E$((UV,NN4 $w&488a<NN4  ,8&r   c                   | j                         }|j                  }t        |      }|| j                  vrt	               | j                  |<   | j
                  j                  j                  || j                  |         }t        |t              rt        d|dg        | j
                  j                  j                  |||       y )Nz%Storing Tensor hook handle in globalsThis is not supported.r  )r  rw  rR   r  r  r(  r+  track_global_existingrV  r   r=   store_global)r   r   r  r   r  r  s         r   STORE_GLOBALz&InstructionTranslatorBase.STORE_GLOBAL  s    
{{d#t,,,*0(D!!$';;++AAD))$/
 e45?4	 	  --heDr   c                .   d|v rZt         j                  j                  j                  |   }|j	                  dd      j	                  dd      j	                  dd      }n t        |      }d|j	                  dd       }| j                  | j                  j                  ||       || j                  j                  |<   | j                  j                  }||vs||   |u st        d      |||<   | j                  j                  |       t        |      S )	z-Create an alias to a module for use in guardstorch_package>r   <rU  _dot_	__import_zGexpected alias not in f_globals or f_globals[alias] is value to be true)r  r  package_importer_package_imported_modulesr  r   add_import_sourcer(  import_sourcesglobal_scoper   update_co_namesrR   )r   r  r  aliasrz  s        r   r  z'InstructionTranslatorBase.import_source  s    k)MM22LLE ##C-55c3?GGWU  #;/E 3 3C ABCE<<#LL**5+>,7""5)KK,,	Y&)E*:e*C Y  !	%##E*E""r   c                ~    |j                  d|dz
        }t        |      |k  rt        d      |d   }|r| d| S |S )z
        Copied from the Cpython implementation of __import__
        Resolve a relative module name to an absolute one.
        https://github.com/python/cpython/blob/5a094f0255eea1db58fb2cf14c200971e64ec36e/Lib/importlib/_bootstrap.py#L902
        rU  r   z2attempted relative import beyond top-level packager   )rsplitr   ImportError)r   r   r  levelbitsbases         r   resolve_namez&InstructionTranslatorBase.resolve_name  sQ     ~~c519-t9uRSSAw#'$q1T1r   c                   | j                   j                  d      }| j                   j                  d      }|6|2||j                  k7  r#t        j	                  d||j                  d       |S ||j                  S t        j	                  dd       | j                   d   }d| j                   vr|j                  d	      d
   }|S )z
        Copied from the Cpython implementation of __import__
        https://github.com/python/cpython/blob/5a094f0255eea1db58fb2cf14c200971e64ec36e/Lib/importlib/_bootstrap.py#L1090
        __package____spec__z)__package__ != __spec__.parent (%r != %r)r  )
stacklevelzYcan't resolve package from __spec__ or __package__, falling back on __name__ and __path__r   __path__rU  r   )rz  r  r  r!  warning
rpartition)r   r  specs      r   calc_packagez&InstructionTranslatorBase.calc_package  s    
 ..$$]3~~!!*-Gt{{$:?KK 	   N;;KK8  
 nnZ0G/!,,S1!4r   c           
     l   | j                  d      \  }}|j                         }|j                         }|j                  }t        j                   d| d| d| }|| j
                  v r| j
                  |   }t        |      }n{	 t        |||| j
                        }|d
k7  r#| j                         }| j                  |||      }|s&|j                  d      d
   }	| j                  |	      }n| j                  |      }| j                   r| j                   j#                  |       t%        t&        j(                  t*        f      r| j-                  t/        ||             y t        dt1        |      dg 	       y # t        $ r, t        dd| d| d| dg t        j                  	       Y w xY w)Nr  r   )fromlistr  globalszImport failurezmodule_name: z, fromlist: z, level=z"Failure when attempting to import.r  r   rU  r  zBad import resultz%Import result is not a Python module.)rH  r  rw  rL   LOCAL_MOD_PREFIXrz  rR   
__import__r  r=   r   r  r  r  	partitionr  r  add_local_modrV  rW  rX  rK   rF  r   re   )
r   r   r  r  r  recorded_namer  r  pkgtop_level_module_names
             r   IMPORT_NAMEz%InstructionTranslatorBase.IMPORT_NAME	  s   ))A,x((*..0kk !112!E7!H:Q{mT 	 DNN*NN=1E!-0F"% NN	 z'')"//S%H (3(=(=c(B1(E%++,AB++K8,,]EB ee..<=II*5@A+CA  ,+K=XJhW\V]^ D9-889	 s   E> >1F32F3c                \    | j                  |       | j                  |j                         y r   )DUP_TOP
_load_attrrw  r  s     r   IMPORT_FROMz%InstructionTranslatorBase.IMPORT_FROMR	  s    T$r   c                t   || j                   vr#t        ddd| dg t        j                         | j                   |   }t	        |      rBt        | j                  j                        }t        ||      }t        j                  | ||      S t        |      st        d      t        j                  | |      S )Nz%failed to find name in frame builtinsr   zFailed to find name `z` in frame's builtins.r  z,expected is_builtin_constant(val) to be true)r|  r=   r   r  r  rR   r(  %name_of_builtins_dict_key_in_fglobalsrQ   rg   rx  rX   r   )r   rw  ri  builtins_source
var_sources        r   load_builtin_from_argvalz2InstructionTranslatorBase.load_builtin_from_argvalX	  s    (?3F8;QR&11	 oof%C=*AAO +?FCJ"((sJ??&s+$%STT"((s33r   c                X    | j                  | j                  |j                               y r   )rF  r  rw  r  s     r   r~  z&InstructionTranslatorBase.load_builtinp	  s    		$//<=r   c                N   | j                   t        d      | j                  t        d      |j                  t        d      t	               j                  d| j                   | j                  z
         | j                  |j                     | _         | j                   | _        y )Nr  0expected self.start_point is not None to be truer  ir_count)r   r   r  r.  r^   	incrementindexofr  s     r   r  zInstructionTranslatorBase.jumps	  s    ##+ J  # !STT;; !NOO''0043C3CC	
 $(<<#< 33r   Tc           	         |j                   t        d      | j                  j                  t	        ||j                   t        | j                                     y Nr  r.  r   r
  r   r-  r   r  r  s     r   
SETUP_LOOPz$InstructionTranslatorBase.SETUP_LOOP	  A    ;; !NOOdkk3tzz? STr   c           	         |j                   t        d      | j                  j                  t	        ||j                   t        | j                                     y r  r  r  s     r   SETUP_EXCEPTz&InstructionTranslatorBase.SETUP_EXCEPT	  r  r   c                8    | j                   j                          y r   )r
  r  r  s     r   	POP_BLOCKz#InstructionTranslatorBase.POP_BLOCK	  s    r   c                &    | j                  |       y r   setup_or_before_withr  s     r   
SETUP_WITHz$InstructionTranslatorBase.SETUP_WITH	      !!$'r   c           	         |j                   t        d      | j                  j                  t	        ||j                   t        | j                                     y r  r  r  s     r   SETUP_FINALLYz'InstructionTranslatorBase.SETUP_FINALLY	  sA    ;; !NOOdkk3tzz? STr   c                   t         j                  dk\  rQ| j                         }| j                         j                         }| j	                  |       | j	                  |       n/| j                         j                         }| j	                  |       	 t         j                  dk\  rCt        | |      \  }}| j                          | j	                  |       | j	                  |       y |j                  |       }| j	                  |       y # t        t        j                  t        j                  f$ r}t        |t        j                  t        j                  f      rt        j                  |        t         j                  dk\  r%| j	                  t        j                  d              n| j                          | j                  |       Y d }~y d }~ww xY w)Nr     r8  )rZ  r  r  realizerF  r   next_variableStopIterationr   ObservedUserStopIterationObservedIndexErrorrV  handle_observed_exceptionrm   ry  r  )r   r   null_or_idxitri  next_r  s          r   FOR_ITERz"InstructionTranslatorBase.FOR_ITER	  sW   w&((*K##%BIIbMIIk"##%BIIbM	7*24[I
U
		% 		#&&t,		#))""
 	
 !c;;S=S=STU--d37*
 		*11$78 
IIdOO#	s    AD +"D (G6BGGc                l    t        |t        j                  t        f      r|j	                  | g i       }|S r   )rV  r   rk   r   rG  r  s     r   _create_exception_typez0InstructionTranslatorBase._create_exception_type	  s6    )++-NO

 ##D"b1C
r   c                   | j                         } |j                  | d      }t        |t        t        f      st        d      t	        j                  ||      } |j                  | dt        j                  | d      |gi        y )Nr(  zKexpected isinstance( tb, (ConstantVariable, TracebackVariable) ) to be true__setattr__)
r  var_getattrrV  rm   r   r   from_frame_summarycall_methodrg   rx  )r   r   r  tbnew_tbs        r   _attach_traceback_to_exceptionz8InstructionTranslatorBase._attach_traceback_to_exception	  s    **,S__

 "/1BCD ]  #55mRH""496B		
r   c                   | j                  |      }t        | j                        rWt        |t        j
                        r=|j                  t        u r+t        j                  | t              j                  | g i       }| j                  |      r:t        |dd       -t        j                  j                   j#                         |_        | j                  |      rd| j&                  j)                  ||       t+        j,                  |j                        }t        |dd       } |d|j/                          |      t+        j0                  t2        | d|j5                          g       y )Npython_stackrj  raised exception )r'  z/exceptions must derive from BaseException, not r   )r  r/   r  rV  r   r   exc_typer  rg   rx  r)  rG  _isinstance_exceptionr  r  _guardsr   extract_stackr  r  rk  r   get_dynamo_observed_exception
debug_reprraise_observed_exception	TypeErrorpython_type_name)r   ri  rj  observed_exception_typer  s        r   _raise_exception_variablez3InstructionTranslatorBase._raise_exception_variable	  s9    ))#.
 %3	 ; ;<-!''l;II$PRTVWC &&s+^T2:$}};;IIKC %%c*
 33C[3Q&)&G&G&U#"3=L)#CNN$4#56<  	$$A#BVBVBXAYZ	
r   c           
     j   |j                   dk(  rt        | j                        st        j                  t
        | dg       t        | j                        st        d      | j                  d   }| j                  |      st        |      | j                  |d       y |j                   dk(  rO| j                  d   }	 | j                  |d	       | j                  j                         }| j                  |       y | j                         }| j                         }	 | j                  |d	       | j                  j                         }| j                  |       | j                  |      }|j                  | d
t        j                   | d      |gi        y # | j                  j                         }| j                  |       w xY w# | j                  j                         }| j                  |       | j                  |      }|j                  | d
t        j                   | d      |gi        w xY w)Nr   zNo active exception to reraiser  *expected len(self.exn_vt_stack) to be truer  Fr  r   Tr  	__cause__)rA  r   r  r   r  r)  r   r  r  r  rp  r  r  r  r  rg   rx  )r   r   ri  curr_excfrom_vtcauses         r   rh  z'InstructionTranslatorBase.RAISE_VARARGS
  s   88q=t((),, $.N-O t(()$%QRR##B'C--c2$S))**3E*BXX]**R.C>..s.E  ,,BBD33H= hhjG((*C..s.E  ,,BBD33H=33G<$$!$**4=uE	  ,,BBD33H=  ,,BBD33H=33G<$$!$**4=uE	s    F  G
 -G
A(H2c                    | j                   d   }t        |t              st        d      |j                  t
        u rt        dddg        y | j                  |       y )Nr  z6expected isinstance(tos, ExceptionVariable) to be truez CLEANUP_THROW with StopIterationr   zRReceived StopIteration when handling generator.throw/close. This is not supported.r  )r  rV  r   r   r  r  r=   RERAISEr   r   toss      r   CLEANUP_THROWz'InstructionTranslatorBase.CLEANUP_THROWG
  sZ    jjn#01 H  <<=(:p	 LLr   c                z   t         j                  dk\  re| j                         }|j                  r$| j                         }| j	                  |d       y | j                  |       | j	                  |d       y | j                         }| j                         }| j                         }| j	                  |d       y )Nr6  Fr  )rZ  r  r  rw  r  rF  )r   r   ri  r   _exc_tbs         r   r  z!InstructionTranslatorBase.RERAISEX
  s     w&((*C{{HHJ..s.F 		#..s.F88:D((*C((*C**3E*Br   c                "    t        |t              S r   )rV  r   r  s     r   r  z/InstructionTranslatorBase._isinstance_exceptiono
  s    #}--r   c                B   g }t         j                  dk\  rt         j                  dk  rdnd}t        | j                        |k\  st	        d      | j                  |    }| j                  d   }| j                  |      st	        d      t        |j                        }|j                  | d      }t         j                  dk\  rt        | j                  d	   t              s|j                  | j                  d	          nt        | j                        d
k\  st	        d      | j                  d   }| j                  d   }| j                  |      st	        d      t        |j                        }|j                  | d      }||||gz  }| j                  ||i        y )Nr6  r           z-expected len(self.stack) >= fn_loc to be truer  3expected self._isinstance_exception(val) to be truer(     z(expected len(self.stack) >= 7 to be trueir  )rZ  r  r   r  r   r  rk   r  r  rV  r   r   rG  )r   r   r   fn_locrR  ri  typr  s           r   WITH_EXCEPT_STARTz+InstructionTranslatorBase.WITH_EXCEPT_STARTr
  sr   &(w&**W4Q!F 

Ov-$%TUUVG$B**R.C--c2$I  "#,,/CB
 7*!$**R.,?KK

2/

Oq($%OPPBB**R.C--c2$I  "#,,/C7Bc22tR(r   c           	     	   	 d	d	 fd}t         j                  dk\  rL j                  j                  }|rt	         j
                        |j                  kD  r3 j                          t	         j
                        |j                  kD  r3|j                  r9 j                  t        j                    j                  j                                j                   j                  j                                 j                  |       y  j
                  j!                           j                  j                         } j#                  |       t%               t&        u r |        t	         j(                        rF j(                  j                         }|j*                  j,                  dk(  rЉ j/                  d        j                  j                          t	         j(                        dk(  rY j
                  j!                          t%               t&        u r,t1        dt3              	dz   g t4        j6                  	        j(                  j                         }|j*                  j,                  dk(  rЉ j                  j                         } j                  j9                          t	         j
                        |j:                  kD  r3 j                          t	         j
                        |j:                  kD  r3t=        t?        d
      dd d      } j(                  jA                  tC        |d t	         j
                                     t	         j                        dk\  rr j                  d   } j                  tE        jF                                 j                  |        j                  tE        jH                  |jJ                               nl j                  tM        jN                  d               j                  tM        jN                  d               j                  tM        jN                  d               j                  tE        jF                                 j                  |        j                  tE        jH                  |jJ                                j                  |       y  j
                  j!                          t%               t&        u r |        )NzDynamo found no exception handler at the top-level compiled function when encountering an exception. Exception will propagate outside the compiled region.c                 0   j                   j                         } t        j                  | j	                               }t        |      st        d      t        dd| j                          g t        j                  t        j                         y )Nz<expected isinstance(raised_exception, dynamo_exc) to be truezObserved exceptionr  r#  )r  rp  r   r  python_typerV  r   r=   r  r   r  rR  )r  
dynamo_excobserved_exn_gb_explanationraised_exceptionr   s     r   bubble_exception_to_interpreterzTInstructionTranslatorBase.exception_handler.<locals>.bubble_exception_to_interpreter
  s    ((>>@H::8;O;O;QRJ.
;$R  ,+H,?,?,A+BC7&11&22 *	r   r6  EXCEPT_HANDLERr  r   z#Observed exception (EXCEPT_HANDLER)z  This graph break is unexpected.r#  g    .Ar  r  r   )(rZ  r  r  rF  r   r  depthr  lastirF  rg   rx  r  r  rp  r  r   r  r]  rL  r
  r   r   rH  r=   r   r   r  rn  r/  r.   r   r   r-  r   r   rk   r  rm   ry  )
r   r  r  rF  r  block_stack_entryexception_varexcept_handler_instold_exceptionr  s
   ``       @r   r  z+InstructionTranslatorBase.exception_handler
  s   d 	$
	& w& 44BBM
 $**o(;(;;HHJ $**o(;(;; !&&II'--dD4L4L4S4ST
 		$++AACD 		-( 

  "  ,,BBD33H=:!6635&&4##$ %)$4$4$8$8$:!',,337GG IIaL%%))+4++,1 

((*:)>>)(M(+,<(=,G"D-E&E(9(D(D&E)9 /.(,(8(8(<(<(>%) (,,337GG, !% 1 1 G G I!!AAC $**o(9(E(EEHHJ $**o(9(E(EE
 '2#c(<LdTU&V#  ''#$7s4::O
 t(()Q.$($5$5b$9M IIi779:IIm,IIi778N8NOP II.55d;<II.55d;<II.55d;< 		)3356		-(		)33M4J4JKL 		+, 

  ":!6635&&r   c                   | j                         }t        | j                        dk(  rt        j                  d       }n| j                  d   }| j                  |       | j                  |       | j                  j                          y )Nr   r  )r  r   r  rm   ry  rF  rn  )r   r   ri  prev_excs       r   PUSH_EXC_INFOz'InstructionTranslatorBase.PUSH_EXC_INFO&  sk    ( hhjt  !Q&(8(?(?(EH((,H		(		#99;r   c                2   t         j                  dk\  rK| j                         }t        | j                        st        d      | j                  j                          y t        | j                        dkD  st        d      | j                  d   j                  j                  dk7  rt        d      | j                  j                          | j                  d       t        | j                        st        d      | j                  j                          y )	Nr6  r   r   z-expected len(self.block_stack) > 0 to be truer  r   zYBug in Dynamo tracing of exception handling.Top of the block stack is not EXCEPT_HANDLER.r  )
rZ  r  r  r   r  r   r
  r   r   rH  )r   r   r   s      r   
POP_EXCEPTz$InstructionTranslatorBase.POP_EXCEPTC  s    w&
At(()$%QRR!!#(()A-$%TUU#((//3CC$D    "IIaL t(()$%QRR!!#r   c                   t        | j                        dk\  st        d      | j                         }t        j
                  dk\  r| j                  d   }n| j                  j                         }t        |t        t        t        t        f      s,t        dt        |      d| dg t        j                         t        j
                  dk\  r=| j                  |      s,t        d	t        |      d
| dg t        j                         t        |t              r|j                   }n|g}|D ]  }t        |t        t        t        f      s,t        dt        |      d| dg t        j                         | j                  |      r"t#        |j$                  |j&                        r yt        |t(        j                        st#        |j&                  |j&                        s y y)Nr  (expected len(self.stack) >= 2 to be truer6  r  z Exception with bad expected typez"`except ...` has unsupported type rU  r  zCaught non-Exception valuezCExcept expects to receive an object of Exception type but received z#Exception with non-type expectationz!`except ...` expects a non-type: TF)r   r  r   r  rZ  r  rV  rk   r   r   r   r=   r   r   r  r  r  
issubclassr  rR  r   )r   expected_exc_typesexc_instanceexpected_typesexpected_types        r   check_if_exc_matchesz.InstructionTranslatorBase.check_if_exc_matches[  s   DJJ1$ !KLL!XXZw&  ::b>L
  ::>>+L 12	
 :./@AS@TTUV5)445	 w&--l;8-"efresst u9-889	 (-8/55N #N , 	M#65 A."CM?RS T9-889	 )),7J%%  = L)*C*CD  J
 3	6 r   c                j    | j                  t        j                  | | j                                      y r   )rF  rg   rx  r3  r  s     r   CHECK_EXC_MATCHz)InstructionTranslatorBase.CHECK_EXC_MATCH  s$    		/''d.G.G.IJKr   c                H    | j                         s| j                  |       y y r   )r3  r  r  s     r   JUMP_IF_NOT_EXC_MATCHz/InstructionTranslatorBase.JUMP_IF_NOT_EXC_MATCH  s    ((*IIdO +r   z`Encountered graph break when attempting to trace COMPARE_OP: a comparison operation, e.g. a == b)rF  r4  c                    |j                   dk(  r| j                  |       y | j                  t        |j                      | | j	                  d      i              y )Nzexception matchr  )rw  r5  rF  r   rH  r  s     r   
COMPARE_OPz$InstructionTranslatorBase.COMPARE_OP  sF    
 ;;++  &II)$++6tTYYq\2NOr   c                   t         j                  dk\  r| j                         }t        |t        t
        f      r7| j                  |       | j                  t        j                  | d             y | j                  t        j                  | t              |gi        | j                  t                      y | j                  t        j                  | t              | j                         gi        y )Nr  r   )rZ  r  r  rV  r   r   rF  rg   rx  rG  iterr   r   r   objs      r   GET_ITERz"InstructionTranslatorBase.GET_ITER  s    w&((*C#m<=		#		///a89""?#8#8t#DseRP		,.)44T4@488:,PRSr   zjEncountered graph break when attempting to trace CALL_FUNCTION: a call to a regular function, e.g. f(x, y)c                    | j                  |j                        }| j                         }| j                  ||i        y r   )rH  rw  r  rG  )r   r   r   rR  s       r   CALL_FUNCTIONz'InstructionTranslatorBase.CALL_FUNCTION  s3    
 yy%XXZ2tR(r   zjEncountered graph break when attempting to trace CALL_FUNCTION_EX: a variadic function call, e.g. f(*args)c           	     n   |j                   dk(  rt        i       }| j                         }n|j                   dk(  st        j                  dk\  r<| j                         }t        |t              rt        i       }| j                         }n9t        dd|j                    d|j                    g t        j                         t        j                  dk\  r+| j                         }t        |t              st        d	      | j                         }t        j                  d
k\  r>t        j                  dk  r+| j                         }t        |t              st        d	      t        t              st        t        | |            }t        t              rt        j                   | t"        |      }t        |t              rt        |t              s7t        ddt%        |       dt%        |       dg t        j&                         |j)                         }| j+                  ||j,                  |       y )Nr   r   r  z%Variadic function call with bad flagszflags: zHAttempted to call a variadic function (CALL_FUNCTION_EX) with bad flags r  r  z2expected isinstance(null, NullVariable) to be truer6  z0Variadic function call with bad args/kwargs typezargs type: z, kwargs type: z2Expected args to be a list and kwargs to be a dict)rw  rs   r  rZ  r  rV  r   r=   r   r  r   r   r   rc   r   rl   call_custom_dictr  re   r  keys_as_python_constantrG  r  )r   r   
kwargsvarsargsvarsnullrR  s         r   CALL_FUNCTION_EXz*InstructionTranslatorBase.CALL_FUNCTION_EX  s    ;;!*2.JxxzH[[A!1!1W!<J*l3.r2
xxzH?!$++/fgkgrgrfst5)445	 w&88:DdL1$H  XXZw&3+;+;g+E88:DdL1$H  
 %_T8%DEH j";<,==dD*UJ ($45Z>

 J%gh&7%8PZH[G\]P5)445  779
2x~~z:r   zyEncountered graph break when attempting to trace CALL_FUNCTION_KW: a function call with keyword arguments, e.g. f(x=True)c                   | j                         }| j                  |j                        }| j                         }t        |t              st        d      |j                         st        d      |j                         }|d t        |        |t        |       d  }}t        t        ||            }t        |      t        |      k7  rt        d      | j                  |||       y )Nz7expected isinstance(argnames, TupleVariable) to be truez1expected argnames.is_python_constant() to be truez0expected len(kwargs) == len(argnames) to be true)r  rH  rw  rV  r   r   r  r  r   r  ziprG  )r   r   argnamesr   rR  kwargs_listr  s          r   CALL_FUNCTION_KWz*InstructionTranslatorBase.CALL_FUNCTION_KW  s     88:yy%XXZ(M2 I  **, !TUU..0 !1CM>2D#h-9I4Jkc(K01v;#h-' !STT2tV,r   c                (   | j                  t        j                  |d             |j                  d   }| j                  d   |   }t
        j                  dk  r| j                  |       y | j                  t        j                  ||             y )Nr  r=  r   co_namesr6  )	r@  r   r  rw  r  rZ  r  r  LOAD_METHODr   r   rA  rw  s       r   LOAD_METHOD_SUPERz+InstructionTranslatorBase.LOAD_METHOD_SUPER1  st    ;..tA>?kk!n"":.s3g%OOF#[00fEFr   c                    | j                  t        j                  |d             |j                  d   }| j                  d   |   }| j                  |       y )Nr  r=  r   rN  )r@  r   r  rw  r  r  rP  s       r   LOAD_ATTR_SUPERz)InstructionTranslatorBase.LOAD_ATTR_SUPER:  sK    ;..tA>?kk!n"":.s3r   c                F   | j                  |j                         | j                         }t        j                  dk\  r#| j                  |       | j                  |       y t        j                  dk\  r#| j                  |       | j                  |       y t        d      )Nr  r6  zPLOAD_METHOD should have been rewritten to LOAD_ATTR. We should never reach here.)r  rw  r  rZ  r  rF  r  r   r<  s      r   rO  z%InstructionTranslatorBase.LOAD_METHOD@  sy    $hhjw&IIcNNN4 ( NN4 IIcN b r   c                    t        d      )Nz^CALL_METHOD should have been rewritten to CALL_FUNCTION. This function should never be called.)r   r  s     r   CALL_METHODz%InstructionTranslatorBase.CALL_METHODQ  s    l
 	
r   c                    | j                         }t        j                  | t              j	                  | |t        j                  | |      gi       }| j                  |       y r   )r  rg   rx  r  rG  rF  )r   attrr=  r  s       r   r  z$InstructionTranslatorBase._load_attrV  sS    hhj &&tW5CC/''d34

 			&r   c                    t         j                  dk\  r!|j                  dz  r| j                  |       y | j	                  |j
                         y )Nr8  r  )rZ  r  rA  rO  r  rw  r  s     r   	LOAD_ATTRz#InstructionTranslatorBase.LOAD_ATTR_  s<    w&xx!|  &$r   zkEncountered graph break when attempting to trace STORE_ATTR: storing an object's attribute, e.g. x.attr = yc                    | j                  d      \  }}t        j                  | t              j	                  | |t        j                  | |j
                        |gi        y )Nr  )rH  rg   rx  setattrrG  rw  )r   r   ri  r=  s       r   
STORE_ATTRz$InstructionTranslatorBase.STORE_ATTRg  sQ    
 99Q<SdG,::/''dkk:C@	
r   c                    | j                         }| j                  ||j                         t        j                  | t
              j                  | |t        j                  | |j                        gi        y r   )r  _maybe_sync_dealloc_attrrw  rg   rx  delattrrG  r<  s      r   DELETE_ATTRz%InstructionTranslatorBase.DELETE_ATTRs  s[    hhj%%c4;;7dG,::/''dkk:;	
r   c                    | j                   j                  j                  ||      rI| j                   j                  j                  ||      }t	        |t
              r| j                  |       y y y r   )r(  r+  has_pending_mutation_of_attr	load_attrrV  r   rX  )r   r=  r   attr_vars       r   r_  z2InstructionTranslatorBase._maybe_sync_dealloc_attr|  s]     ;;##@@dK{{//99#tDH(N3--h7 4 Lr   c                   g }|dk  st        d      |dk(  r|j                  t        d             | j                  dk(  rt	        d      nt	        d| j
                        }|j                  t	        d      t	        d      |g       |S )a  
        Debug CPython expects the stack to be empty after the return.
        Calling compile_subgraph will push cells and frame values to TOS.
        This function will pop those 2 values from the stack before actually returning.

        Expects the stack to be:
            cells, frame values, current frame stack (0 or 1 values)

        Pops cells and frame values, leaving the current frame stack as TOS.
        A return instruction is included.
        r   z"expected num_stack <= 1 to be truer  r  r  r=  r  )r   r  r+   r   r(   rw  )r   r  rm  return_insts       r   codegen_return_with_popsz2InstructionTranslatorBase.codegen_return_with_pops  s      Q !EFF>LLQ( {{n, ~.#N4;;G 	
 		*,>y,I;W	
 r   c                x    |rt        |j                  |j                        D ]  \  \  }}	}
t        t         j
                  |
         }|j                  t                      |j                  |       |j                  g t        d      |j                  |      |j                         |j                  |      t        d              |j                  D ]  \  }}	t        t         j                  |         }|j                  t                      |j                  |       |j                  g t        d      |j                  |      |j                         |j                  |j                   |j"                  |   z         t        d              t%        |      r#|j&                  st)        d      |j&                  }t+        d|j,                         }|rlt/         j0                  |      t3         fd j                  D              }t5        |j6                        t3        fd|D              }t3        fd|D              }|j                  t               |j                  |      |j                         t               g       |D ]`  }|j                  t               |j                  |j                   |j"                  |   z         |j                         gt        d             b |j                  t        d      t        d	t9        |      
      gt        d      t;        |j                   dd             n8t3        |j"                  j=                               }t3        |j6                        }t>        j@                  dk  rt9        |      dk7  rt)        d      t9         j
                        t9        |jB                        z
  } jD                  j,                  t)        d      tG        jH                   jJ                   jL                   jD                  j,                  |j,                  t3        d  jN                  D              |||t3        d  jN                  D              |t3        |j                        t3        |j                        t3        |jB                        t3        |       jP                         } tS        jT                   jJ                        jW                  dd              }|+tY        jZ                  |      tS        jT                  |      d<    j\                  j_                  || j`                          jb                  * jb                  je                  | j`                  d   |       tf        d   |jh                  xx   dz  cc<   ||fS )a.  
        Creates the resume function for the frame corresponding to `self`.

        Expects the TOS to be:
            [frame N cells, ..., frame 1 cells],
            [
                frame N stack + locals,
                ...,
                frame 1 stack + locals
            ]

        Some additional codegen may happen to prepare the frame stack + locals values for the generated resume function:
        - inactive context variables in the stack and locals will be replaced by their types
        - if the frame is a leaf frame, prune dead locals

        Regardless of codegen, the stack will be left in the same state as before.

        Args:
            - idx: depth of this frame: 0 corresponds to the leaf frame (frame N), N-1 to the root frame (frame 1).
            - resume_inst: the instruction that this frame should resume at
            - meta: metadata for this frame returned from OutputGraph.compile_subgraph
            - resume_codes: nested resume code objects generated from previous create_resume calls.
            - cg: codegen object to output to
            - is_leaf: True if `self` corresponds to the leaf frame.
            - handle_inactive_ctx: If True, handles inactive context variables as described above. This is necessary
                iff the resume function is traced
        r  r  z&expected resume_inst.target to be true__resume_at_c              3  N   K   | ]  }|v r|j                         vr|  y wr   )r  )r   r  r  r   s     r   r  z:InstructionTranslatorBase.create_resume.<locals>.<genexpr>  s0      !:!4+A+A+C"C !s   "%c              3  ,   K   | ]  }|vs|  y wr   r   r   r  argnames_null_sets     r   r  z:InstructionTranslatorBase.create_resume.<locals>.<genexpr>  s     S1AR8RQS   	c              3  ,   K   | ]  }|v s|  y wr   r   rm  s     r   r  z:InstructionTranslatorBase.create_resume.<locals>.<genexpr>	  s     !TQBS=S!!Tro  r  r	  r
  NTr8  r   z&variables should not be NULL in < 3.12z?expected self.current_instruction.offset is not None to be truec              3  H   K   | ]  }|j                   j                    y wr   )r.  r  r   r  s     r   r  z:InstructionTranslatorBase.create_resume.<locals>.<genexpr>A  s     <a!((//<s    "c              3  <   K   | ]  }|j                           y wr   )r7  rr  s     r   r  z:InstructionTranslatorBase.create_resume.<locals>.<genexpr>E  s     :A!++-:r  orig_graphmodulec                      y r   r   r   r   r   r   z9InstructionTranslatorBase.create_resume.<locals>.<lambda>Q      r   r   resumesr   )5rI  stack_ctx_argsstack_ctx_idxes_origr   rn   r  append_outputr'   r  r  r+   r  r  r(   locals_ctx_argsr  r  r  r0   r.  r   r1   r  r    rv  r6  r  locals_null_keysr   r#   re  rZ  r  stack_null_idxesr  rM   lookupr  r   r
  r(  r2   get_contextr  weakrefrefr(  install_resume_function_globalrz  r  add_resume_functionr[   r  )r   r  resume_instr  resume_codesr  is_leafhandle_inactive_ctxjr   j_origrv  r   resume_nameall_argnamesrJ  argnames_nullrA  	stack_lennew_codeorig_graphmodule_maybern  r  s   `                    @@r   r  z'InstructionTranslatorBase.create_resume  sG   T "%d&9&94;T;T"U A2DJJv4FG  !12$$R(  $Q,,S1 //1 ,,Q/	
 +>:   // a2D4H4H4NO  !12$$R(  $Q,,S1 //1 ,,T^^d>O>OPT>U-UV	
 +>:( K(%%$%MNN%,,K,{/A/A.B CD %d&7&7EE  !--! L
 !$D$9$9 :SSSH!!T\!TTM "$((-++-"$	   	  &(,,T^^d>O>OPS>T-TU//1 %Q		 &y1&|XG !^
 )tD	 T..3356H!$"7"78Mg%=!Q&$%MNN 

Oc$*?*?&@@	##**2 Q  $:#@#@KKKK$$++<4+;+;<<:)9)9::$%%&$&&'$''(,---!$
*"
!9!9$++!F!J!J"
 " "-EL[[&FL$$X./AB
 	224>>	
 <<#LL,,$..4k 	H,,-2-$$r   c                J   |j                   y	 t        |j                  |j                         }t	        | j
                        |z
  }| j
                  |   }t        |t              r|j                  t        j                  u sy| j                  j                  }|j                  r|j                  j                  n|j                  }|yt!        ||      }| j"                  j%                  d|      }t        |t'        |            | j
                  |<   y# t        $ r Y yw xY w)a  Replace warnings.warn on the symbolic stack with a wrapper that
        preserves the leaf frame's source location for warning dedup.

        When nested graph breaks inline a warnings.warn call into the root
        frame's bytecode, the root frame's line numbers defeat Python's
        per-location warning dedup.  This replaces the SkipFunctionVariable
        for warnings.warn on the symbolic stack before compile_subgraph, so
        the codegen naturally reconstructs the wrapper via LOAD_GLOBAL.
        N__warnings_warn_wrapperr  )rA  r,   r   r  r   r  rV  rz   r  	_warningsr  r  r  r  r   r  r  r(  install_globalrR   )	r   r   r!  callable_idxcallable_varleaf_filenameleaf_linenor  wrapper_names	            r   rC  z?InstructionTranslatorBase._maybe_replace_warnings_warn_on_stacke  s     88	+DKKBE 4::.zz,/|%9:""inn4///3~~dnn++4CSCS-m[I{{112KWU#7L6$


< %  		s    D 	D"!D"c           
        d| _         t        | j                  j                        }g }g }g }| }d}|i|| u r|}	n|j                  }	|	j
                  dk7  r3|j                  |       |j                  |       |j                  |	       |j                  }|dz  }|it        | j                        t        |d   j                        z
  }
|s|
dk\  st        d      |j                  t        |
dz                t        |
dz         D ]  }|j                  t!        d              |j                  t!        d             |j#                         S |d   | u r)|j                  t!        d|
	             d}|
|d   _        n|j                  t        |
             t        |
dz
        D ]  }|j                  t!        d              |j                  t!        dd	             ||d      j$                  }||d      xj$                  dz  c_        |d   j'                  t)                      |j                  g t+        d      |j-                  |d         |j/                         t1        ||d
             g }|D ]F  }|j3                  t5               |j-                  |      |j/                         gt        d             H |j3                  t!        d      t!        dt        |      	      g       |j                  |       |j                  g t        d      t7        j8                  |      t        d             g }g }t;        |      D ]L  \  }}|j=                  |||   |||      |||| u d
      \  }}|j                  |       |j                  |       N | j?                  |||       |j                  t!        d             |j#                         S )aP  
        Codegen all resume function(s) from the frame stack starting at `self`, call them,
        and return the result.
        Assumes that the unsupported instruction has already been run.

        Expects the TOS to be:
            [
                frame N locals,
                frame N-1 stack + locals,
                ...,
                frame 1 stack + locals
            ], *(frame N stack (post-unsupported instruction))

        Leaves the result of calling the resume functions on the stack and returns it
        (empty stack after return).

        Args:
            - inst: the instruction of the current (deepest) frame to resume at
            - all_stack_locals_metadata: metadata returned from OutputGraph.compile_subgraph - contains
                metadata such as local names, NULL positions, stack length, etc.
        Nr   r  r   z*expected current_num_stack >= 1 to be truer  r  r	  r
  T) r   r3   r(  r  r  r   r   r  r   r  r}  r   r  r+   rX  rz  r(   rj  r  rF  r   r&   r  r  r#   r  r'   rE  deepcopyrk  r  r  )r   r   r  r  txesidxesresume_instsr  r  r  current_num_stackr   stack_insert_idxfilter_instsr  resume_namesrg  resume_coder  s                      r   r  z/InstructionTranslatorBase.create_call_resume_at  s   6 $( t{{**+ 13*,37 ~"$55!!^3F#S!##K0]]F1HC    

Oc%a(99/
 

 
 &*$%QRR[):Q)>?@,q01 @  !3I!>?@/?@&&(( 7d? /BSTU 5F%a(2
 [):;<,q01 @  !3I!>?@/!DE8qBLL%eAh/99Q>9GLL*+ 	Q $$U1X. '')	
 %%57GN
	
  	C"$((-++- !^		 	"9-"<SZ@	
 	& 	Q|, Q	
 .0"4 	-IAv'-';';Q)%(3$($K ,,	- 	  |R@
+N;<""$$r   c           	     R   |j                  t        d             t        t        ||             D ]  \  }\  }}|t	        |      dz
  k(  r n|j
                  ru|j                  t               |j                  |      |j                         g       |j                  |j                  |d      gt        d      t        dd             n"|j                  |j                  |dd             |j                  t        d              |j                  t        d      t        d	t	        |       dz
  
      g       |j                  t        d             | d   j
                  r|j                  |j                  d      |j                         g       |j                  |j                  |d   d      gt        d      t        dd             |j                  g t        d             n;|j                  t        d      g|j                  |d   d      t        d             |j                  t               t               |j                  d      |j                         gt        d      |j                  d      t        d             t        j                   | d         r|j                  t        d	d
      g       nA|j                  g t        d      t        d	d
      t        d      t        dd
             |j                  t#        dd             y)a  
        Calls the provided resume functions.

        Expects the TOS to be in the state:
            [frame N cells, ..., frame 1 cells],
            [
                frame N stack + locals,
                frame N-1 stack + locals,
                ...,
                frame 1 stack + locals
            ]

        Pops the cells and frame values, leaving the result of calling the resume functions on TOS.

        Args:
            - resume_codes: list of resume function code objects to call
            - resume_names: list of the corresponding names of the resume functions
            - cg: PyCodegen object to output instructions to
        r  r   T)r  )	push_nullFr   r  r	  r
  r  r  r  LIST_EXTENDN)r  r&   rk  rI  r   r  r'   r  r  create_load_globalr+   r$   load_function_namer(   r*   rM   uses_boxed_callr%   )r  r  r  rg  r   r  s         r   r  z-InstructionTranslatorBase.codegen_call_resume4  s8   4 	Q((\<)HI 	-OA|dC%))  &(,,Q///1   --d-=$Q .a4@   !6!6tUA!FG[^,/	-0 	"9-"<S5F5JK	
 	Q(''((,++- )),r*:)E ^ *!t< !!_ &y1**<+;UC "!_* 	  $$R('') Q $$R( #?3	
  "11,r2BC '|; !!_&|; !^
 '}!< 	0=>r   c                   t         j                  dk\  rJ| j                  j                  }|r2| j                  r%|j
                  | j                  d   j
                  uryt        d | j                  D              xr{ | j                   xrl | j                  xs | j                   xrO | j                   xr@ | j                   xr1 | j                   xr" | j                  j                  j                  d u S )Nr6  r  Fc              3  <   K   | ]  }|j                           y wr   )r2  rr  s     r   r  zIInstructionTranslatorBase.should_compile_partial_graph.<locals>.<genexpr>  s     :A:r  )rZ  r  r  rF  r
  r.  r  r+  r  r   r  r*  !skip_one_hop_torch_function_depthr(  current_tracerr  )r   r   s     r   r  z6InstructionTranslatorBase.should_compile_partial_graph  s    w&,,::E$$D<L<LR<P<W<W(W:)9)9:: :NN": ,,MD4M4M0M: 333	:
 888: :::: **11T9
	
r   ziEncountered graph break when attempting to trace STORE_SUBSCR: trying to store subscript, e.g. x[key] = yc                Z    | j                  d      \  }}}|j                  | d||gi        y )Nr  __setitem__)rH  r  )r   r   ri  r=  keys        r   r  z&InstructionTranslatorBase.STORE_SUBSCR  s-    
 		!S#mc3Z<r   c                z    | j                  d      \  }}| j                  ||       |j                  | d|gi        y )Nr  __delitem__)rH  _maybe_sync_dealloc_subscrr  )r   r   r=  r  s       r   r  z'InstructionTranslatorBase.DELETE_SUBSCR  s9    99Q<S 	''S1mcUB7r   c                    ddl m} ddlm} d }	 t	        ||      r|j                  | |      }nt	        ||      r|j                  |      }t	        |t              r| j                  |       y y # t        $ r Y .w xY w)Nr   rr   )r   )
variables.dictsrs   variables.listsr   rV  getitem_constmaybe_getitem_constr  r   rX  )r   r=  r  rs   r   item_vars         r   r  z4InstructionTranslatorBase._maybe_sync_dealloc_subscr  s     	75		#/0,, C!232237 h/))(3 0  		s   <A/ /	A;:A;c                n    | j                  |j                        }| j                  t        |             y r   )rH  rw  rF  r   r   r   r  s      r   BUILD_TUPLEz%InstructionTranslatorBase.BUILD_TUPLE  s%    		$++&		-&'r   c                r    | j                  |j                        }| j                  t        ||              y )Nr   )rH  rw  rF  r   r  s      r   BUILD_SLICEz%InstructionTranslatorBase.BUILD_SLICE  s'    		$++&		-$/0r   c                     y)zCheck if comprehension speculation is allowed in nested context.

        For the base class (non-inlined), this always returns False.
        Fr   r   s    r   #_can_speculate_comprehension_nestedz=InstructionTranslatorBase._can_speculate_comprehension_nested  s    
 r   c                    t        | |      ry | j                  |j                        }| j                  t	        j
                  | |             y r   )r4   rH  rw  rF  rg   rx  r  s      r   r	  z$InstructionTranslatorBase.BUILD_LIST  s:    0t<		$++&		/''e45r   c                    t         j                  rt        dddg        | j                  |j                        }t        |t                     }| j                  |       y )Nzmissing BUILD_SET handlerr   z:Missing BUILD_SET bytecode handler (for testing purposes).r  mutation_type)r   +inject_BUILD_SET_unimplemented_TESTING_ONLYr=   rH  rw  r   rf   rF  )r   r   r  new_sets       r   	BUILD_SETz#InstructionTranslatorBase.BUILD_SET  sO    ==3X	 		$++&e3C3EF		'r   c           	     :   | j                  |j                        }g }|D ]  }	 |j                  t        | |               | j                   ||t                            y # t        $ r. t        dt        |      | dg t        j                         Y yw xY w)Nz-Failed to unpack object for BUILD_LIST_UNPACKzU cannot be unpacked into a list for the BUILD_LIST_UNPACK bytecode (`[*x, *y, ...]`).r  r  )rH  rw  r  rc   NotImplementedErrorr=   r   r   r  rF  rf   )r   r   r  seqsr  seqs         r   BUILD_LIST_UNPACKz+InstructionTranslatorBase.BUILD_LIST_UNPACK  s    yy% 
	C	_T378
	 			#e+;+=>? ' KH#&% (2 !29-889s   A##4BBc                2    | j                  |t               y )Nr  )r  r   r  s     r   BUILD_TUPLE_UNPACKz,InstructionTranslatorBase.BUILD_TUPLE_UNPACK+  s    t7r   c           	         t        | |      ry | j                  |j                  dz        }t        t	        |d d d   |dd d               }| j                  t        j                  | |             y )Nr  r   )r4   rH  rw  r  rI  rF  rg   rx  )r   r   r  ds       r   	BUILD_MAPz#InstructionTranslatorBase.BUILD_MAP0  sa    0t<		$++/*U3Q3Zqt!t-.		/''a01r   c                ~   | j                  |j                        }|D cg c].  }t        j                  | t              j                  | |gi       0 }}i }|D ]8  }t        |t              st        d      |j                  |j                         : | j                  t        j                  | |             y c c}w )Nz4expected isinstance(x, ConstDictVariable) to be true)rH  rw  rg   rx  r  rG  rV  rs   r   updater  rF  )r   r   r  rb  r  s        r   BUILD_MAP_UNPACKz*InstructionTranslatorBase.BUILD_MAP_UNPACK8  s    		$++& 
 !!$-;;D1#rJ
 
 "$ 	#Aa!23$J  MM!''"	# 			!!	

s   3B:c                   | j                         }| j                  |j                        }t        |t              st        d      |j                         st        d      t        | |      }t        |      t        |      k7  rt        d      | j                  t        j                  | t        t        ||                         y )N3expected isinstance(keys, TupleVariable) to be truez-expected keys.is_python_constant() to be truez,expected len(keys) == len(values) to be true)r  rH  rw  rV  r   r   r  rc   r   rF  rg   rx  r  rI  )r   r   re  r  s       r   BUILD_CONST_KEY_MAPz-InstructionTranslatorBase.BUILD_CONST_KEY_MAPO  s    xxz4;;'$. !VWW&&( !PQQtT*t9F# !OPP		!!Sv&'	
r   c                @   | j                  d      \  }}|j                  dkD  st        d      |j                  t        d      | j                  |j                      j                         }t        |t              st        d      |j                  | d||fi        y )Nr  r   #expected inst.argval > 0 to be truer>  6expected isinstance(obj, ConstDictVariable) to be truer  )	rH  rw  r   rA  r  r  rV  rs   r  )r   r   r  r  r=  s        r   MAP_ADDz!InstructionTranslatorBase.MAP_ADDb  s    yy|1a !FGG88 !KLLjj$((#++-#01 H  	maVR8r   c                P   | j                         }|j                  dkD  st        d      |j                  t        d      | j                  |j                      }t        |t              st        d      |j                         st        d      |j                  | d|gi        y )Nr   r  r>  0expected isinstance(obj, SetVariable) to be true$expected obj.is_mutable() to be truer  	r  rw  r   rA  r  rV  r   
is_mutabler  r   r   r  r=  s       r   SET_ADDz!InstructionTranslatorBase.SET_ADDo  s    HHJa !FGG88 !KLLjj$((##{+ !STT~~ !GHHeaS"-r   c                P   | j                         }|j                  dkD  st        d      |j                  t        d      | j                  |j                      }t        |t              st        d      |j                         st        d      |j                  | d|gi        y )Nr   r  r>  r  r  r  r  r  s       r   
SET_UPDATEz$InstructionTranslatorBase.SET_UPDATE|  s    HHJa !FGG88 !KLLjj$((##{+ !STT~~ !GHHhR0r   c                   | j                         }|j                  dkD  st        d      |j                  t        d      | j                  |j                      j                         }t        |t              st        d      |j                         st        d      | j                  j                  j                  |       |j                  j                  |       y )Nr   r  r>  1expected isinstance(obj, ListVariable) to be truer  )r  rw  r   rA  r  r  rV  r   r  r(  r+  mutationr  r   r  s       r   r  z%InstructionTranslatorBase.LIST_APPEND  s    HHJa !FGG88 !KLLjj$((#++-#|, !TUU~~ !GHH  ))#.		r   c                v   |j                   }t        j                  dk  r| j                         }| j                         }t        j                  dk\  rKt	        |j
                  d      st        d      t        j                  | |j
                  j                        }d }d }d }d }t        j                  dk  rV|T|dz  r| j                         }|dz  r| j                         }|dz  r| j                         }|dz  r| j                         }t        || j                  |||      }	|r~t        |t              st        d	      |j                  }
t        t!        t#        |
d d d   |
dd d   d
            t%                     }|	j'                  |       j)                  d|       | j+                  |	       y )Nr6  co_qualnamez6expected hasattr(code.value, "co_qualname") to be truer     r  r  r   z:expected isinstance(annotations, TupleVariable) to be trueTstrictr  r   )rA  rZ  r  r  r5  r  r   rg   rx  r  ry   rz  rV  r   r  rs   r  rI  rf   get_dict_vtsetitemrF  )r   r   r  fn_namer  defaultsclosurer   
kwdefaultsrR  r  anns               r   MAKE_FUNCTIONz'InstructionTranslatorBase.MAKE_FUNCTION  s   g%hhjGxxzw& 4::}5$L  &++D$**2H2HIG
g% 4<"hhjG4<"&((*K4<!%J4<#xxzH'NN
 k=9$P 
  %%E#SssU14a4[>?.0C NN4 ((!3 			"r   c           	     ^   | j                         }t        | |      }t        |      |j                  k  r&t	        | d|j                   dt        |       d       t        |      |j                  kD  rt	        | d|j                   d       t        |      D ]  }| j                  |        y )Nz&not enough values to unpack (expected , got r  z$too many values to unpack (expected )r  rc   r   rw  r:   r   rF  )r   r   r  ri  rg  s        r   r  z)InstructionTranslatorBase.UNPACK_SEQUENCE  s    hhjdC(s8dkk!8VCPSH:UVW s8dkk!6t{{m1E # 	AIIaL	r   c           	        d|j                   cxk  rdk  st        d       t        d      |j                   dz  }|j                   dz	  }| j                         }t        | |      x}rt	        | |      }t        |      ||z   k  rt        | d||z    dt        |       d       |d | }||t        |      |z
   }|t        |      |z
  d  }	t        |	      D ]  }
| j                  |
        | j                  t        |t               	             t        |      D ]  }
| j                  |
        y t        d
t        |      | dg t        j                         y )Nr   i  z.expected 0 <= inst.argval <= 0xFFFF to be true   r  z/not enough values to unpack (expected at least r  r  r  z%Failed to unpack object for UNPACK_EXz; cannot be unpacked into a list for the UNPACK_EX bytecode.r  )rw  r   r  r   rc   r   r:   r   rF  r   rf   r=   r   r   r  )r   r   r  suffixr  iteratorr?  vals_prefix	vals_listvals_suffixitems              r   	UNPACK_EXz#InstructionTranslatorBase.UNPACK_EX  sl   T[[*F* !QRR + !QRRt#!hhj&tS1181"42D4y6F?*!EfvoEVV\]`ae]f\gghi w-KVc$i&&89Is4y6134K -  		$ IIl9<L<NOP -  		$  ?C"e#^_5)445	r   z-Encountered intentional debugging graph breakc                >    | j                   rt        ddddg       y y )Nz#Forced graph break on leaf functionr   zSForced graph break on non-inlining function for nested graph break testing purposeszGSet torch._dynamo.config.debug_force_graph_break_on_leaf_return = Falser  )r  r=   r  s     r   graph_break_on_leaf_functionz6InstructionTranslatorBase.graph_break_on_leaf_function  s0     $$=6 ^ %r   c                F    |j                   dk(  r| j                  |       y y )NGRAPH_BREAK_IF_LEAF)rw  r  r  s     r   r  zInstructionTranslatorBase.NOP
  s"    ;;//--d3 0r   c                $    | j                          y r   r  r  s     r   r  z!InstructionTranslatorBase.POP_TOP      
r   c                    | j                         }| j                         }| j                  |       | j                  |       y r   r  rF  r   r   r  r  s       r   ROT_TWOz!InstructionTranslatorBase.ROT_TWO  s.    HHJHHJ		!		!r   c                    | j                         }| j                         }| j                         }| j                  |       | j                  |       | j                  |       y r   r  )r   r   r  r  cs        r   	ROT_THREEz#InstructionTranslatorBase.ROT_THREE  sD    HHJHHJHHJ		!		!		!r   c                   | j                         }| j                         }| j                         }| j                         }| j                  |       | j                  |       | j                  |       | j                  |       y r   r  )r   r   r  r  r  r  s         r   ROT_FOURz"InstructionTranslatorBase.ROT_FOUR   sZ    HHJHHJHHJHHJ		!		!		!		!r   c                h    | j                         }| j                  |       | j                  |       y r   r  )r   r   r  s      r   r  z!InstructionTranslatorBase.DUP_TOP*  s#    HHJ		!		!r   c                    | j                         }| j                         }| j                  |       | j                  |       | j                  |       | j                  |       y r   r  r	  s       r   DUP_TOP_TWOz%InstructionTranslatorBase.DUP_TOP_TWO/  sD    HHJHHJ		!		!		!		!r   c                ,   |dk(  r,t        j                  | t              j                  | |gi       S |dk(  r,t        j                  | t              j                  | |gi       S |dk(  r,t        j                  | t
              j                  | |gi       S |S )Nr   r  r  )rg   rx  r   rG  r  ascii)r   r  flags      r   _convert_valuez(InstructionTranslatorBase._convert_value7  s    19"((s3AA$QSTTQY"((t4BB4%RTUUQY"((u5CCD5'SUVVr   c                   | j                         }t        |t              r@ddlm}m}  |j                   |||      |j                  |       }| j                  |       y | j                  ||dz        }t        j                  | d|j                         z   dz         }| j                  t        t        j                         ||gi        y )Nr   )LazySymNodeFormatStringr~   )r  r   r  z{:})r  rV  r   torch._dynamo.variables.lazyr  r~   ry  r  rF  r  rg   rx  r  rG  rk   r   format)r   fmt_specr  r  r  r~   fmt_vars          r   _format_valuez'InstructionTranslatorBase._format_value@  s    
e_-
 /'..'x8RVE IIe##E54<8!''$4466<
 	?3::6%8H"Mr   c                    |j                   }|t        d      |dz  dk(  r| j                         }nt        j                  | d      }| j                  ||      S )N%expected flags is not None to be truer  r   )rA  r   r  rg   rx  r  )r   r   r  r  s       r   FORMAT_VALUEz&InstructionTranslatorBase.FORMAT_VALUEV  sX    = !HIIDLT!xxzH&,,T26H!!(E22r   c           
     n   g }g }i }|j                   t        d      | j                  |j                         D ]:  }|j                         r#|j	                  d       |j	                  |       7t        |t        j                        r|j	                  |j                         |j                  |j                         t        |j                               t        |j                  j                               z  r2t        dd| d| d|j                   dg t        j                          |j#                  |j                         t        d	t%        |      d
g t        j                          = | j'                  t        j                  j)                  dj+                  |      ||             y )Nr>  z{}zBUILD_STRING key conflictzformat_string_parts: z
, kwargs: z, part.sym_kwargs: z1Failed to build format string due to key conflictr  zBUILD_STRING type errorzLFormat string part type is not correct - expected constant or format string.r   )rA  r   rH  r  r   rV  r   StringFormatVariableformat_stringr  sym_argsr  re  
sym_kwargsr=   r   r  r  r   rF  ry  r  )r   r   format_string_partsr   r  parts         r   BUILD_STRINGz&InstructionTranslatorBase.BUILD_STRING`  s{   )+&(-/88 !KLLIIdhh' 	D&&(#**40D!D)"@"@A#**4+=+=>DMM*v{{}%DOO,@,@,B(CC! ;"78K7LJW]V^^qrv  sB  sB  rC  !D$W= 1 < <=	 doo.5I n9-889	!	, 			**11+,dF	
r   c                    |j                   dk(  s|j                   dk(  st        d      |j                   dk(  rdnd}| j                  t        |   | | j	                  d      i              y )Nr   r   8expected inst.argval == 0 or inst.argval == 1 to be trueiszis notr  )rw  r   rF  r   rH  )r   r   rw  s      r   IS_OPzInstructionTranslatorBase.IS_OP  s`    q DKK1$4 J  )x		%f-dDIIaL"EFr   c                    |j                   dk(  s|j                   dk(  st        d      | j                  d      \  }}|j                   }| j                  t	        | ||             |dk(  r| j                  |       y y )Nr   r   r+  r  )rw  r   rH  rF  r   	UNARY_NOT)r   r   leftrightr  s        r   CONTAINS_OPz%InstructionTranslatorBase.CONTAINS_OP  ss    q DKK1$4 J  iile[[		"4567NN4  r   c                P   | j                         }|j                  dkD  st        d      |j                  t        d      | j                  |j                      }t        |t              st        d      |j                         st        d      |j                  | d|gi        y )Nr   r  r>  r  r  r  )	r  rw  r   rA  r  rV  r   r  r  r  s       r   r  z%InstructionTranslatorBase.LIST_EXTEND  s    HHJa !FGG88 !KLLjj$((##|, !TUU~~ !GHHhR0r   c                    | j                  t        j                  | t              j	                  | | j                         gi              y r   )rF  rg   rx  r6  rG  r  r  s     r   LIST_TO_TUPLEz'InstructionTranslatorBase.LIST_TO_TUPLE  s6    		!!$.<<TDHHJ<QST	
r   c                   | j                   d   }| j                  |      st        d      |j                  t        u rt        j                  | t              j                  | t        j                  | d      gi       }|j                  | dt        j                  | d      |gi        |j                  | dt        j                  | d      |gi        || j                   d<   y y )Nr  r  zgenerator raised StopIterationr  rr  r  )
r  r  r   r  r  rg   rx  r)  rG  r  )r   r   ri  new_vals       r   STOPITERATION_ERRORz-InstructionTranslatorBase.STOPITERATION_ERROR  s     jjn))#. !VWW<<=(%++D,?MM &&t-MNOG
  &&t];SA	 mo&;&;D+&NPS%TVX %DJJrN )r   c                l   | j                         }|j                  dkD  st        d      |j                  t        d      | j                  |j                      j                         }t        |t              st        d      |j                         st        d      |j                  | d|gi        y )Nr   r  r>  r  r  r  )
r  rw  r   rA  r  r  rV  rs   r  r  r  s       r   
DICT_MERGEz$InstructionTranslatorBase.DICT_MERGE  s    HHJa !FGG88 !KLLjj$((#++-#01 H  ~~ !GHHhR0r   c                $    | j                          y r   r  r  s     r   	GEN_STARTz#InstructionTranslatorBase.GEN_START  r  r   c           	        | j                   d   }|j                         r=| j                  t        j                  | t        |j                                            y | j                  |j                  | dg i              y )Nr  r  )r  r  rF  rg   rx  r   r  r  r  s      r   GET_LENz!InstructionTranslatorBase.GET_LEN  s]    jjn!!#IIo++D#c6L6L6N2OPQIIcoodIr2>?r   c                    | j                   d   }| j                  | j                  t        j                  | t
              |gi              y)zr
        If STACK[-1] is an instance of collections.abc.Mapping, push True.
        Otherwise, push False
        r  N)r  rF  r  rg   rx  rG   r  s      r   MATCH_MAPPINGz'InstructionTranslatorBase.MATCH_MAPPING  sC    
 jjn		,,%%dO<	
r   c                    | j                   d   }| j                  | j                  t        j                  | t
              |gi              y Nr  )r  rF  r  rg   rx  rJ   r  s      r   MATCH_SEQUENCEz(InstructionTranslatorBase.MATCH_SEQUENCE  sB    jjn		,,%%d,?@	
r   c           	        | j                  d      \  }}}t        j                  | |j                        }| j	                  | j                  t        j                  | t              ||||gi              t        j                  dk  rD| j                  d   }| j	                  t        j                  | t        |t                            y y )Nr  r6  r  )rH  rg   rx  rA  rF  r  rH   rZ  r  r  r`   rm   )r   r   subjectr  namesrA  r  s          r   MATCH_CLASSz%InstructionTranslatorBase.MATCH_CLASS  s    "iile##D$((3		,,%%d,<=#sE*	
 g%**R.CIIo++DfSBR6S2STU &r   c           	        | j                   d   }| j                   d   }t        |t              st        d      | j	                  | j                  t        j                  | t              ||gi              t        j                  dk  rD| j                   d   }| j	                  t        j                  | t        |t                            y y )Nr  r  r  r6  )r  rV  r   r   rF  r  rg   rx  rI   rZ  r  r`   rm   )r   r   re  r=  r  s        r   
MATCH_KEYSz$InstructionTranslatorBase.MATCH_KEYS  s    zz"~jjn$. !VWW		,,%%dO<sDk2	
 g%**R.CIIo++DfSBR6S2STU &r   c                D    | j                  | j                  d             y )Nr   rF  r  r  s     r   LOAD_ASSERTION_ERRORz.InstructionTranslatorBase.LOAD_ASSERTION_ERROR  s    		$//0@ABr   c                D    | j                  | j                  d             y )N__build_class__rK  r  s     r   LOAD_BUILD_CLASSz*InstructionTranslatorBase.LOAD_BUILD_CLASS  s    		$//0ABCr   z`Encountered graph break when attempting to trace BINARY_SUBSCR: a binary subscript, e.g. x[attr]c                    |j                   dk(  r| j                  |       d| _        y t        j                  dk\  r!|j                   dk(  r| j                  |       y | j                  rt        d      y )Nr   Fr  r  z/expected not self.accept_prefix_inst to be true)rA  append_prefix_instr  rZ  r  r   r  s     r   RESUMEz InstructionTranslatorBase.RESUMEE  sc    88q=##D)&+D#(TXX]##D)&&$%VWW 'r   c                b    |j                   t        d      t        |j                      | |      S Nr>  )rA  r   _binary_op_lookupr  s     r   	BINARY_OPz#InstructionTranslatorBase.BINARY_OPR  s.    xx$%OPP$TXX.tT::r   c                     y r   r   r  s     r   r;  z!InstructionTranslatorBase.PRECALLW      r   c                H   |j                   t        d      | j                  d   |j                      }t        |t              st        d      |D ]  }t        |t
              rt        d       | j                  t        d      t        j                  |      | _        y )Nr>  	co_constsz/expected isinstance(kw_names, tuple) to be truez)expected isinstance(name, str) to be truez)expected self.kw_names is None to be trueru  )	rA  r   r  rV  r6  r   rD  rm   ry  )r   r   rD  r   s       r   r<  z"InstructionTranslatorBase.KW_NAMESZ  s    88 !KLL$$[1$((;(E* !RSS 	RDdC($%PQQ	R ==$ !LMM(//h?r   c                6    | j                  t                      y r   )rF  r   r  s     r   r  z#InstructionTranslatorBase.PUSH_NULLg  s    		,.!r   c                n   |rut         j                  dk\  st        d      | j                         }t	        |t
              st        d      |j                         st        d      |j                         }n$| j                  r| j                  j                  nd}|j                  t        d      | j                  |j                  dz         }t         j                  dk\  r!|d   }t	        |d	   t              rg n|d	   g}n&t	        |d   t              r|d	   }g }n|d   }|d	   g}|rX||dt        |        z   }|t        |       d  }t        t        ||            }t        |      t        |      k7  rt        d
      ||dd  z   }i }	 | j!                  |||       d | _        y # d | _        w xY w)Nr  z/expected sys.version_info >= (3, 13) to be truez7expected isinstance(kw_names, TupleVariable) to be truez1expected kw_names.is_python_constant() to be truer   r>  r  r   r   z0expected len(kwargs) == len(kw_names) to be true)rZ  r  r   r  rV  r   r  r  rD  r  rA  rH  r   r   r  rI  rG  )	r   r   call_kwrD  contentsrR  r   rK  r  s	            r   _callzInstructionTranslatorBase._callj  s    $$/$%VWWxxzHh6$M  ..0$G   224H.2mmt}}**H88 !KLL99TXX\*w&!B#HQK>2Xa[MD(1+|4a[a[ }(1H~66D"CM>#34K#h45F6{c(m+$%WXX(12,&DF	! r40 DMDDMs   F+ +	F4zTEncountered graph break when attempting to trace CALL: a function call, e.g. f(x, y)c                &    | j                  |       y r   r_  r  s     r   r:  zInstructionTranslatorBase.CALL  s    
 	

4r   c                    |j                   t        d      | j                  | j                  |j                              y rT  )rA  r   rF  r  r  s     r   COPYzInstructionTranslatorBase.COPY  s3    88 !KLL		$**dhhY'(r   c                    |j                   t        d      | j                  |j                       | j                  d   c| j                  d<   | j                  |j                    <   y )Nr>  r  )rA  r   r  r  s     r   SWAPzInstructionTranslatorBase.SWAP  sS    88 !KLL04

DHH90EtzzRT~-

2

DHH9-r   c                     y r   r   r  s     r   CACHEzInstructionTranslatorBase.CACHE  rX  r   c                &    | j                  |       y r   r  r  s     r   BEFORE_WITHz%InstructionTranslatorBase.BEFORE_WITH  r  r   c           	        t        |t              r+|j                         s| j                  j	                  |       t
        j                  dk\  r|j                  r>| j                  r/|j                  j                  | j                  d   j                  urd }nN| j                  j                  t        d      | j                  j                  j                  }n|j                  }|rt        | t              st        j                  r;| j                  j	                  t        ||t!        | j"                        |             n9| j                  j	                  t        ||t!        | j"                                     |j%                  |       S )Nr6  r  zCexpected self.next_instruction.exn_tab_entry is not None to be true)rV  ro   supports_graph_breaksr*  r   rZ  r  rF  r
  r.  r  r   rL  r   r  r-  r   r  enter)r   rv  r   r.  s       r   	enter_ctxz#InstructionTranslatorBase.enter_ctx  s4    s:;--/0077<w&
 !!$$%%,,D4D4DR4H4O4OO((66>(]  ..<<CC[[F$ 56&:T:T  ''#D&#djj/3G   ''fc$**o(VWyyr   c                P    t        dd|  d| j                          dg d       y )NzUnsupported context managerz1Attempted SETUP_WITH/BEFORE_WITH/LOAD_SPECIAL on z%Dynamo does not know how to enter a `z` context manager.)z,Avoid using the unsupported context manager.aE  If the context manager seems like it should be supported (e.g. torch.set_grad_enabled), then it may be the case that it was created outside the compiled region, which Dynamo does not support. Supported context managers can cross graph break boundaries only if they are local non-closure variables, or are intermediate values.zFile an issue to PyTorch. Simple context managers can potentially be supported, but note that context managers can't be supported in generalr  )r=   r  )rv  s    r   unsupported_ctx_graph_breakz5InstructionTranslatorBase.unsupported_ctx_graph_break  s3    1GuM?@T@T@V?WWij		
r   c                @   | j                         }t        |t        t        f      s| j	                  |       t        |t        t        f      st        d      | j                  t        ||j                               | j                  | j                  ||             y )N`expected isinstance( ctx, (ContextWrappingVariable, GenericContextWrappingVariable) ) to be true)
r  rV  rn   ro   ro  r   rF  rq   r.  rm  )r   r   rv  s      r   r  z.InstructionTranslatorBase.setup_or_before_with  s    hhj)+IJ
 ,,S1 )+IJ
 !r  			*3<=		$..d+,r   c                h    | j                   st        d      | j                  j                  |       y )Nz+expected self.accept_prefix_inst to be true)r  r   r  r   r  s     r   rQ  z,InstructionTranslatorBase.append_prefix_inst  s+    && !NOO  &r   c                @   t         j                  dk\  rz| j                  snt        | j                  |j
                     t              st        d      | j                  j                  j                         | j                  |j
                  <   y | j                  |       y )Nr8  zOexpected isinstance(self.symbolic_locals[inst.argval], NullVariable) to be true)rZ  r  r  rV  r  rw  r   r   r(  r+  track_cell_newrQ  r  s     r   	MAKE_CELLz#InstructionTranslatorBase.MAKE_CELL  s    w&t/F/F d224;;?N$e  ((779   - ##D)r   c                &    | j                  |       y r   rQ  r  s     r   COPY_FREE_VARSz(InstructionTranslatorBase.COPY_FREE_VARS       %r   c                &    | j                  |       y r   rw  r  s     r   RETURN_GENERATORz*InstructionTranslatorBase.RETURN_GENERATOR#  ry  r   c                2   t         j                  dk\  r| j                          n| j                  d       t         j                  dk\  rO| j                  |   }|| j
                  v r1| j
                  j                  |       | xj                  dz  c_        y y y )Nr  r  r8  r   )rZ  r  r  rH  r  _comprehension_end_for_ipsdiscard_comprehension_depth)r   r   
current_ips      r   END_FORz!InstructionTranslatorBase.END_FOR*  s    w&HHJIIaL w&d+JT<<<//77
C))Q.) = 'r   c                    t        | j                  j                  |j                  d       t              r6t        d|j                  d|j                   g t        j                         | j                  |       y )Nz)LOAD_FAST_CHECK on uninitialized variablez/Attempted to load uninitialized local variable r  )	r`   r  r  rw  r   r=   r   r  rL  r  s     r   LOAD_FAST_CHECKz)InstructionTranslatorBase.LOAD_FAST_CHECK7  s`    $&&**4;;=|LCMdkk][5)445	 	tr   c                    |j                   | j                  vr| j                  t                      n| j	                  |       t               | j                  |j                   <   y r   )rw  r  rF  r   rL  r  s     r   LOAD_FAST_AND_CLEARz-InstructionTranslatorBase.LOAD_FAST_AND_CLEARA  sD    ;;d222IIln%NN4 ,8NT[[)r   c                    | j                  t        j                  |d             |j                  t	        d      |j                  dz  r| j                  |       y | j                  |j                         y )Nr  r=  r>  r   )r@  r   r  rA  r   rO  r  rw  r  s     r   LOAD_SUPER_ATTRz)InstructionTranslatorBase.LOAD_SUPER_ATTRH  s\    ;..tA>?88 !KLL88a<T"OODKK(r   c                >   |j                   dk(  r| j                  |       y |j                   dk(  r| j                  |       y |j                   dk(  r5t        | | j	                               }| j                  t        |             y |j                   dk(  rN| j	                         j                         }t        j                  t        |            }| j                  |       y t        dd|j                    d|j                    dg t        j                  	       y )
Nr  r     r  z Missing CALL_INTRINSIC_1 handlerzCALL_INTRINSIC_1 operand: z,No handler implemented for CALL_INTRINSIC_1  instruction.r  )rw  r8  UNARY_POSITIVErc   r  rF  r   r  r   TypingVariabler   r=   r   rR  )r   r   r  r  tvs        r   CALL_INTRINSIC_1z*InstructionTranslatorBase.CALL_INTRINSIC_1Q  s    ;;!$$T*[[A%[[A#D$((*5EIImE*+[[A
--/A))'!*5BIIbM:4T[[MBJ4;;-Wde6)556	r   c                   | j                         }| j                         }|j                  dk(  rVt        |t              st	        d      |j                  | dt        j                  d      |gi        | j                  |       y t        dd|j                   d|j                   dg t        j                  	       y )
Nr  z>expected isinstance(arg1, BaseUserFunctionVariable) to be truer  __type_params__z Missing CALL_INTRINSIC_2 handlerzCALL_INTRINSIC_2 operand: z,No handler implemented for CALL_INTRINSIC_2 r  r  )r  rw  rV  rt   r   r  rm   ry  rF  r=   r   rR  )r   r   arg2arg1s       r   CALL_INTRINSIC_2z*InstructionTranslatorBase.CALL_INTRINSIC_2i  s    xxzxxz;;! d$<=$T  !(():;TB	 IIdO:4T[[MBJ4;;-Wde6)556	r   c                f    | j                         }| j                          | j                  |       y r   r  r  s      r   END_SENDz"InstructionTranslatorBase.END_SEND  s!    hhj
		#r   zpEncountered graph break when attempting to trace CALL_KW: a function call with keyword arguments, e.g. f(x=True)c                *    | j                  |d       y )NT)r]  ra  r  s     r   CALL_KWz!InstructionTranslatorBase.CALL_KW  s     	

4
&r   c                J    | j                   j                  dvrt        d      y )N)POP_JUMP_IF_TRUEPOP_JUMP_IF_FALSEr/  zmexpected self.next_instruction.opname in ( "POP_JUMP_IF_TRUE", "POP_JUMP_IF_FALSE", "UNARY_NOT", ) to be true)r  r   r   r  s     r   r  z!InstructionTranslatorBase.TO_BOOL  s4       '' 0
 

 ! 
r   c                   |j                   }|t        d      | j                         }t        |t              st        d      | j                         }|dz  rpt
        j                  dk\  st        d      |j                  | t        j                  | d      gi       }|j                  | dt        j                  d      |gi        n|d	z  r||_        n|d
z  rt        |t              st        d      |j                  }t!        t#        t%        |d d d   |dd d   d            t'                     }|j)                  |       j+                  d|       n|dz  r||_        n|dz  r||_        | j1                  |       y )Nr   z>expected isinstance(fn, NestedUserFunctionVariable) to be true   r  z/expected sys.version_info >= (3, 14) to be truer   r  r   r  r  z3expected isinstance(attr, TupleVariable) to be truer  Tr  r  )rA  r   r  rV  ry   rZ  r  rG  rg   rx  r  rm   ry  r  r   r  rs   r  rI  rf   r  r  r  r  rF  )r   r   r  rR  rX  r  r  s          r   SET_FUNCTION_ATTRIBUTEz0InstructionTranslatorBase.SET_FUNCTION_ATTRIBUTE  su   = !HIIXXZ"89 P  xxz4<$$/$%VWW %%d_-B-B4-K,LbQDNN!(():;TB	 T\BJT\dM2$I 
 JJE#SssU14a4[>?.0C NN4 ((!3 T\ BMT\BK		"r   c                    |j                   t        d      | j                  | j                  | j	                         |j                                y rT  )rA  r   rF  r  r  r  s     r   CONVERT_VALUEz'InstructionTranslatorBase.CONVERT_VALUE  s;    88 !KLL		$%%dhhj$((;<r   c                P    | j                  t        j                  | d      d       y )Nr   r   )r  rg   rx  r  s     r   FORMAT_SIMPLEz'InstructionTranslatorBase.FORMAT_SIMPLE  s    ?00r:A>r   c                D    | j                  | j                         d       y r   )r  r  r  s     r   FORMAT_WITH_SPECz*InstructionTranslatorBase.FORMAT_WITH_SPEC  s    488:q)r   c                l    | j                          t        j                  dk\  r| j                          y y )Nr  )r  rZ  r  r  s     r   POP_ITERz"InstructionTranslatorBase.POP_ITER  s'    
w&HHJ 'r   )	__enter____exit__
__aenter__	__aexit__c                z   t        |j                  t              st        d      | j                  |j                     }|dv r| j                         }t        |t        t        f      s| j                  |       t        |t        t        f      st        d      |dk(  r,| j                  t        |             | j                  |       y | j                  t        |d              | j                  |       y | j                  |       | j                         }| j                  |       | j                  |       y )Nz*expected LOAD_SPECIAL arg to be set to int)r  r  rq  r  )rV  rA  r   r   _load_special_namesr  rn   ro   ro  rF  rp   r  rq   r  )r   r   rX  rv  r=  s        r   LOAD_SPECIALz&InstructionTranslatorBase.LOAD_SPECIAL  s
   $((C( !MNN''1,,((*C-/MN 005 -/MN %v  {"		3C89t$ 		23=>t$ OOD!((*CIIcNNN4 r   c                b    | j                  t        j                  | |j                               y r   )rF  rg   rx  rw  r  s     r   LOAD_SMALL_INTz(InstructionTranslatorBase.LOAD_SMALL_INT  s    		/''dkk:;r   r   r  c                    t        |j                  t              st        d      | j	                  t        j                  | | j                  |j                                  y )Nz2expected LOAD_COMMON_CONSTANT arg to be set to int)rV  rA  r   r   rF  rg   rx  _common_constantsr  s     r   LOAD_COMMON_CONSTANTz.InstructionTranslatorBase.LOAD_COMMON_CONSTANT"  sD    $((C( !UVV		/''d.D.DTXX.NOPr   c                P    | j                   j                         dkD  r	d | _        yy)Nr   c                      yNTr   r   r   r   r   z>InstructionTranslatorBase.is_non_empty_graph.<locals>.<lambda>*  rv  r   TF)r(  count_callsr  r   s    r   r  z,InstructionTranslatorBase.is_non_empty_graph'  s%    ;;""$q(&2D#r   c           
         |g }dj                  t        j                  | j                         gt	        t        |            z               S )Nr   )r  	tracebackformat_listr  r   r   )r   additional_stack_framess     r   format_frame_summaryz.InstructionTranslatorBase.format_frame_summary.  sN     #*&(#ww!!##%&h7N.O)PP
 	
r   c           	     4   | j                   j                  }i }t        j                  dk\  r ||j                  |d<   |j
                  |d<   t        j                  t        | j                  dd      | j                  t        | j                  dd      fddi|S )	Nr6  colno	end_colnor  	<unknown>r  lookup_lineF)r  r  rZ  r  r:  r;  r  FrameSummaryr  r  r   )r   r  r  s      r   r  z'InstructionTranslatorBase.frame_summary9  s    ,,66	!#w&9+@'22F7O"+":":F;%%DKK<KKDKKK8
 	

 
 	
r   c                    t        | j                  dd      }t        j                  d      }|j	                  |      d uS )Nr  r  z.*torch/nn/modules.*)r  r  recompilematch)r   r   nn_modules_patterns      r   is_co_filename_from_nn_modulesz8InstructionTranslatorBase.is_co_filename_from_nn_modulesH  s:    4;;{CZZ(?@!''1==r   c                    | j                   j                  |t        j                  |            }t	        t        |      j                  t        j                               |S r   )	r(  install_global_by_idr  r  rB   rS   r  rA   WEAKREF_ALIVE)r   r  r  global_names       r   store_global_weakref_by_idz4InstructionTranslatorBase.store_global_weakref_by_idM  sJ    kk66vw{{5?QR,778R8RS	
 r   c                B    | j                   j                  j                  S r   )r(  tracing_context	fake_moder   s    r   r  z#InstructionTranslatorBase.fake_modeT  s    {{**444r   c              #  b   K   | j                   }|| _         	 d || _         y# || _         w xY ww)zx
        Strict mode is enabled on a per-VariableTracker level depending on the return value of check_fn(node).
        N)r  )r   check_fnpriors      r   strict_translation_modez1InstructionTranslatorBase.strict_translation_modeX  s3      %% (	*$)D!ED!s   /# /	,/c                *   | j                   t        d      | j                   dkD  st        d      | j                  j                  | j                  j
                  | j                  | j                   dz
  | j                  | j                   dz
           S )Nr  r   0expected self.instruction_pointer > 0 to be truer   )r   r   r$  r   r  r  r   rv  r   s    r   r)  z#InstructionTranslatorBase.speculatef  s    ##+ J  ((1, !STT##((KK##KK$$q(d66:;	
 	
r   c                     ||dk  r||fS ||fS r   r   )r   r   r   fallback_linenos       r   _make_frame_locz)InstructionTranslatorBase._make_frame_loct  s%     >VaZo..&!!r   c                d   g }t         j                  rs| j                  }|e| j                  |j                  j
                  |j                  |j                  j                        }|j                  |       |j                  }|e|j                          |j                  |       t        |      S r   )r   r  r  r  r  r  r   r  r   reverser6  )r   	frame_locframe_loc_chain_list
current_txparent_frame_locs        r   _get_frame_loc_chainz.InstructionTranslatorBase._get_frame_loc_chain{  s     79%%;?;;J(#'#7#7%%11%%%%44$ 
 %++,<='..
 ( 	$$&##I.)**r   c                   t               }g }| j                  D ]Z  }|j                  }|||v r|j                  |       |j	                  d|d|j                         j                                 \ |syddj                  |      z   S )zLFormat bytecode source locations for stack values involved in a graph break.z  z originated from:
r   z#Stack variable source attribution:
r   )r  r  r<  r  r   r  r  r  )r   seenpartsvtr<  s        r    _format_stack_source_attributionz:InstructionTranslatorBase._format_stack_source_attribution  s    $'E** 		B 00O&$&HH_%LLRF-o.D.D.F.M.M.O-PQ		 5		%8HHHr   c                6   |j                   ry t        |dd       }|(t        j                  j                  j                         }	 t        j                  rR| j                  F| j                  | j                  j                  | j                  | j                  j                        }n-| j                  |d   j                  |d   j                  d      }| j!                  |      }d}t        j"                  r/t%               }dj'                  t)        j*                  |            }nt%               |z   }t-        |      }dj'                  t)        j*                  |            }	|t/        ||      }| j1                         }
d|d    d|d	    d
| g}|
r|j3                  d|
g       |j3                  ddg       dj'                  |      dz   t        j"                  r| d|	 dz  nt5        |	      z  t        j6                  j9                  dd fd       t;        |t<              r|j>                  n
tA        |      }tB        jE                  tF        jH                        rptJ        sjtM        jN                  ||f      rSt        j"                  r&dz  dj'                  | jP                        dz   z  tB        jS                         d|_         y tB        jS                  d|d   |d	   |       d|_         y # t        $ r |d   |d   f}Y Aw xY w)Nr'  r  r   r  r  r   zGraph break in user code at r   r   zGraph Break Reason: zUser code traceback:r   zQ
========== most recent `torch.compile` tracing attempt started here ==========

a}  
NOTE: the most recent `torch.compile` tracing attempt might not be where you applied `torch.compile`! This is due to how graph breaks are implemented - the optimized code object returned by Dynamo will call another Dynamo-generated resume function and tracing is re-enabled by calling the resume function as a normal Python function, which Dynamo intercepts as a top-level frame.
artifactc                     dddS )Ndynamo_graph_break_reasonstring)r   encodingr   r   r   r   r   z;InstructionTranslatorBase.log_graph_break.<locals>.<lambda>  s    3$! r   c                 6      dt        j                          S )Nr   )r  
format_exc)user_stack_traces   r   r   z;InstructionTranslatorBase.log_graph_break.<locals>.<lambda>  s    "2!32i6J6J6L5MN r   )metadata_fn
payload_fnz4
Most recent bytecode instructions traced (max 20):
zmGraph break (user stack suppressed due to duplicate graph break) in user code at %s:%s
Graph Break Reason: %sT)*loggedr  r  r  r   r  r   r  r  r  r  r  r   r  r   
IndexErrorr  r  r9   r  r  r  r7   r5   r  r  r   _loggingtrace_structuredrV  r>   r  r]  graph_break_logisEnabledForr   DEBUGexplainr_   r  r  r  )r   r  r   r   
user_stackr  frame_loc_chainstack_above_dynamo_formattedstack_above_dynamouser_stack_formattedstack_source_attributionuser_stack_trace_partsr  r  s                @r   r  z)InstructionTranslatorBase.log_graph_break  s    ::S,5
55CCEJ	))dkk.E 00KK++KKKK..	 !00rN++rN))	 33I>')$>>!7!9+-77%%&89,( 01J>J/
;J!wwy'<'<Z'HI ?6sFCF#'#H#H#J *9Q<.)A,H"6(+"
 $"))2/G*HI%%r+A&BC99%;<tC>>/0 1e'( )LL $8 99'' O 	( 	
 ",C!=#++49((7/33Wo4NO
 ~~ L  !DIId.H.H$ID$PP !!  
 !! A!!	 
k  	 ]+-.I	s   BL LLc                ^    t        ddt        |        dg t        j                  |d       y )Nzgraph break in loopzframe skipped: ztorch.compile detected a graph break in a for/while loop. Skipping the frame and falling back to eager, as graph breaks in loops are not supported.T)r  r  r  r  r$  r%  )r=   r8   r   r-  )r  r   s     r   r  z0InstructionTranslatorBase.raise_loop_graph_break  s;     	)%&7&=%>?hD%CCD	
r   c                h   t         |           || _        || _        || _        || _        || _        |	| _        |
| _        d | _	        g | _
        d| _        d | _        t        d      | _        d| _        g | _        g | _        d| _        d| _        d | _        d| _        g | _        || _        t1        d      | _        d| _        t7               | _        t;        d       | _        i | _        || _         ||ntC        | j@                        | _"        || _#        || _$        || _%        || _&        || _'        || _(        |$tR        jT                  rtW        |||      | _,        nd | _,        i | _-        i | _.        || _/        d	| _0        d	| _1        d	| _2        d | _3        d | _4        d| _5        d | _6        d	| _7        g | _8        || _9        d
dl:m;}m<}m=}m>} ||z  |z  }t~        j                  dk  r||z  }|j                  |z  r| j                  t        d              || _D        d	| _E        d gt        |j                        z  | _H        t        j                  t        j                        | _M        t        j                  t        j                        | _O        t        j                  |j                  |       y )Nr   r  Tr     )maxlenc                 ,    t        j                  d      S r   )r  r  r   r   r   r   z4InstructionTranslatorBase.__init__.<locals>.<lambda>Z  s    	 2 r   )r  r  r  Fr   )CO_ASYNC_GENERATORCO_COROUTINECO_GENERATORCO_ITERABLE_COROUTINEr6  )SrU  rV  r$  distributed_stater(  r  r  r  r  r  r  r   r  r(   r  r(  r
  r*  r  r   rD  r  r  r  r   r  r  r  r}  r   r  r  rv  r   r  rG  rz  r|  r  r  r  r   replay_record_enabledrL   r  nn_module_stack	num_callsexportr+  r   r  r  r  r  r  r  r  r  resume_executionr  r  r  r  rZ  r  co_flagsrF  rk   r  r  r   rZ  rv  r  r  r   r  r  r  r  r  	lazycacher  )r   r(  rv  rG  rz  r|  r  r  r  r  r  r  r  r  r$  r  r  r  r  r  r  r  r  r  
push_typesr\  s                            r   rV  z"InstructionTranslatorBase.__init__"  s   0 	.!2 . 0-J*%:" -1),.
#$ #5e#< (,%UW,67."&(%*"%5"$%!47E' 23 	$ 57! 0<*GD<M<M0N 	  	 *3*4)5&, 6#?#?!2)"D "&D BD)+ $)!*/'#'  $$(!&+#	
 	
 "$99<NN
g%,&J??j)IIod+,().&P
  !P"
 ++GMM: 	* 9I8U8UMM9
( 	F..	:r   r   r  )r   ztuple[str, ...])r  r   r   r   )r  r   r   r   )rR  rg   r   r  r  r  r   r   )rR  rt   r   r  r  r  r   rg   F)
rR  rt   r   r  r  r  r  r   r   r   r   )r   r  r   r   r  )r   r   r   r   r   r.   r   r   )r   r.   )r  r.   r   r   r   r   )ri  rg   r   r   )r?  r  r   r   r   rg   )r  r   r   r  )rY  r   r   r   )r   r.   r   rg   )r  r   r   rR   )r   r   r  r   r  r   r   r   )rw  r   r   rg   )r   zInstruction | BlockStackEntryr   r   )ri  rg   r   rg   )r   r   r   r   )ri  rg   rj  r   r   r   )ri  rg   r   zTypeIs[ExceptionVals])r  r   r   r   )rX  r   r   r   )r=  rg   r   r   r   r   )r   r.   r  r   r   r  )r  r   r  r.   r  rF   r  list[types.CodeType]r  r3   r  r   r  r   r   ztuple[types.CodeType, str]r   r.   r  zlist[StackLocalsMetadata]r   r  )r  r  r  r   r  r3   r   r   )r=  rg   r  rg   r   r   )r   r.   r  r]  r   r   )r  rg   r  r   r   rg   )r  rg   r  r   r   r   )r   r.   r]  r   r   r   )rv  z8ContextWrappingVariable | GenericContextWrappingVariabler   r.   r   rg   )rv  rg   r   r   )r  zlist[Any] | Noner   r   )r   ztraceback.FrameSummary)r  r   r  r   r   r   r   zFakeTensorMode | None)r  z!Callable[[VariableTracker], bool]r   r   )r   r   )r   r   r   r  r  r   r   tuple[str, int])r  r  r   ztuple[tuple[str, int], ...])r  rC   r   r   r   z)Unsupported | UserError | StepUnsupportedr   r   )r  types.CodeTyper   zUnsupported | UserErrorr   r   )NNN)(r(  rE   rv  r  rG  r   rz  r   r|  r   r  rC   r  r  r  r  r  r   r  r   r  r  r  r   r  r   r$  r   r  ra  r  DistributedState | Noner  ztuple[types.CellType] | Noner  r  r  zdict[Instruction, int] | Noner   r   ($  r   r   r   r   r  r  r  r  r  r  r  r  r  rG  r  r  r  r  r  r  rZ  r  r  propertyr  r  r!  r7  rF  r@  r  rH  rL  rR  rV  rZ  rX  rs  LOAD_CLOSURErw  rs  r  rP  cached_propertyr  r  r  r   r  r  r  r  EAGER_IMPORT_NAMEr  r  r~  r  JUMP_FORWARDJUMP_ABSOLUTEr  rt  not_r  ru  r  JUMP_IF_FALSE_OR_POPJUMP_IF_TRUE_OR_POPr  r  r  r  r  r  r  r  r  rh  r	  r  r  r  r  r)  r+  r3  r5  r7  rL  r9  r>  r@  rG  rL  rQ  rS  rO  rV  r  rZ  r]  ra  r_  staticmethodrh  r  rC  r  r  r  r  r  r  r  r  r  r	  r  r   r  r  BUILD_TUPLE_UNPACK_WITH_CALLr  r  BUILD_MAP_UNPACK_WITH_CALLr  r  r  r  r  r  r  r  r  r  r  r
  r  r  r  r  r  r  r!  r)  r-  r2  r  r5  r8  r:  DICT_UPDATEr<  r>  r@  rC  rG  rI  rL  rO  rS  posr  negUNARY_NEGATIVEr/  invertUNARY_INVERTpowBINARY_POWERmulBINARY_MULTIPLYmatmulBINARY_MATRIX_MULTIPLYfloordivBINARY_FLOOR_DIVIDEtruedivBINARY_TRUE_DIVIDEr\  BINARY_MODULOBINARY_REMAINDERr  
BINARY_ADDsubBINARY_SUBTRACTgetitemBINARY_SUBSCRlshiftBINARY_LSHIFTrshiftBINARY_RSHIFTand_
BINARY_ANDor_	BINARY_ORxor
BINARY_XORipowINPLACE_POWERimulINPLACE_MULTIPLYimatmulINPLACE_MATRIX_MULTIPLY	ifloordivINPLACE_FLOOR_DIVIDEitruedivINPLACE_TRUE_DIVIDEimodINPLACE_MODULOINPLACE_REMAINDERiaddINPLACE_ADDisubINPLACE_SUBTRACTilshiftINPLACE_LSHIFTirshiftINPLACE_RSHIFTiandINPLACE_ANDixorINPLACE_XORior
INPLACE_ORrR  rV  r;  r<  r  r_  r:  rc  re  r   JUMP_BACKWARD_NO_INTERRUPTPOP_JUMP_FORWARD_IF_TRUEPOP_JUMP_BACKWARD_IF_TRUEPOP_JUMP_FORWARD_IF_FALSEPOP_JUMP_BACKWARD_IF_FALSErg  ri  rm  ro  r  rQ  ru  rx  r{  r  r  r  r  r  r  r  r  r  r  r  r  r  LOAD_FAST_BORROWr  r  r  r  r  r   r  r6  r  r  r   r  r  r  r  r  r  r  r  r  
contextlibcontextmanagerr  r)  r  r  r  r  r  rV  r^  r_  s   @r   r   r   C  sQ    //00#==.."CC  ##$$""&&K%%####00  ++>>,, ! EE""%%.$L00B1'

88 $8 +	8
 
884$4 $4 +	4
 
4$ +0$ $ +	
 $( 
*n	Wrh 7"-	+b	 ; ;IV2M=^0 ;!+F
V	2')
V/  L
*J, J J!E( # #2
2:;| $% 4 4.>4 LM$X]]E:#HNNE:'t<&x~~t<UU(U
#J
(8
"8
158
	8
t(T"C..,)\D'L<:$0RhL  uP	P
T  )	)
  @;	@;D  A
-
-"G "

%   A
	

8 &)	 @}%}% !}% "	}%
 +}% }% }% "}% 
$}%~#
Jh%h% $=h% 
	h%T J?*J?:CJ?IRJ?	J? J?X
(  ~=	=84"4)84	4((16
 @L @ 8 $6 2
* "2
&9.15n :  N

4

N,3 
DG	!1

%41 K@

V V$CD hll+Nhll+N'IHOO,LHLL)Lx||,O%hoo6"8#4#45!("2"23X\\*M-(,,'Jx||,O.u x "M X__-MX__-M(--(J&I(,,'JX]]+M.&x'7'78#H$6$67"8#4#45hmm,N /8==)K.h../Nh../N8==)K8==)K(,,'J	X 7"	;
@"7!r  i	)
V
 M!%+HNNEB ,X^^U C ,X]]E B!-hmmU!C(&E& & 
	&P 
 
 -$'
*&&/;)02  A
'
'.`=
?* !I!@< 	

Q
 ;?	
'7	
		

>
 5 5 *9*	* *
""%/"BE"	"+(+	$+(I&p!p p 7	p
 
pd 

#:
	
 
@ 15)-15-M;M; (M; !	M;
 "M; #M; "M; 4M; 5M; (BM;  3M; M; M; M; (M;  %!M;" 3#M;& .'M;( ')M;, /-M;. 
/M; M;r   )	metaclassc                       e Zd Zedd       Zej                  dd       Z	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d fdZddZ	ddZ
ddZddZddZdd	Zdd
Z xZS )rL  c                 "    t         j                  S r   )tlsr  r   r   r   r  z InstructionTranslator.current_tx  s    ~~r   c              #     K   t        t        dd       }| t        _        	 d  ||t        _        y t        t        d      rt        `y y # ||t        _        w t        t        d      rt        `w w xY ww)Nr  )r  rm  r  r5  )r   r  s     r   set_current_txz$InstructionTranslator.set_current_tx  sh     \40	# !&l+N ,  !&l+N ,s   A4A
 &A4
'A11A4c                    t               t        j                  d|j                   d|d    d|d           t        !|   t        ||	| ||||||||
|      ||||||i i d d ||d||||       | j                          t        | j                  j                        5  | j                         5  |
| _        || _        | j                  r| j                  st        d	      i | _        t!        | j#                               }d }d }|j$                  |j&                  z   }|j(                  t*        z  r|j,                  |   }|d
z  }|j(                  t.        z  r|j,                  |   }t1        j2                  |      j5                  dd       }|j7                         D ]r  \  }}||vsd }|r)t9        |j5                  |i       j7                               }t;        j<                  |t?        |d|||k(  ||k(        |       }|| j                  |<   t | j                  j@                  }| jC                         D ]z  }||v rN||   }t?        |dd      }t;        j<                  |||       }|jE                         }|jG                  ||       n|jE                         }||_$        || j                  |<   | |t        d      tK        | jM                         |      D ]i  \  }}tO        |      } t?        |d      }	 t;        j<                  |jP                  ||       }|jY                  | ||      }||_$        || j                  |<   k t[        |d      | _.        t_               | _0        |r.tT        j:                  jc                  | j                        | _        d d d        d d d        y # tR        $ r tU        jV                         }Y w xY w# 1 sw Y   5xY w# 1 sw Y   y xY w)Nztorchdynamo start tracing r  r  r   r  )local_scoper  r  torch_function_mode_stackr+  r  r   )r(  rv  rG  rz  r|  r  r  r  r  r  r  r  r  r  r$  r  r  r  z4Export without one graph - something has gone wrong.r   dynamismT)is_inputrs  
is_varargsis_varkwr  )rt  is_derefed_cell_contentsz'expected closure is not None to be true)rw  F)	skip_next)2r"  r   INFOr  rU  rV  rE   _throw_if_in_functorchr   r(  r  ro  r+  r  r   r  r  r  co_argcountco_kwonlyargcountr  ru   co_varnamesrv   r2   r  r  r  	frozensetr~   ry  rU   r+  r  rt  rq  rr  rI  r  rT   cell_contentsr  r   DeletedVariabletrack_cell_existingr   r  r   r  realize_all)"r   rv  r  rG  rz  r|  r  rr  r  compiler_fnr+  r  export_constraintsframe_stater$  r  r  r  r  varargs_name
varkw_name_vararg_idxrs  r   r  local_dynamismrY  r+  contents_sourcerQ  cell_varrP  cell_sourcer\  s"                                    r   rV  zInstructionTranslator.__init__  s5   ( 	LL((8,}:U9VVWXdeuXvWwx	
 	"$&*C# &!%*."&+%/A 	 !	
F 	##% T[[001 w	43F3F3H w	#,DN DK{{~~(N  $&D *-d.D.D.F*G (,L%)J ,,v/G/GGK+%11+>q /#//<
#//7;;JMH'~~/ 5e00%)N)28<<b3I3O3O3Q)R-44# %)%3(,(<&*j&8  
C 25D((.!5(  ;;33L %68#$TNE* '2!%15'O
 5H4N4N45L  ,::<H ++HlC+::<H&*#-5$$T*K%6R $%NOO!$--/7; 6
d-d3"-dT"R?#6#=#=**O$L (;;| '+#-5$$T*6  2L)2D.
 *=)>D& (1'D'D'P'P((($kw	 w	 w	D " ?#,#<#<#>L?Ew	 w	 w	 w	sQ   O0C7O(EO;"N*A<OO*O
	O	O
	
OO	OO"c                   t         j                  j                  d      }t        j                  | j
                  j                  d| j
                  j                        }t         j                  j                  j                         }t         j                  j                  j                  j                  t         j                  j                  j                  j                  t         j                  j                  j                  j                  f}|\|j                         |v rI||urD|j                         j                  j!                         }d| d| d| d}t#        dd|g 	       y y y y )
Neagerr  zhIf you are reaching here, it means dynamo failed for one of the following reasons:
- Calling torch.func.zP(compiled_fn) function from eager mode is not supported. Ensure that torch.func.zp is also wrapped within a torch.compile function. For more information, see PyTorch issue #128711.
- torch.func.z2(fn) requires the function to be inlined by dynamoz%Unsupported functorch tracing attemptr   r  )r  _dynamolookup_backendrM  getattr_staticr(  r  _C
_functorchpeek_interpreter_stackTransformTypeVmapGradJvpr  r   lowerr=   )r   r  r  ciforbidden_keysr   r`  s          r   rz  z,InstructionTranslator._throw_if_in_functorch{  s0   ,,W5,,KK##]DKK4K4K
 XX  779HH--22HH--22HH--11
 >bffh.8[PU=U668==&&(D((,v .**. 0  !%v%WY  ?	 >V8>r   c                    t        |t              r| j                  |j                     S t        |t              r| j
                  |j                     S t        r   )rV  rU   rG  rr  rR   rz  r  rJ  )r   r  s     r   get_example_valuez'InstructionTranslator.get_example_value  sE    fk*==!2!233fl+>>&"4"455r   c                    | j                   j                         D ]G  }t        |t              st	        |j                         t        j                  j                        sG y y)NTF)	r  r  rV  r   r.  r  r  nnModule)r   r  s     r   $symbolic_locals_contain_module_classz:InstructionTranslator.symbolic_locals_contain_module_class  sR    %%,,. 	A!56:$$&< 		
 r   c                    t        | j                        rP| j                  d   x}r>t        |t              r-t	        t        | |      t                     | j                  d<   y y y y )Nr  r  )r   r  rV  rx   r   rc   rf   )r   r  s     r   "replace_tos_if_return_is_generatorz8InstructionTranslator.replace_tos_if_return_is_generator  s\    

O

2&&3 <=1c*.0DJJrN > ' r   c                   | j                          | j                  t        d      | j                  t        d      t	               j                  d| j                  | j                  z
         t        j                  s| j                  j                         dk(  rw| j                  sk| j                         s[| j                  sO| j                  sC| j                  s7| j                  s+t!        j"                  dt%        | j&                               d | _         t)               t*        j,                  d| j&                  j.                   d|j0                   d       t2        j5                  d	       | j                  j7                  | t9        d
| j;                         gd      |j0                  dk(  rdnd      }t=        |      dk7  rt        d      |d   j>                  rt        d      | j                  jA                  | jC                  ||d   jD                        t        jF                  rd| jI                  d       g       tJ        d        tJ        )Nr  r  r  r   zhNo ops traced for the FX graph. `torch.compile` will skip the frame and fall back to eager.
Frame info: ztorchdynamo done tracing r   r  zreturn triggered compilereturn_valueF)r&  r  r   r  z7expected len(all_stack_locals_metadata) == 1 to be truezEexpected not all_stack_locals_metadata[0].stack_null_idxes to be truez__ret = r  )&r  r   r   r  r^   r  r   allow_empty_graphsr(  r  r  r  r  r+  r   r  r   	SkipFramer8   r  r"  r   ry  r  r   r!  r  r  rD   r  r   r}  r  rh  r  generate_pycoder  rA  )r   r   r  s      r   _returnzInstructionTranslator._return  s1   //1##+ J  # !STT''0043C3CC	

 ))'')Q.22==?KKNN--33--0=>@ 
 $( LL'(;(;'<Bt{{m1M	
 			,-$(KK$@$@%!3!3!5 6E !KK>9qq %A %
! ()Q. I  %Q'88 W  	++))$0I!0L0V0VW%% 44W=>?@	
  		
 r   c                &    | j                  |       y r   r  r  s     r   r  z"InstructionTranslator.RETURN_VALUE      Tr   c                &    | j                  |       y r   r  r  s     r   r  z"InstructionTranslator.RETURN_CONST  r  r   )r   rL  r  )$rv  r  r  r  rG  r   rz  r   r|  r   r  ztuple[Any, ...] | Nonerr  r   r  rC   r  r   r+  r   r  r   r  r   r  r   r$  r   r  ra  r  r  r  r  r   r   r   )r  rW   r   r   r  r  )r   r   r   r#  r  rh  ri  ro  rV  rz  r  r  r  r  r  r  r^  r_  s   @r   rL  rL    s     	# 	#v'v v !	v
 "v #v (v $'v "v v v v  v v (v  %!v" 3#v$ '%v& 
'vp>	9vr   rL  r6  INPLACEr  BINARY_c              #  d  K   t         j                  sd y| j                  t               | _        | j                  j	                         }| j                  j                         }| j                  j                  |j                  |j                  |j                  t        j                                d}	 d d}| j                  j                         }t        j                         }|r| |       }||j                  z
  }	|	|j                  z
  }
t        |j                   |j"                  |j$                  |	|
t'        |j(                        ||r|d   nd|r|d   nd|r|d   nd|j*                  |      }| j                  j-                  |       | j                  j/                  |	       yyy# | j                  j                         }t        j                         }|r| |       }||j                  z
  }	|	|j                  z
  }
t        |j                   |j"                  |j$                  |	|
t'        |j(                        ||r|d   nd|r|d   nd|r|d   nd|j*                  |      }| j                  j-                  |       | j                  j/                  |	       w w w xY ww)a[  
    Context manager for profiling inline calls.

    Args:
        output: The OutputGraph containing profiler_state
        code: The code object being inlined (for timing metadata)
        get_inline_depth: Callable that returns inline_depth (called after work completes)

    Yields:
        None (profiling happens around the with block)
    NFTr   r   r  )	func_namer   firstlineno
cumtime_ns
tottime_nsbytecode_countr  caller_func_namecaller_filenamecaller_firstlinenois_primitive_call
call_stack)r   dynamo_profilerprofiler_stater   get_current_callerget_call_stackrF  r  r  r  timetime_nsr  start_time_nschild_time_nsr   r  r   r  r   co_coder  record_timingadd_child_time)r(  r  get_inline_depthcaller_infor  trace_successstack_entrytrace_end_nsr  r  r  timings               r   profile_inline_callr     sn    " !!$ 3 5''::<K&&557J
d&&(;(;T\\^ M=++//1||~[4+-L%(A(AAJ#k&?&??J(%//$--'33%%"4<<0)3>QD2=A45@;q>d"-"?"?%F !!//7!!00<) 5= ++//1||~[4+-L%(A(AAJ#k&?&??J(%//$--'33%%"4<<0)3>QD2=A45@;q>d"-"?"?%F !!//7!!00<) 5=s    B5J08F5 >C7J05C8J--J0c                  X    e Zd ZU dZded<   ded<   e	 d	 	 	 	 	 	 	 	 	 	 	 dd       Ze	 	 	 	 dd       Ze	 d	 	 	 	 	 	 	 	 	 	 	 dd       Z	dd	Z
	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d fd
Zedd       ZddZddZd fdZ	 	 	 	 	 	 d fdZddZddZ	 	 	 	 d dZd fdZd fdZ xZS )!r  z Trace and inline a called methodr<  symbolic_resultr   r  c                    d }t        j                  |j                         fd      5  | j                  ||||      }|j	                         cd d d        S # 1 sw Y   y xY w)Nc                 "     j                   dz   S r  r  )r  s   r   r   z;InliningInstructionTranslator.inline_call.<locals>.<lambda>P  s    F4G4G!4K r   r  )r  r(  r  build_inline_tracerinline_call_)r  r  funcr   r  r  tracers    `     r   r  z)InliningInstructionTranslator.inline_callE  sm      MM4==?,K
 
	) ,,*C - F &&(
	) 
	) 
	)s   &AA%c                   | j                         rt        dt        |       dg        t        | t              rt        j                  | j                         dd      rat        j                  | j                         dd       }t        dt        | j                               d| j                          d	| d
dg       t        j                  | d      }|j                  rddlm} t        | d      rDt        | j                  d      r.| j                  j                  |u rt        j                   dd      S t        | d      r| j                  j"                  nd}d| dg}d| j%                         vr|d| ddgz  }t        dd| d| j'                          d| j%                          d|j(                   d| d |       |S )!NzInline attempt with __self__zAttempted to inline a function with the `__self__` attribute. Dynamo is expected to decompose method calls into function calls with a `self` argument.r  _torchdynamo_disableF_torchdynamo_disable_msgz2Skip inlining `torch.compiler.disable()`d functionzSkip inlining function z= since it was wrapped with `torch.compiler.disable` (reason: r  z(Remove the `torch.compiler.disable` callT)is_inlined_callr   )!produce_trampoline_autograd_applyrR  _originz"allowlist in dynamo known functionr   zAvoid calling the function `rQ  r  z:Apply `@torch._dynamo.dont_skip_tracing` to the function `zw` to force tracing into the function. More graph breaks may occur as a result of attempting to trace into the function.z Please file an issue to PyTorch.z.Attempted to inline function marked as skippedz
qualname: z, name: z, filename: `z`, skip reason: z?Dynamo developers have intentionally marked that the function `z` should not be traced.)has_selfr=   r   rV  r{   rM  r  get_functionr   check_verboseskippedtorch._dynamo.variables.miscr  r5  rR  r  
SkipResultr   get_filenameget_namer   )r  r`  r  r  fn_qualnamer  s         r   check_inlineablez.InliningInstructionTranslator.check_inlineable[  s    ==?6D	k d01g6L6L!77
 ((!!#%?C LD--/05d6G6G6I5J K::=aA ? **4F>>V
 d#DGGY/GGOO'HH #--?  3:$2E$''..2K.{m2>E  1 1 33PQ\P] ^h h 7	  H$[M$--/9J K"//122B6==/S]^i]j k( ( r   c                
    t        |t        t        t        f      st	        d      |j                         d } j                  j                  }t        j                  s"|r |j                  j                  d       x}r|}|Ot        j                  |      }|j                  durt	        d      t        j                  s|r||j                  <   d }	 |j                   ||      }|t	        d      t1        j2                  |j5                               D ]8  }t        |t6              rt#        dd| d| dg t,        j8                         : j:                  dv r\|r-t        |d   t<        j>                  t<        j@                  f      s-t#        ddj:                   d| dj:                   dg        d}tB        jD                  jF                  jH                  jK                  d      r&dtM        jN                        jM                          }tP        jR                  dk\  r@ jT                   jV                  d% fd}tX        j[                  dt]        |             t^        j[                  d ||j`                         |r|d   }d!}t        |tb              rU|je                         sEtg        |ji                         tB        jj                  jl                        r|jo                         }nd}|rt        |tp              r j                  js                  |jt                        }t        |tB        jv                  jx                        rt{        j|                  |      t        j                  |j                  j                        d"<   nt        |t              ro|j                  }t        |tB        jv                  jx                        r?t{        j|                  |      t        j                  |j                  j                        d"<   t        |t              rt	        d#      t              r3t         | j                   j                   j                  ||$      }|S t         | j                   j                   j                  ||$      }|S # t         $ r}	t#        dd|j%                          d|j'                          d|j                         j(                   d|D 
cg c]  }
|
j+                          nc c}
w c}
 d	| 
d
|j%                          dg t,        j.                  |	       Y d }	~	ad }	~	ww xY w)&Nz~expected isinstance( func, ( UserFunctionVariable, NestedUserFunctionVariable, LocalGeneratorFunctionVariable, ), ) to be trueFz+expected result.skipped is False to be truez2failed to bind arguments when attempting to inlinezfunc='z' r   z	; args = z; kwargs = z4Argument mismatch when attempting to trace function rU  r#  z*expected sub_locals is not None to be truez:Encountered unconverted argument when attempting to inlinezfunc: z, arg: zWAn argument to an inlined function was not successfully converted to a VariableTracker.r  )r  r  r  __delattr__r   zJUnsupported __setitem__/__setattr__/__delitem__/__delattr__ inline attemptzcode name: z, args: zAttempted to inline z: where first argument (self) is not a user-defined object.r   bytecoder   r6  c                     j                  j                  j                        } t              j	                         }dj
                   d|  d| S )N)r   zTRACE inlined call z from r   )r  r  r   r]   r  r  )headerr  r  cur_instr  parent_codes     r   get_trace_call_log_strzQInliningInstructionTranslator.build_inline_tracer.<locals>.get_trace_call_log_str  s[    77#--44 8  2+xHOOQ,T\\N&4&QQr   r  zINLINING %s%s, %sTrt  z>expected not isinstance(func, SkipFunctionVariable) to be truer  r  )KrV  r{   ry   rw   r   r  r(  r  r   dont_skip_tracingpreviously_inlined_functionsr  r  r  r  	bind_argsr  r=   r  r  r  r  r   r  r  r  r  rg   r  r  r   r   r   r  r  	_internal	log_stateis_artifact_enabledri  BytecoderZ  r  r  r  trace_call_logr  ra   r!  r   r~   is_realizedr.  	peek_typer  r  r  r   r  r  r  r-  r  r  r2   r  forwardr  r   r  rz   r/   &InliningGeneratorInstructionTranslatorr  r  r  )r  r  r   r  r  r  tracing_ctxprevious_result
sub_localsr  rA  r  r  r  arg0should_checkmoduler  r  r  r  s   `                 @@@r   r  z1InliningInstructionTranslator.build_inline_tracer  s    $*.
 ! Q   $}}mm33
 ''K"-"J"J"N"Nd#   )>2CCDIF~~U*$%RSS++AG88>
	f=J  !MNN!2!2!45 	Aa1X$TF'!5 y9-889		 << 
 
 Q7766 d%dll^8D6B24<<.@z{	  >>##--AA*M#,,t,00234Fw&11H --KR R   z2H'IJ		%tVV]]C 7DL$ 34T=M=M=Odnn.@<<>D#(Ld$45#]]88IF!&%((*>*>? $KK/ %001H1HI.  &CD!ZZF!&%((*>*>? $KK/ %001H1HI. d01 P  ;''44,,*C	F*  3''44,,*C	F o  
	L  1D4E4E4G3H$--/JhJhIi j8<=3??,==>k&SRSWS`S`SbRccde&11 	 	
	s%   R' '	U0AU8T8UUc                   | j                   }d|_        d|_        | j                  }t	        j
                         }|j                  r| j                  |j                        }	 |5  | j                          d d d        | j"                  |_        d|_        | j$                  j&                  rt)        j*                  d       S | j,                  t/        d      | j0                  |j0                  u r%|j2                  j5                  | j2                         |xj6                  | j6                  z  c_        t        j                  d|       | j$                  j8                  j:                  j=                  |       t>        j@                  stC        | tD              r| jF                  rtI        |      r}tC        | tD              rm| jJ                  ratC        | tD              st/        d      g }| j,                  jM                         s| j,                  g}t        jN                  tP        | |	       y | j,                  S tI        |      r_tC        | tD              st/        d      | j,                  jM                         st/        d
      tS        | jT                  tW                     S | j,                  S # 1 sw Y   ;xY w# t        j                  $ r#}d| d| }t        j                  |        d }~wt        t        f$ r}d|_         d }~wt         $ r t        j                  d|        w xY w# | j"                  |_        d|_        w xY w)NFTz!Observed exception DURING INLING z : zFAILED INLINING %sz4expected self.symbolic_result is not None to be truezDONE INLINING %szLexpected isinstance(self, InliningGeneratorInstructionTranslator) to be truer  z;expected self.symbolic_result.is_constant_none() to be truer  ),r  r  r  r  rh  nullcontextr  r  r7  r   r   r!  r  r>   r?   r%  r  r   r(  r)  rm   ry  r  r   rz  r  r  r  r  traced_coder   r   r  rV  r  is_generator_from_ctx_managerr/   generator_exhaustedrs  r  r  r   generated_itemsrf   )r   r  r  
strict_ctxr  r`  r   s          r   r  z*InliningInstructionTranslator.inline_call_A  s   &+#(,%{{$002
""55f6M6MNJ	2 
& +/*C*CF',1F);;""#**400' !WXX>>V---##**4+@+@A((D,J,JJ(		$d+##//66t<44tCD22 T"t%KL,,!$(NO(f 
 ++<<> 001D,,]DtL+++D!!$(NO(f  ++<<>(U  ,(("2"4 
 +++U $$ 	5dV3qcBCIIcNY' 	 !AL 	II*D1	 +/*C*CF',1F)sH   #J< %J/6J< /J94J< <L+K--L+?L$L++L. .Mc	                   |j                         }	|	d   }
t        |
t              s|
j                  }
|j                  j
                  }|r|j                  j                  |      nd }|%|j                  }|j                  }|j                  }not        |      }t        |       t        |      }t        t        t!               D ci c]  }|t#        ||       c}      }|rt%        |||      |j                  |<   t&        | Q  |j                  i |	|
||||||||j*                  |j,                  dz   |j.                  |j0                  |j2                  |j4                  |       || _        || _        |j:                  | _        d | _        |j>                  jA                         | _        |jB                  | _!        || _"        y c c}w )N__builtins__)rv  r  r  r   )r(  rG  rz  r|  r  r  r  r  rv  r  r  r  r  r$  r  r  r  r  )#get_globalsrV  r  __dict__r(  r  inlined_code_cacher  rv  r  r  r"   r!   r   r   rC   r-   r  r   rU  rV  r  r  r$  r  r  r  funcvarr  r
  r  r	  rE  r+  _allow_nested_graph_breaks)r   r  r  r  r  r  r  r  r  rz  r|  r  cachedrv  r  r  r  r\  s                    r   rV  z&InliningInstructionTranslator.__init__  s    '')	~.
*d+#,,J mm33=H//33D9d!..LnnG!..L/5L-!,/G=?Kaaq!11KL 7G!-#!-8..t4 	==!+-*G"7%%==,,q0"22,,$66NN% 	 	
( ))#%55::<))*C'G Ls   G
c                .    | j                   j                  S r   )r  r  r   s    r   r  z'InliningInstructionTranslator.fake_mode  s    {{$$$r   c                \    t        j                  | j                  j                               S r   )r   r   r  r  r   s    r   r!  z)InliningInstructionTranslator.run_ctx_mgr  s     ++DKK,E,E,GHHr   c                    t         j                  sy| j                  sy| j                  j	                         sy| j
                  j                         syy)zCheck if comprehension speculation is allowed in this inlined context.

        Unlike should_compile_partial_graph(), this skips the exception table entry check.
        FT)r   r  r  r   should_allow_nested_graph_breaksr  r  r   s    r   r  zAInliningInstructionTranslator._can_speculate_comprehension_nested  sE    
 ))..||<<>{{779r   c                    t         j                  rQ| j                  sy| j                  j	                         sy| j
                  j                         syt        |          S yr'  )r   r  r  r  r  r  r  rU  r   r\  s    r   r  z:InliningInstructionTranslator.should_compile_partial_graph  sO    %%22<<@@B;;;;=7799r   c                d    t         j                  rt        |   ||      S t	        dddg        y )NzGraph break in inlined functionr   z2Graph breaks in an inlined call are not supported.r  )r   r  rU  r  r=   )r   r   r  r\  s      r   r  z3InliningInstructionTranslator.create_call_resume_at  s5    
 %%707PQQ5L		
r   c                F    | j                         | _        d | _        t        r   )r  r  r   rA  r  s     r   r  z*InliningInstructionTranslator.RETURN_VALUE
  s    #xxz#' r   c                H    | j                  |      | _        d | _        t        r   )rw  r  r   rA  r  s     r   r  z*InliningInstructionTranslator.RETURN_CONST  s#    #//5#' r   c                2   d| j                   v r| j                   d   j                  d      sv| j                   d   }| j                  |      }d|v r(t        j                  j
                  j                  |   }nt        |      } t        | |      |      }t        ||      }n[| j                  j                  d| j                         }t        |      }| j                   } t        | |      |      }t        ||      }t        |      rt        |      }|||fS )Nr   namedtuple_r  ___unnamed_scope)rz  rf  r  r  r  r  r  r   ri   rP   r(  r  rR   rQ   r]  rV   )	r   r   r  r  r  fglobals_vtglobal_sourceglobals_nameglobals_sources	            r   get_globals_source_and_valuez:InliningInstructionTranslator.get_globals_source_and_value  s    'z0J0U0U1
 ..4K ..{;M+-MM22LL#  "0!< ?/$>~NK&}d;M;;;;"DNNL *,7N!^^N @/$?OK-ndCM^$ ,M:M{M99r   c                   |j                   }|| j                  vr| j                  |      S | j                  j                  | j                  u rt
        |   |       y | j                  |      \  }}}| j                  j                  j                  ||      r6| j                  | j                  j                  j                  ||             y | j                  |   }| j                  t        j                  | ||             y r   )rw  rz  r~  r(  r  rU  r  r  r+  rc  rF  rd  rg   rx  )r   r   r   r   r  r  r  r\  s          r   r  z*InliningInstructionTranslator._load_global>  s    {{t~~%$$T**;;##t~~5 G &,0,M,Md,S)A{M{{''DD[RVW		$++22<<[$OPt,		///e]KLr   c                l   | j                   j                  | j                  u rt        |   |       y | j                         }t        |t              rt        d|j                  dg        |j                  }| j                  |      \  }}}| j                   j                  j                  |||       y )Nz3Storing Tensor hook handle in globals (inline call)r  r  )r(  r  rz  rU  r  r  rV  r   r=   rw  r  r+  
store_attr)r   r   r  r   _fglobals_valuer  r   r\  s          r   r  z*InliningInstructionTranslator.STORE_GLOBALO  s    ;;##t~~5 G &HHJE%!89Q KK 8	 ;;D.2.O.OPT.U+O[!KK$$//T5Ir   r  )r  r   r  rt   r   r  r  r  r  r   r   rg   )r  rt   r   ztrace_rules.SkipResult)r  r   r  rt   r   r  r  r  r  r   r   r  r  )r  r   r  r  r  r  r  r  r  r   r  r   r  z7BaseUserFunctionVariable | LocalGeneratorObjectVariabler  r   r   r   r  r  r  r  r  )r   r   r   z#tuple[Any, VariableTracker, Source])r   r   r   r   r   r  r  r#  r  r  r  rV  r  r  r!  r  r  r  r  r  r  r  r  r^  r_  s   @r   r  r  >  s   *++%% +0)) ') $	)
 +) $() 
) )* ?&?	? ?B  +0aa&a $a +	a
 $(a 
'a aFU,@ +0AD)AD AD 4	AD
 5AD (BAD  3AD IAD $(AD 
ADF % %I	

 $=
 
	


(:(:	,(:TM"J Jr   r  c                       e Zd ZU ded<   d fdZd fdZddZddZddZddZ	d fd	Z
d fd
ZddZddZ xZS )r  r  r  c                N    t        |   |i | g | _        d| _        d| _        y r'  )rU  rV  r  r  r  )r   r   r  r\  s      r   rV  z/InliningGeneratorInstructionTranslator.__init__f  s-    $)&)!#( -2*r   c                     t         j                   j                   fd      5  t                  cd d d        S # 1 sw Y   y xY w)Nc                      j                   S r   r  r   s   r   r   zEInliningGeneratorInstructionTranslator.inline_call_.<locals>.<lambda>m  s    4CTCT r   )r  r(  r  rU  r  r  s   `r   r  z3InliningGeneratorInstructionTranslator.inline_call_l  s8     dkk;TU 	*7')	* 	* 	*s	   ?Ac                     yr'  r   r   s    r   r  zCInliningGeneratorInstructionTranslator.should_compile_partial_graphp  s    r   c                   | j                         }| j                  j                  |       t        | j                        t        kD  rt
        j                  t        j                  s| j                  r|| _
        t        y r   )r  r  r   r   r}   r   InfiniteGeneratorErrorr   r  r  r  rC  )r   r   tops      r   YIELD_VALUEz2InliningGeneratorInstructionTranslator.YIELD_VALUEt  sf    hhj##C(t##$'99,,,5511#&D 	 2r   c                    | j                   d   }t        |t              sN| j                          t	        j
                  | t              j                  | |gi       }| j                  |       y y rB  )	r  rV  r   r  rg   rx  r;  rG  rF  )r   r   r  ress       r   GET_YIELD_FROM_ITERz:InliningGeneratorInstructionTranslator.GET_YIELD_FROM_ITER  sV    jjn#34HHJ!''d3AA$rRCIIcN 5r   c                0    | j                   | _        t        r   )r  r  rA  r  s     r   r{  z7InliningGeneratorInstructionTranslator.RETURN_GENERATOR  s    #||r   c                0    d| _         t        | 	  |      S r  )r  rU  r  r   r   r\  s     r   r  z3InliningGeneratorInstructionTranslator.RETURN_VALUE      #' w#D))r   c                0    d| _         t        | 	  |      S r  )r  rU  r  r2  s     r   r  z3InliningGeneratorInstructionTranslator.RETURN_CONST  r3  r   c                   t        | j                        dk\  st        d      | j                         }| j                  d   }|j	                         st        dddg        	 |j                  |       }t        | j                  t              st        d      | j                  d	kD  st        d
      | xj                  dz  c_        | j                  |       | j                  |       y # t        t        j                  f$ rw}t        |t        j                        rt        j                  |        | j                          | j                  t!        j"                  |j$                               Y d }~y d }~ww xY w)Nr  r-  r  Unreachable sub-generator coder   @Should only be encountered while implementing generator support.r  rr  r   r  r   )r   r  r   r  rs  r=   r  rV  r   r   rF  r,  r  r   r  r  rm   ry  r  )r   r   ri  r  exs        r   
YIELD_FROMz1InliningGeneratorInstructionTranslator.YIELD_FROM  s:   DJJ1$ !KLLhhjjjn##% 8^		###D)C d66<$S  ,,q0$%WXX$$)$IIcNT"' s<<= 	9"c;;<--d3 HHJII&--bhh788	9s   #C+ +E;A-E66E;c                   t        | j                        dk\  st        d      | j                         }t        j
                  dk\  r| j                         }| j                  d   }t        |t        t        f      sgt        |t              r.t        |j                  t        j                  j                        s)t        j
                  dk\  rt        |t        t        f      r|j!                         rl	 t        j
                  dk\  rt#        | |      \  }}n|j%                  |       }t        j
                  dk\  r| j'                         | j'                  |       y t3        dddg 	       y t3        d
dt5        |       dt5        |       dg 	       y # t(        t*        j,                  t*        j.                  f$ rH t        j
                  dk  r| j                          | j'                  |       | j1                  |       Y y w xY w)Nr  r-  r  r  r8  r6  r   r7  r  zSEND with bad typez
TOS type: z(Attempted to SEND with unsupported type rU  )r   r  r   r  rZ  r  rV  r|   rx   r   r  collectionsabcIteratorr   r   rs  r   r  rF  r  r   r  r  r  r=   re   )r   r   ri  null_or_indexreceivernext_idxs         r   SENDz+InliningGeneratorInstructionTranslator.SEND  s   DJJ1$ !KLLhhjw& HHJM::b>x"24P!QR8%>?x~~{/G/GH   G+x,)FG ##%#''72(= (M)X '44T:" ''72		(+IIcN < b	 ,$WX%6$78FwxGXFYYZ[	? "11** $ '''1
IIcNIIdO$s   45F A-HH)r   r   r  r   r   r   r  r  r  )r   r   r   r   rV  r  r  r,  r/  r{  r  r  r9  rA  r^  r_  s   @r   r  r  b  s<    **3***'#R?r   r  )r   r   r   ztypes.ModuleType)r   rJ  )r   r   r   Generator[None, None, None])rR  zCallable[..., object]r   Callable[..., Any])r\  r  r   r   )rl  r   r   r   )r   r   ry  Callable[[object], bool]rF  r   r   r   )r  r  r   r   )r   )r  rg   r  r   r   r   )ry  rD  rF  r   r   rK  )r   r   r  r3   r  r  r   r   )r   r   r   r   r   rC  )rF  r   r4  r   r   zYCallable[[Callable[..., None]], Callable[[InstructionTranslatorBase, Instruction], None]])r(  rE   r  r  r  zCallable[[], int]r   rB  (  r   
__future__r   r  r;  collections.abcrh  rE  r   ri  rP  r   rM  r  r  r   rt  r  rZ  	threadingr  r  rW  r  r   r   typingr   r   r   r	   r
   r   typing_extensionsr   r  torch._loggingtorch._dynamo.dynamo_profilerr   r   torch._dynamo.excr   r   torch._guardsr   r   r   torch._logging.structuredr   %torch.fx.experimental.symbolic_shapesr   torch.utils._functoolsr   r   r   r   r   r  r   r   bytecode_analysisr   r   r    r!   bytecode_transformationr"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   codegenr3   comprehension_graph_breakr4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   funcname_cacher@   guardsrA   rB   output_graphrC   rD   rE   rF   	polyfillsrG   rH   rI   rJ   replay_recordrK   rL   r  rM   rN   rO   r  rP   rQ   rR   rS   rT   rU   rV   rW   rX   rY   utilsrZ   r[   r\   r]   r^   r_   r`   ra   rb   rc   variables.baserd   re   rf   rg   variables.builderrh   ri   rj   variables.builtinrk   rl   variables.constantrm   variables.ctx_managerrn   ro   rp   rq   r  rs   variables.functionsrt   ru   rv   rw   rx   ry   rz   r{   variables.iterr|   r}   variables.lazyr~   r  r   r   r   r   r   variables.miscr   r   r   r   r   r   variables.nn_moduler   r   variables.object_protocolr   r   r   r   variables.setsr   rb  r   variables.tensorr   r   r   variables.torch_functionr   r   variables.user_definedr   r   r   r   r   r   r   torch._subclasses.fake_tensorr   r  r   	getLoggerr   r!  r  getArtifactLoggerr  r  r  r  r  rm  r  rG  r   r   containsr   r   r   r   cacher   	dataclassr   r   r   r	  r  r"  ri  r%  r+  r-  r   r   r  rA  rC  rS  r]  rp  r  r  r  r  r  r  r  rL  r]  rN  ra  r   rL  r  _nb_opsr  rU  r  r  r  )r  r  r   r   s   0000r   <module>rq     s  0 #       
        	 
      * I I $   R O C C / < /      $ '  L    ) /   : 
	 	 	 ;   W V R R C 0  /	 	 	 A /   Q  ( 2 W W  3<'g!..228^L11(LI>>33HnM ^^55h@PQ ioo4R4L4R4R4T',0AqAq'''' ^  "("3"34BBX]]+99
 D ! H 
 '(() y  ) )   B I I IX 
 
 
 / / /3 3. 4 4 )!) ) )& $!$ $ $ ! ! !H	~ 		I 	9 A . .&*
#*&* * 
	*Z B@&@Fe&e.2e=eP	R!R'0R;LR	RB4[["[[|J J2 i i iXl=;'l=;^{A5 AH
 w 
 FA	 	!#v-F12JWVABZL3I	
 :=:=
:= (:= !	:= :=zaJ$= aJHZ-J Z{'hhs   V<$W