o
    }oi]
                     @   sl   d dl mZ d dlmZ d dlmZ G dd deZG dd deejZG dd	 d	ejZ	G d
d dZ
dS )    )SimpleNamespaceN)WithOptionalCudaGraphsc                       s,   e Zd Z fddZdd Zdd Z  ZS )MockClassWithCudaGraphsc                    s   t    d| _d S NT)super__init__cuda_graphs_usedself	__class__ f/home/ubuntu/.local/lib/python3.10/site-packages/tests/collections/common/test_optional_cuda_graphs.pyr      s   

z MockClassWithCudaGraphs.__init__c                 C   
   d| _ d S )NFr   r	   r   r   r   disable_cuda_graphs      
z+MockClassWithCudaGraphs.disable_cuda_graphsc                 C   r   r   r   r	   r   r   r   maybe_enable_cuda_graphs   r   z0MockClassWithCudaGraphs.maybe_enable_cuda_graphs)__name__
__module____qualname__r   r   r   __classcell__r   r   r   r   r      s    r   c                       $   e Zd Z fddZdd Z  ZS )MockModuleWithCudaGraphsc                    s   t    tdd| _d S )N
      )r   r   nnLinearlinearr	   r   r   r   r   "   s   
z!MockModuleWithCudaGraphs.__init__c                 C   
   |  |S Nr   r
   xr   r   r   forward&   r   z MockModuleWithCudaGraphs.forwardr   r   r   r   r$   r   r   r   r   r   r   !   s    r   c                       r   )MockModuleWithCudaGraphsByPathc                    s*   t    tdd| _tt d| _d S )Nr   r   )decoding)r   r   r   r   r   r   r   r'   r	   r   r   r   r   +   s   
z'MockModuleWithCudaGraphsByPath.__init__c                 C   r   r    r!   r"   r   r   r   r$   0   r   z&MockModuleWithCudaGraphsByPath.forwardr%   r   r   r   r   r&   *   s    r&   c                   @   s   e Zd Zdd Zdd ZdS )TestWithOptionalCudaGraphsc                 C   s<   t  }|jsJ t| |jrJ t| |jsJ d S r    )r   r   r   disable_cuda_graphs_recursiveenable_cuda_graphs_recursive)r
   module_with_graphsr   r   r   test_module_toggle_cuda_graphs5   s   



z9TestWithOptionalCudaGraphs.test_module_toggle_cuda_graphsc                 C   sP   t  }|jjjs
J tj|dd |jjjrJ tj|dd |jjjs&J d S )Nzdecoding.decoding)attribute_path)r&   r'   r   r   r)   r*   )r
   module_with_graphs_by_pathr   r   r   &test_module_toggle_cuda_graphs_by_path=   s   zATestWithOptionalCudaGraphs.test_module_toggle_cuda_graphs_by_pathN)r   r   r   r,   r/   r   r   r   r   r(   4   s    r(   )typesr   torch.nnr   2nemo.collections.common.parts.optional_cuda_graphsr   r   Moduler   r&   r(   r   r   r   r   <module>   s   	
