o
    i                     @   s    d dl Z G dd de jjZdS )    Nc                       s6   e Zd ZdZdejjdef fddZdd Z	  Z
S )ForwardAdaptora  Wrapped module to parallelize specified method

    torch.nn.DataParallel parallelizes only "forward()"
    and, maybe, the method having the other name can't be applied
    except for wrapping the module just like this class.

    Examples:
        >>> class A(torch.nn.Module):
        ...     def foo(self, x):
        ...         ...
        >>> model = A()
        >>> model = ForwardAdaptor(model, "foo")
        >>> model = torch.nn.DataParallel(model, device_ids=[0, 1])
        >>> x = torch.randn(2, 10)
        >>> model(x)
    modulenamec                    s6   t    || _|| _t||st| d| d S )Nz doesn't have )super__init__r   r   hasattr
ValueError)selfr   r   	__class__ V/home/ubuntu/.local/lib/python3.10/site-packages/funasr/train_utils/forward_adaptor.pyr      s   

zForwardAdaptor.__init__c                 O   s   t | j| j}||i |S )N)getattrr   r   )r	   argskwargsfuncr   r   r   forward   s   zForwardAdaptor.forward)__name__
__module____qualname____doc__torchnnModulestrr   r   __classcell__r   r   r
   r   r      s    r   )r   r   r   r   r   r   r   r   <module>   s    