
    קg                     t    d dl Z d dlmZ d dlmZ d dlmZ d dlmZ d dl	m
Z d dlZ G d de          Zd	 ZdS )
    N)CapabilityBasedPartitioner)OperatorSupport)CALLABLE_NODE_OPS)FakeTensorProp)_pytreec                   2    e Zd Zdej        j        defdZdS )CudaGraphsSupportnodereturnc                 T   |j         t          vrdS |j        t          j        j        j        j        fv rdS |j        t          j	        fv rdS dd }fd}|j
        D ]%}t          j        | ||j                             &t          j        | ||j                              S )NFTc                 *    d| v r| d         n| d         S )Nvalfake_result )metas    _/var/www/html/ai-engine/env/lib/python3.11/site-packages/torch/fx/passes/backends/cudagraphs.pymeta_fkz4CudaGraphsSupport.is_node_supported.<locals>.meta_fk   s    "'4--4;;T-5HH    c                 h    t          | t          j                  r| j        j        dk    rdd S d S d S )NcudaT)
isinstancetorchTensordevicetype)tfound_not_cudas    r   find_not_cudaz:CudaGraphsSupport.is_node_supported.<locals>.find_not_cuda   s>    !U\** &qx}/F/F!%& &/F/Fr   )opr   targetr   opsatenembedding_dense_backwarddefaultoperatorgetitemall_input_nodespytree	tree_map_r   )self
submodulesr
   r   r   nr   s         @r   is_node_supportedz#CudaGraphsSupport.is_node_supported   s    7+++5;59>BJKKK5;8+,,,4	I 	I 	I	& 	& 	& 	& 	&
 % 	= 	=A]GGAFOO<<<<	(:(:;;;
 "!!r   N)__name__
__module____qualname__r   fxNodeboolr-   r   r   r   r	   r	      s:        "%(- "D " " " " " "r   r	   c                      t          |           j        |  t                      }t          | |d          }|                                }|                    |          }|S )z
    Partition an FX graph into sub-GraphModules that can be validly run under
    CUDA graphs.  For a subgraph to be runnable under CUDA, all of the operations
    must involve CUDA tensors only/
    T)allows_single_node_partition)r   	propagater	   r   propose_partitionsfuse_partitions)gminputssupported_opspartitioner
partitionsfused_graphs         r   partition_cudagraphsr?   +   sh     !N2 &))%''M -R]abbbK//11J--j99Kr   )r   !torch.fx.passes.infra.partitionerr    torch.fx.passes.operator_supportr   torch.fx.passes.tools_commonr    torch.fx.passes.fake_tensor_propr   torch.utilsr   r(   r%   r	   r?   r   r   r   <module>rE      s     H H H H H H < < < < < < : : : : : : ; ; ; ; ; ; ) ) ) ) ) ) " " " " " " " "@    r   