o
    TÃib  ã                   @   sŒ   d dl mZ d dlmZmZmZmZ 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 G dd„ deƒZG dd„ deƒZdS )é    )Úabstractmethod)ÚAnyÚDictÚOptionalÚTypeN)ÚDeepSpeedConfigModelé   )ÚDSModuleBase)ÚDSModuleRegistryBase©ÚDSLinearConfigé   )ÚInferenceParameterc                	       s¤   e Zd ZdZedee fdd„ƒZdede	e
ef ddf‡ fdd	„Zed
ejdefdd„ƒZddejdejdeej dejfdd„Zeedejfdd„ƒƒZ‡  ZS )ÚDSLinearBasea&  
    Base mixin for all Linear modules. The interface represented by this module
    is:

    hidden_out = activation(hidden_in * weight + bias)

    The format and dtype of the weight and bias tensors are not defined and implementations
    may compress as necessary. Must support a bias.
    Úreturnc                   C   ó   t S ©Nr   © r   r   úi/home/ubuntu/.local/lib/python3.10/site-packages/deepspeed/inference/v2/modules/interfaces/linear_base.pyÚconfig_class   ó   zDSLinearBase.config_classÚconfigÚimplementation_configNc                    s   t ƒ  ||¡ d S r   )ÚsuperÚ__init__)Úselfr   r   ©Ú	__class__r   r   r   !   s   zDSLinearBase.__init__Úparamc                 C   ó   dS )z§
        Perform any necessary transformations of the parameters of this module.

        Parameters:
            param (torch.Tensor): Weight or bias tensor.
        Nr   )r   r   r   r   r   Útransform_param$   s   zDSLinearBase.transform_paramÚhidden_statesÚwÚbc                 C   s   t ƒ ‚)aF  
        Parameters:
            hidden_states (torch.Tensor): Hidden states tensor. Expected shape is either
                [batch, seq_len, in_channels] or [batch, in_channels].

        Returns:
            torch.Tensor: Output tensor. Tensor should have same number of dimensions as
                input tensor.
        )ÚNotImplementedError)r   r!   r"   r#   r   r   r   Úforward.   s   
zDSLinearBase.forwardc                 C   r   )zA
        Return the padded, pre-allocated output Tensor.
        Nr   )r   r   r   r   Úoutput:   s   zDSLinearBase.outputr   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ústaticmethodr   r   r   r   r   Ústrr   r   r   ÚtorchÚTensorr   r    r   r%   Úpropertyr&   Ú__classcell__r   r   r   r   r      s    
"(	r   c                   @   s0   e Zd ZU i Zeed< edee fdd„ƒZ	dS )ÚDSLinearRegistryÚregistryr   c                   C   r   r   )r   r   r   r   r   Úassociated_classF   r   z!DSLinearRegistry.associated_classN)
r'   r(   r)   r2   r   Ú__annotations__r+   r   r	   r3   r   r   r   r   r1   C   s   
 r1   )Úabcr   Útypingr   r   r   r   r-   Údeepspeed.runtime.config_utilsr   Ú	ds_moduler	   Úmodule_registryr
   Úconfigsr   Úinference_parameterr   r   r1   r   r   r   r   Ú<module>   s   1