
    9j6                         d dl Zd dlZd dlZd dlZd dlmZ dZd Z G d dej                  j                        Zd Z	 d
dZd	 Zy)    N)get_remote_module_template_remote_module_c                 N   t        | dd      st        d      t        j                  j	                  |       }t        j
                  j                  j                  }|j                  |      }d|j                         vrt        d|j                                |j                  d      }g }g }|t        |j                  D ]m  }|j                  |j                         |j                         rd|j                   }nd}|j                   d|j                    | }	|j                  |	       o |d	d  }d
j#                  |      }
|d	d  }d
j#                  |      }t%        |j&                        d	k7  rt        |j&                  d   }t)        |j                         }|
||fS )N__torch_script_interface__FzGExpect a TorchScript class interface decorated by @torch.jit.interface.forwardz2Expect forward in interface methods, while it has z =  z:    z, r   )getattrAssertionErrortorch_jit_internal_qualified_namejit_state
_python_cuget_interfacegetMethodNames	getMethod	argumentsappendnamehas_default_valuedefault_valuetypejoinlenreturnsstr)module_interfacequalified_namecumodule_interface_cmethod_schemaarg_str_listarg_type_str_listargumentdefault_value_strarg_type_strargs_strarg_types_strreturn_type_strs                e/media/conek/DATA/Code/OCR/venv/lib/python3.12/site-packages/torch/distributed/nn/jit/instantiator.py#get_arg_return_types_from_interfacer-      s   #%A5IU
 	
 ((889IJN				$	$B)).9*99;;@ASAbAbAd@ef
 	
 '00;ML!++ /HMM*%%'"%h&<&<%= > ""--8==/:K9LM  ./  #Lyy&H)!"-II/0M
=  !Q&$$Q'H(--(O]O33    c                   h    e Zd ZdZdeddfdZdedefdZdedefd	Zdedefd
Z	dede
fdZddZy)_StringLoaderay  
    A custom loader for dynamically generated Python source code.

    Inherits from SourceLoader for API compatibility but overrides exec_module()
    to avoid bytecode caching issues. The default SourceLoader.exec_module() calls
    cache_from_source() which fails with IndexError when the filename doesn't
    correspond to a real filesystem path with a .py extension.
    datareturnNc                     || _         y Nr1   )selfr1   s     r,   __init__z_StringLoader.__init__D   s	    	r.   fullnamec                     | j                   S r4   r5   r6   r8   s     r,   
get_sourcez_StringLoader.get_sourceG   s    yyr.   pathc                 8    | j                   j                  d      S )Nzutf-8)r1   encoder6   r<   s     r,   get_dataz_StringLoader.get_dataJ   s    yy((r.   c                     d| dS )N<z>.py r:   s     r,   get_filenamez_StringLoader.get_filenameM   s    8*D!!r.   c                     t        d      )Nz4dynamically generated module has no filesystem stats)OSErrorr?   s     r,   
path_statsz_StringLoader.path_statsP   s    LMMr.   c                     | j                  |j                        }| j                  |j                        }t        ||dd      }t	        ||j
                         y)z
        Execute the module by compiling and running the source directly.

        This overrides SourceLoader.exec_module() to bypass the problematic
        get_code() -> cache_from_source() code path that fails on dynamic modules.
        execT)dont_inheritN)r;   __name__rD   compilerI   __dict__)r6   modulesourcefilenamecodes        r,   exec_modulez_StringLoader.exec_moduleT   sH     1$$V__5vxdCT6??#r.   )r2   N)rK   
__module____qualname____doc__r   r7   r;   bytesr@   rD   dictrG   rR   rC   r.   r,   r0   r0   :   sn    S T 3 3 )S )U )"S "S "Ns Nt N
$r.   r0   c                 r   | t         j                  v rt         j                  |    S t         t        |      j                  di |      }t
        j                  j                  | |d      }|t        t
        j                  j                  |      }|t         j                  | <   |j                  |       |S )Nz	torch-git)originrC   )sysmodulesr0   r   format	importlibutilspec_from_loaderr   module_from_specrR   )generated_module_namestr_dict!enable_moving_cpu_tensors_to_cudaloaderspecrN   s         r,   &_do_instantiate_remote_module_templaterf   a   s     +{{011L"#DELLXxXF >>**vk + D |^^,,T2F)/CKK%&
vMr.   c           	      \   t        | dd      st        d|  d      t        j                  j	                  |       j                  dd      }t         | }d| j                   d| j                   d	}t        |       \  }}}d
}d| }	d| d}
t        |||	|
||d      }t        |||      S )Nr   Fzmodule_interface_cls z8 must be a type object decorated by @torch.jit.interface._zfrom z import z as module_interface_clsr   z -> z -> Future[]z@torch.jit.script)assign_module_interface_cls	arg_typesarrow_and_return_typearrow_and_future_return_typeargskwargsjit_script_decorator)r
   
ValueErrorr   r   r   replace_FILE_PREFIXrS   rK   r-   rW   rf   )module_interface_clsrc   module_interface_cls_namera   assign_module_interface_cls_strr)   r*   r+   
kwargs_strarrow_and_return_type_str arrow_and_future_return_type_strrb   s               r,   -instantiate_scriptable_remote_module_templater{   u   s    ')EuM#$8#9 :# #
 	
 !& 3 3 C C!gc3   ,n-F,GH $//0((
))A	C $ 0S0,Hm_ J"&&7 8)4_4EQ'G$$C7%E0H 2x)J r.   c            	      R    t          d} t        ddddddd      }t        | |d      S )	Nnon_scriptablezmodule_interface_cls = Nonez*argsz**kwargsz*args, **kwargsr   )rk   ro   rp   rl   rm   rn   rq   T)rt   rW   rf   )ra   rb   s     r,   1instantiate_non_scriptable_remote_module_templater~      sA    +nN;$A# %'H 22GSWXXr.   )T)importlib.abcr]   importlib.utilrZ   r   9torch.distributed.nn.jit.templates.remote_module_templater   rt   r-   abcSourceLoaderr0   rf   r{   r~   rC   r.   r,   <module>r      sS      
 
 !'4T$$IMM.. $$N* =A&RYr.   