o
    *j;                     @   s   d dl 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 d dlmZ ejejejd	G d
d de	ZdS )    )AnyDictN)	Pipelines)DistributedGPTMoE)DistributedPipeline)	PIPELINES)TextGenerationJiebaPreprocessor)Tasks)module_namec                       sz   e Zd ZdZdZd fdd	Zedd Zedee	e
f dee	e
f fd	d
Zdee	e
f dee	e	f fddZ  ZS )DistributedGPTMoEPipelinez9This class is used to instantiate the gpt-moe model.
    Nc                    s:   |d u rt |}t j|fd|i| t|dsJ d S )Npreprocessor	tokenizer)r   super__init__hasattr)selfmodelr   kwargs	__class__ v/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/modelscope/pipelines/nlp/distributed_gpt_moe_pipeline.pyr      s   z"DistributedGPTMoEPipeline.__init__c                 K   s"   t ||fi || _| j  d S N)r   r   eval)clsrankZ	model_dirr   r   r   r   _instantiate_one   s   z*DistributedGPTMoEPipeline._instantiate_oneinputsreturnc                 C   s$   |d d  tj  }| j|S )Nr   Z	input_ids)cudatorchZcurrent_devicer   generate)r   r   tokensr   r   r   _forward_one"   s   z&DistributedGPTMoEPipeline._forward_onec                 K   s*   ddl m} |j| jj|jd  iS )zprocess the prediction results

        Args:
            inputs (Dict[str, Any]): _description_

        Returns:
            Dict[str, str]: the prediction results
        r   )
OutputKeys)Zmodelscope.outputsr$   ZTEXTr   r   Z
detokenize	sequencestolist)r   r   Zpostprocess_paramsr$   r   r   r   postprocess(   s   
z%DistributedGPTMoEPipeline.postprocessr   )__name__
__module____qualname____doc__r   r   classmethodr   r   strr   r#   r'   __classcell__r   r   r   r   r      s    
$
r   )typingr   r   r    Zmodelscope.metainfor   Z1modelscope.models.nlp.gpt_moe.distributed_gpt_moer   Zmodelscope.pipelines.baser   Zmodelscope.pipelines.builderr   Zmodelscope.preprocessorsr   Zmodelscope.utils.constantr	   Zregister_moduleZtext_generationZgpt_moe_generationr   r   r   r   r   <module>   s   