o
    ÔÙ¾iç
  ã                   @   sp   d dl mZmZ d dlmZmZ d dlZd dlmZ er"d dl	m
Z
 ddgZG dd„ deƒZG d	d„ deƒZdS )
é    )ÚABCÚabstractmethod)ÚTYPE_CHECKINGÚOptionalN)ÚMoeRunnerConfig)ÚStandardDispatchOutputÚBaseLinearSchemeÚBaseMoESchemec                   @   sX   e Zd ZdZedd„ ƒZedejjfdd„ƒZ	edejjdej
deej
 fd	d
„ƒZdS )r   úu
    Abstract class used to describe the weight creation and forward pass
    of different quantization schemes.
    c                 O   ó   t ‚©zU
        Weight creation for the particular scheme. Inputs to this function

        ©ÚNotImplementedError©ÚselfÚargsÚkwargs© r   ú^/home/ubuntu/.local/lib/python3.10/site-packages/sglang/srt/layers/quantization/base_scheme.pyÚcreate_weights   ó   zBaseLinearScheme.create_weightsÚlayerc                 C   r   ©zf
        Called after weight loading is complete for any cleanup that
        needs to occur.
        r   ©r   r   r   r   r   Úprocess_weights_after_loading   r   z.BaseLinearScheme.process_weights_after_loadingÚxÚbiasc                 C   r   ©ag  
        Run the forward pass for the particular scheme. This is where
        scheme-specific dequant/quant steps/kernels should be applied.

        :param layer: torch.nn.Module with the registered weights and
            other parameters relevant to the particular scheme.
        :param x: input to the layer
        :param bias: bias parameter

        r   )r   r   r   r   r   r   r   Úapply_weights&   s   zBaseLinearScheme.apply_weightsN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   ÚtorchÚnnÚModuler   ÚTensorr   r   r   r   r   r   r      s    
ÿÿÿc                   @   sf   e Zd ZdZedd„ ƒZedejjde	fdd„ƒZ
edejjfdd	„ƒZedejjd
dfdd„ƒZdS )r	   r
   c                 O   r   r   r   r   r   r   r   r   =   r   zBaseMoEScheme.create_weightsr   Úmoe_runner_configc                 C   r   )Nr   )r   r   r'   r   r   r   Úcreate_moe_runnerE   s   zBaseMoEScheme.create_moe_runnerc                 C   r   r   r   r   r   r   r   r   K   r   z+BaseMoEScheme.process_weights_after_loadingÚdispatch_outputr   c                 C   r   r   r   )r   r   r)   r   r   r   r   S   s   zBaseMoEScheme.apply_weightsN)r   r    r!   r"   r   r   r#   r$   r%   r   r(   r   r   r   r   r   r   r	   7   s$    
ÿÿþý)Úabcr   r   Útypingr   r   r#   Úsglang.srt.layers.moer   Ú&sglang.srt.layers.moe.token_dispatcherr   Ú__all__r   r	   r   r   r   r   Ú<module>   s   '