
    קg                     B    d dl Z d dlmZ d dlmZ  G d de          ZdS )    N)ProxyTorchDispatchMode)TorchFunctionModec                       e Zd ZdZddZdS )AutogradStateOpsFailSafeguarda  
    Detect grad state ops during exporting the graph and fail the process by
    raising an error, to avoid unexpected behavior. Those grad mode ops could be:
    `torch.no_grad`
    `torch.enable_grad`
    `torch.set_grad_enabled`

    Export with predispatch mode is exempted.
     Nc                    |pi }t           j        j        g}t           j                                        }||v rt	          |          dk    sJ |d         }t           j                            t           j        j        j                  }|r5t          |t                    r |j
        s||k    rt          d| d           ||i |S )N   r   z&Encountered autograd state manager op z trying to change global autograd state while exporting. This is unsafe because we don't capture this op in torch.export today, hence we can't reflect the user intention soundly. You can fix this by adding a torch.no_grad() context around the export call.)torch_C_set_grad_enabledis_grad_enabledlen_get_dispatch_mode_TorchDispatchModeKeyPROXY
isinstancer   pre_dispatchRuntimeError)	selffunctypesargskwargsunsupported_grad_mode_opscurrent_statechanged_statemodes	            S/var/www/html/ai-engine/env/lib/python3.11/site-packages/torch/export/_safeguard.py__torch_function__z0AutogradStateOpsFailSafeguard.__torch_function__   s    2H&%
!
 0022,,,t99>>>> GM8..ux/M/STTD t%;<< ) "]22"OT O O O   tT$V$$$    )r   N)__name__
__module____qualname____doc__r   r   r    r   r   r      s2         % % % % % %r    r   )r
   "torch.fx.experimental.proxy_tensorr   torch.overridesr   r   r   r    r   <module>r'      sg     E E E E E E - - - - - -%% %% %% %% %%$5 %% %% %% %% %%r    