
    sg                      h    d dl Z d dlmZ d dlZddlmZmZmZ ddlm	Z	 ddl
mZ d Z G d	 d
e      Zy)    N)Dict   )unimplementedUnsafeScriptObjectErrorUnsupported   )VariableTracker)UserDefinedObjectVariablec                     d }|S )Nc                 B     t        j                          fd       }|S )Nc                  d    	  | i |S # t         $ r}t        |j                        |d }~ww xY wN)r   r   msg)argskwargsefns      X/var/www/html/venv/lib/python3.12/site-packages/torch/_dynamo/variables/script_object.pygraph_break_as_hard_errorzQ_raise_hard_error_if_graph_break.<locals>.deco.<locals>.graph_break_as_hard_error   s9    <4*6** <-aee4!;<s    	/*/)	functoolswraps)r   r   s   ` r   decoz._raise_hard_error_if_graph_break.<locals>.deco   s&    			< 
	< )(     )reasonr   s     r    _raise_hard_error_if_graph_breakr      s    ) Kr   c                        e Zd ZU i Zeed f   ed<   edefd       Z	e
d        Zd fdZd Z ed      d	edefd
       Z ed      d        Z xZS )TorchScriptObjectVariable_fake_script_object_cacheuser_clsc                 6    t        |t        j                        S r   )
issubclasstorchScriptObject)clsr    s     r   is_matching_clsz)TorchScriptObjectVariable.is_matching_cls   s    (E$6$677r   c                     t        | |fi |S r   )r   )proxyvalueoptionss      r   createz TorchScriptObjectVariable.create"   s    (AAAr   returnc                     t        |   |fi | || _        || j                  j                  j                  d<   || _        y )Nexample_value)super__init__r(   nodemetasource)selfr(   r)   r3   r   	__class__s        r   r0   z"TorchScriptObjectVariable.__init__&   s;    )&)
05

_-r   c                     | j                   S r   )r(   )r4   s    r   as_proxyz"TorchScriptObjectVariable.as_proxy,   s    zzr   z<Dynamo cannot safely trace script object due to graph break.namec                     ddl m} ddlm} ddlm} t        | j                  |d       }|t        d| d       t        |      st        d	       |j                  | || j                  |      | |
      S )Nr   )call_torchbindr   )
AttrSourcer   ) TorchHigherOrderOperatorVariablez'FakeScriptObject doesn't define method z3. Did you forget to implement it in the fake class?zvOnly method calls on TorchScript objects can be supported safely. Please use method calls instead of attribute access.)r3   script_obj_varmethod_name)!torch._higher_order_ops.torchbindr:   r3   r;   higher_order_opsr<   getattrr)   r   callablemake)r4   txr8   r:   r;   r<   methods          r   var_getattrz%TorchScriptObjectVariable.var_getattr/   s     	E'FT40>9$?rs H
 044dkk40	 5 
 	
r   c                 "    t        d| d       y )Nzcall method z on script object is not safe.)r   )r4   rD   r8   r   r   s        r   call_methodz%TorchScriptObjectVariable.call_methodO   s     	TF*HIJr   )r,   N)__name__
__module____qualname__r   r   int__annotations__classmethodtyper&   staticmethodr+   r0   r7   r   strr	   rF   rH   __classcell__)r5   s   @r   r   r      s    HJtC)D$DEJ8t 8 8 B B &F
C 
O 

: &FKKr   r   )r   typingr   r#   excr   r   r   baser	   user_definedr
   r   r   r   r   r   <module>rW      s0       E E ! 38K 9 8Kr   