
    %Vji                     0   d dl Z d dlZd dlmZ d dlmZmZ d dlZd dlm	c m
Z d dlmZmZmZ d dlmZ d dlmZmZ d dlmZmZ d dlmZmZ  G d	 d
ej        j                  Z edddg          Zdej        j        dedej        j         f         fdZ!dS )    N)
namedtuple)AnyCallable)	FrameInfofullgraph_captureget_compile_id)argument_names)dynamo_timedget_metrics_context)compile_contextCompileContext)_PyTreeCodeGen_PyTreeInfoc                   <     e Zd Zdededdf fdZdeddfdZ xZS )	ModuleToTracefooin_specreturnNc                 d    t                                                       || _        || _        d S N)super__init___export_rootr   )selfr   r   	__class__s      Y/root/voice-cloning/.venv/lib/python3.11/site-packages/torch/_dynamo/functional_export.pyr   zModuleToTrace.__init__   s,        	flat_argsExportTracerOutputc                     t          j        || j                  \  }} | j        |i |}t          j        |          \  }}t          ||          S r   )pytreetree_unflattenr   r   tree_flattenr   )r   r   argskwargsresout_flatout_specs          r   forwardzModuleToTrace.forward   sV    ,YEEfd000#055(!(H555r   )__name__
__module____qualname__r   r   r)   __classcell__)r   s   @r   r   r      su        C # $      
6# 6*> 6 6 6 6 6 6 6 6r   r   r   r   r(   modr   .c                 R     dt           dt           dt          j        j        f fd}|S )z
    This is lower level API that is used for export to capture dynamo level
    torch IR.

    Notable TODOs:
    1. Are we actually gonna run the bytecode?
    2. Need to attach guards
    r$   r%   r   c            
      "	   t          j        | |f          \  }}t          !|          }t          j        |j                  } |j        | }|                                 d|i|j        }t          |j        j
        j        |j        j
        j        |t          d          }t          j        j                            dd          }	t%          t'          t)          i                               5  t+                      5  t-          d          5  |	5  t/          |d          }
|
j        j        j        J |
j        j        j        j        }|j        }|j        }|j        }|
j        j         }i }|D ]G}||         }tC          |t          j        j"        j#                  sJ tI          |          ||j%        <   Hd tM          |j'        j(                  D             }tS          d	 tM          |j'        j(                  D                       }tI          |          d
k    r|d
         n|}i }|j'        *                    |          5  tW          tI          |                    D ]`}|j'        ,                    d|           }||v r8|||                   |||                  j-        .                                |_-        |||<   a	 d d d            n# 1 swxY w Y   g }|D ]|}||         \  }}|dk    r&|/                    |j0        d
         |                    |dk    r"|j%        }|/                    ||                    |dk    r|/                    |           }tc          |          f|_0        |2                                D ]D\  }}||         }||         }|3                    |           |j'        4                    |           Ed
dl5m6}  | 7                    |           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   tq          ts          tu          || |          ||                    |j'        _;        |<                                 |S )Nr    )closurelog_graph_in_out_metadataTr   ) _is_export_deprecated_do_not_usec                 (    g | ]}|j         d k    |S )placeholderop.0ns     r   
<listcomp>zC_dynamo_graph_capture_for_export.<locals>.inner.<locals>.<listcomp>^   s$    XXX!!$-BWBWABWBWBWr   c              3   0   K   | ]}|j         d k    |V  dS )outputNr7   r9   s     r   	<genexpr>zB_dynamo_graph_capture_for_export.<locals>.inner.<locals>.<genexpr>_   s.      QQ@P@P!@P@P@P@PQQr   r   arg_	graph_outinputconstant)_LazyGraphModule)=r!   r#   r   inspect	signaturer)   bindapply_defaults	argumentsr   __func____code____globals__builtinstorch_dynamoconfigpatchr   r   r   r   r
   r   dynamo_outputtracer_outputoutput_graphexport_metadatagraph_input_idx_to_local_sourceoutput_return_typer(   backend_inputgraph_module
isinstancesourceGetItemSourcelenindexlistgraphnodesnextinserting_beforeranger6   metacopyappendr$   tupleitemsreplace_all_uses_with
erase_nodetorch.fx._lazy_graph_modulerD   force_recompiler   r   r	   _codegen	recompile)"r$   r%   flat_inputsr   module_to_tracerF   bound_argumentsf_localsframedynamo_config_ctxoutrU   graph_inputsrW   r(   r`   graph_input_orderinpr[   placeholdersr>   anchorinp_to_nodeinode_newnew_argstypeval	input_idxsrc_idxoldnewrD   r.   s"                                    r   innerz/_dynamo_graph_capture_for_export.<locals>.inner+   s   %2D&>BBW'W55%o&=>>	().+6&&(((OI/HI#,5#,8
 
 
 "M066'
 

 N>"+=+=>>???	4 ?	4!!?	4 ?	4 ,--?	4 ?	4 	?	4 ?	4 $EDQQQC$2?KKK !/<L  +JL!0!C&/H%2E 13# I I%c*!&%-*>*LMMMMM256G2H2H!&,//XXtEK,='>'>XXXLQQT%+*;%<%<QQQQQF(+L(9(9A(=(=\!__6FK--f55 . .s;//00 . .A${66zazzBBH---$%6q%9::(45Fq5I(J(O(T(T(V(V%-KNN.. . . . . . . . . . . . . . . H' ) ).q1	c;&&OOFKN3$78887?? #	IOOK	$:;;;:%%OOC((( ??,FK/5577 , ,
"7+!!n))#...&&s++++ EDDDDD,,U333?	4 ?	4 ?	4 ?	4 ?	4 ?	4 ?	4 ?	4 ?	4 ?	4 ?	4 ?	4 ?	4 ?	4 ?	4 ?	4 ?	4 ?	4 ?	4 ?	4 ?	4 ?	4 ?	4 ?	4 ?	4 ?	4 ?	4 ?	4 ?	4 ?	4 ?	4 ?	4 ?	4 ?	4 ?	4 ?	4 ?	4 ?	4 ?	4 ?	4 ?	4 ?	4 ?	4 ?	4 ?	4 ?	4 ?	4 ?	4 ?	4 ?	4 ?	4 ?	4 ?	4 ?	4 ?	4 ?	4 ?	4 ?	4 ?	4 ?	4B  .y$77  
  
 	s   2P9P"PD4O4	A>KO4	KO4	KDO4	(P4O88P;O8<P?P"PP"PP"P9"P&	&P9)P&	*P99P= P=)r   rN   fxGraphModule)r.   r   s   ` r    _dynamo_graph_capture_for_exportr      sL    aS aC aEH,@ a a a a a aF Lr   )"rM   rE   collectionsr   typingr   r   rN   torch.utils._pytreeutils_pytreer!   torch._dynamo.convert_framer   r   r   torch._dynamo.eval_framer	   torch._dynamo.utilsr
   r   torch._guardsr   r   torch.fx.graphr   r   nnModuler   r   r   r   r   r1   r   r   <module>r      sn     " " " " " "                  $ $ $ $ $ $ $ $ $ T T T T T T T T T T 3 3 3 3 3 3 A A A A A A A A 9 9 9 9 9 9 9 9 6 6 6 6 6 6 6 6
6 
6 
6 
6 
6EHO 
6 
6 
6  Z 4{J6OPP o	oc58''(o o o o o or   