
    `i
                     R    d dl Z d dlmZmZ de j        de j        fdZdad Zd ZdS )    N)	decompileDecompilationErrorcodenew_codec                    dd l }|j                            dd          }dd l}|                    |j                  r	 t          |          }|                    d           |                    |           n:# t          $ r-}|                    dt          |                     Y d }~nd }~ww xY w|                    d           d S # |                    d           w xY wd S )Nr   ztorch._dynamo.convert_framebytecodezpossible source code:zDecompilation fails due to: %sziIf you find the decompiled code is wrong,please submit an issue at https://github.com/thuml/depyf/issues.)
torch_logginggetArtifactLoggerloggingisEnabledForDEBUGr   debugr   str)r   r   r	   bytecode_logr   decompiled_srces          q/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/depyf/explain/enhance_logging.pypytorch_bytecode_src_hookr      s/   LLL>33%z L NNN  // 	&x00N6777~....! 	I 	I 	I?QHHHHHHHH	I 9    L9    s/   9A9 8C
 9
B0#B+&C
 +B00C
 
C!c                  h    ddl } t          dS | j        j                            t
                    adS )a  
    Install the bytecode hook for PyTorch, integrate into PyTorch's logging system.

    Example:

    .. code-block:: python

        import torch
        import depyf
        depyf.install()
        # anything with torch.compile
        @torch.compile
        def f(a, b):
            return a + b
        f(torch.tensor(1), torch.tensor(2))
    
    Turn on bytecode log by ``export TORCH_LOGS="+bytecode"``, and execute the script.
    We will see the decompiled source code in the log:

    .. code-block:: text

        ORIGINAL BYTECODE f test.py line 5 
        7           0 LOAD_FAST                0 (a)
                    2 LOAD_FAST                1 (b)
                    4 BINARY_ADD
                    6 RETURN_VALUE
        
        
        MODIFIED BYTECODE f test.py line 5 
        5           0 LOAD_GLOBAL              0 (__compiled_fn_1)
                    2 LOAD_FAST                0 (a)
                    4 LOAD_FAST                1 (b)
                    6 CALL_FUNCTION            2
                    8 UNPACK_SEQUENCE          1
                    10 RETURN_VALUE
        
        
        possible source code:
        def f(a, b):
            __temp_2, = __compiled_fn_1(a, b)
            return __temp_2
        
        If you find the decompiled code is wrong,please submit an issue at https://github.com/thuml/depyf/issues.
    
    To uninstall the hook, use :func:`depyf.uninstall()`.
    r   N)r	   _handle_dynamoconvert_frameregister_bytecode_hookr   )r	   s    r   installr      s:    ^ LLLm)@@!# #GGG    c                  N    t           dS t                                            da dS )zf
    Uninstall the bytecode hook for PyTorch.
    Should be called after :func:`depyf.install()`.
    N)r   remove r   r   	uninstallr    U   s'     NNGGGr   )	typesdepyf.decompilerr   r   CodeTyper   r   r   r    r   r   r   <module>r$      s|     : : : : : : : :EN en    , 4# 4# 4#n	 	 	 	 	r   