/usr/local/lib64/python3.6/site-packages/torch/fx/experimental/__pycache__
NameSizeModeActions
accelerator_partitioner.cpython-36.pyc292110644editdlrm
const_fold.cpython-36.pyc58990644editdlrm
graph_gradual_typechecker.cpython-36.pyc268710644editdlrm
merge_matmul.cpython-36.pyc57470644editdlrm
normalize.cpython-36.pyc50010644editdlrm
optimization.cpython-36.pyc141050644editdlrm
partitioner_utils.cpython-36.pyc92750644editdlrm
refinement_types.cpython-36.pyc9210644editdlrm
rewriter.cpython-36.pyc48130644editdlrm
schema_type_annotation.cpython-36.pyc40370644editdlrm
unify_refinements.cpython-36.pyc29000644editdlrm
__init__.cpython-36.pyc1570644editdlrm
Edit: /usr/local/lib64/python3.6/site-packages/torch/fx/experimental/__pycache__/rewriter.cpython-36.pyc (4813B)
3 EgO@sddlZddlZddlZddlZddlZddlmZddlmZm Z m Z m Z m Z m Z ddlmZddlmZddlmZddlZGdddejZGd d d eZe ejje fe ejje fd d d ZdS)N) FunctionType)castUnionCallableDictOptionalAny)Tracer)Graph)normalize_source_linesc@s.eZdZdZedddZddZddZd S) AST_Rewriterax Take a FunctionType object representing a `forward` method, then perform an AST rewrite to swap out nodes that are not symbolically traceable with a callsite to the FX alternative. To support swapping out an AST node, define a new `visit` method on that node. For more details, see: https://docs.python.org/3/library/ast.html#ast.NodeTransformer )fncCstj|\}}t|}dj|}tj|}tj|}tj|j |}t |dd}t j |j } t | j} t|| tt | j| } t| dkst| | d} dd} | | |j dS)NexecrcSs8t|j||j|j|jd}tj||}tj|j|_|S)z?Based on https://stackoverflow.com/a/13503277/2988730 (@unutbu))nameZargdefsZclosure) r__code____name__ __defaults__ __closure__ functoolsupdate_wrappercopy__kwdefaults__)fglobalsgrJ/usr/local/lib64/python3.6/site-packages/torch/fx/experimental/rewriter.pychange_func_globals.s  z1AST_Rewriter.rewrite..change_func_globals)r)inspectgetsourcelinesr jointextwrapdedentastparsefix_missing_locationsvisitcompiler __globals__setkeysrlistlenAssertionError)selfr sourcelines_sourceZnormalized_strZ source_astZdest_astcodeZ globals_dictZ keys_beforeZnew_keysZ fn_compiledrrrrrewrites        zAST_Rewriter.rewritecCsrtjddd}t|tjst|j}t|tjs4t|jr@|jn tjddd}|j |g|_ tj |d}tj ||S)z Swap out the Assert node (Python's `assert`) with a callsite to the symbolically-traceable torch._assert function ztorch._assert()eval)moderN)valuekind)r8) r%r& isinstance Expressionr/bodyCallmsgConstanttestargsExpr copy_location)r0nodenZ call_noder>Z expr_wrapperrrr visit_Assert?s  zAST_Rewriter.visit_AssertcCs4tj|jgtjtjdtjd|j|jggddS)a Swap out Python's AnnAssign with an Assign node where the annotation function is called. Example: Original: y: Tensor_Type(1,2,3, Dyn) = f2(x) Output: y = annotate(f2(x),Tensor_Type((1,2,3,Dyn))) Zannotate)idctx)funcrAkeywords)targetsr8)r%Assigntargetr=NameLoadr8 annotation)r0rDrrrvisit_AnnAssignSs zAST_Rewriter.visit_AnnAssignN)r __module__ __qualname____doc__rr5rFrQrrrrr s 'r cs@eZdZdeejjefee e e fe dfdd Z ZS)RewritingTracerN)root concrete_argsreturncstjt||S)N)supertrace_rewrite)r0rVrW) __class__rrrZbszRewritingTracer.trace)N)rrRrSrtorchnnModulerrrstrrr rZ __classcell__rr)r\rrUasrU)r rXcsBt|tjjr,tjjdfdd |Stjtt|SdS)N)mcs6Gfdddtjj}tjtt|j|_||S)NcseZdZfddZZS)z9_rewrite..rewrite_module..RewrittenModulecsZtjxJ|jjD]<\}}t|tjjrBtj||j|<qtj||j|<qWdS)N) rY__init____dict__itemsr:r]r^r_r)r0origkv)r\rewrite_modulerrrcms  zB_rewrite..rewrite_module..RewrittenModule.__init__)rrRrSrcrar)ri)r\rRewrittenModulelsrj)r]r^r_r r5rrZforward)rbrj)rirrriksz _rewrite..rewrite_module)r:r]r^r_r r5rr)r r)rirr[fs r[)r%r r#rrtypesrtypingrrrrrrZtorch.fx._symbolic_tracer Ztorch.fx.graphr Ztorch._sourcesr r]NodeTransformerr rUr^r_r[rrrrs     T