Ë
    ÄÓ^j&	  ã                   óô   — d dl Z d dlmZmZ d dlmZ d dlZddg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  G d„ de«      Zdej(                  j*                  dee   dej(                  j*                  fd„Zy)é    N)ÚMappingÚSequence)ÚAnyÚCudaGraphsSupportÚpartition_cudagraphs)ÚFakeTensorProp)ÚCapabilityBasedPartitioner)ÚOperatorSupport)ÚCALLABLE_NODE_OPS)Ú_pytreec                   óz   — e Zd Zdeeej                  j                  f   dej                  j                  de
fd„Zy)r   Ú
submodulesÚnodeÚreturnc                 ó  ‡— |j                   t        vry|j                  t        j                  j
                  j                  j                  u ry|j                  t        j                  u rydŠdt        t        t        f   dt        j                  fd„}dt        dd fˆfd„}|j                  D ](  }t!        j"                  | ||j$                  «      «       Œ* t!        j"                  | ||j$                  «      «       ‰ S )NFTÚmetar   c                 ó   — d| v r| d   S | d   S )NÚvalÚfake_result© )r   s    ún/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/torch/fx/passes/backends/cudagraphs.pyÚmeta_fkz4CudaGraphsSupport.is_node_supported.<locals>.meta_fk    s   € Ø"'¨4¡-�4˜‘;ÐH°T¸-Ñ5HÐHó    Útc                 ót   •— t        | t        j                  «      r| j                  j                  dk7  rdŠy y y )NÚcudaT)Ú
isinstanceÚtorchÚTensorÚdeviceÚtype)r   Úfound_not_cudas    €r   Úfind_not_cudaz:CudaGraphsSupport.is_node_supported.<locals>.find_not_cuda#   s.   ø€ ä˜!œUŸ\™\Ô*¨q¯x©x¯}©}ÀÒ/FØ!%‘ð 0GÐ*r   )Úopr   Útargetr   ÚopsÚatenÚembedding_dense_backwardÚdefaultÚoperatorÚgetitemÚdictÚstrr   r   ÚobjectÚall_input_nodesÚpytreeÚ	tree_map_r   )Úselfr   r   r   r#   Únr"   s         @r   Úis_node_supportedz#CudaGraphsSupport.is_node_supported   sÜ   ø€ ð �7‰7Ô+Ñ+Øà�;‰;œ%Ÿ)™)Ÿ.™.×AÑA×IÑIÑIØà�;‰;œ(×*Ñ*Ñ*Øàˆð	Iœ$œs¤C˜x™.ð 	I¬U¯\©\ó 	Ið	&œVð 	&¨õ 	&ð
 ×%Ñ%ò 	=ˆAÜ×Ñ˜]©G°A·F±F«OÕ<ð	=ô 	×Ñ˜©°·	±	Ó(:Ô;ð
 "Ð!Ð!r   N)Ú__name__Ú
__module__Ú__qualname__r   r-   r   ÚnnÚModuleÚfxÚNodeÚboolr4   r   r   r   r   r      s9   „ ð"Ø! # u§x¡x§¡Ð"6Ñ7ð"Ø?D¿x¹x¿}¹}ð"à	ô"r   ÚgmÚinputsr   c                 ó¨   —  t        | «      j                  |Ž  t        «       }t        | |d¬«      }|j	                  «       }|j                  |«      }|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)r=   r>   Úsupported_opsÚpartitionerÚ
partitionsÚfused_graphs         r   r   r   3   sZ   € ð !„N�2Ó× Ñ  &Ñ)Ü%Ó'€Mô -Ø
ˆM¸ô€Kð ×/Ñ/Ó1€JØ×-Ñ-¨jÓ9€KØÐr   )r*   Úcollections.abcr   r   Útypingr   r   Ú__all__Ú torch.fx.passes.fake_tensor_propr   Ú!torch.fx.passes.infra.partitionerr	   Ú torch.fx.passes.operator_supportr
   Útorch.fx.passes.tools_commonr   Útorch.utilsr   r0   r   r:   ÚGraphModuler.   r   r   r   r   ú<module>rQ      sp   ðÛ ß -Ý ã ð Ð 6Ð
7€Ý ;Ý HÝ <Ý :Ý )ô "˜ô  "ðFØ�‰×ÑðØ&.¨vÑ&6ðà
‡X�X×Ñôr   