o
    ॵi
                     @   s   d dl mZmZmZmZ d dlZd dlmZmZ d dl	m
Z
mZ d dlmZ d dlmZ d dlmZ d dlmZmZ d d	lmZ e Zejejejd
G dd deZdS )    )AnyDictOptionalUnionN)	PipelinesPreprocessors)ModelPipeline)	PIPELINES)batch_process)Preprocessor)FieldsTasks)
get_logger)module_namec                	       s   e Zd Z				ddeeef dee dedef fdd	Z fd
dZ	de
eef de
eef f fddZde
eef de
eef fddZ  ZS )SummarizationPipelineNgpuTmodelpreprocessorconfig_filedevicec                    st   t  j|||||d | j  |du r8| jjjdkr*tj| jjt	j
tjd| _dS tj| jjfi || _dS dS )a  Use `model` and `preprocessor` to create a Summarization pipeline for prediction.

        Args:
            model (str or Model): Supply either a local model dir which supported the summarization task,
            or a model id from the model hub, or a model instance.
            preprocessor (Preprocessor): An optional preprocessor instance.
            kwargs (dict, `optional`):
                Extra kwargs passed into the preprocessor's constructor.
        )r   r   r   r   auto_collateNOfaForAllTasks)typefield)super__init__r   eval	__class____name__r   from_pretrained	model_dirr   ofa_tasks_preprocessorr   multi_modalr   )selfr   r   r   r   r   kwargsr    c/home/ubuntu/.local/lib/python3.10/site-packages/modelscope/pipelines/nlp/summarization_pipeline.pyr      s*   
zSummarizationPipeline.__init__c                    s*   | j jjdkrt| j |S tt| |S )Nr   )r   r   r   r   r   r   _batch)r$   datar&   r'   r(   r)   6   s   zSummarizationPipeline._batchinputsreturnc                    s@   t   t j|fi |W  d    S 1 sw   Y  d S N)torchno_gradr   forward)r$   r+   forward_paramsr&   r'   r(   r0   <   s   
$zSummarizationPipeline.forwardc                 C   s   |S r-   r'   )r$   r+   r'   r'   r(   postprocessA   s   z!SummarizationPipeline.postprocess)NNr   T)r   
__module____qualname__r   r   strr   r   r   r)   r   r   r0   r2   __classcell__r'   r'   r&   r(   r      s&    
!
*r   )typingr   r   r   r   r.   modelscope.metainfor   r   modelscope.pipelines.baser   r	   modelscope.pipelines.builderr
   modelscope.pipelines.utilr   modelscope.preprocessorsr   modelscope.utils.constantr   r   modelscope.utils.loggerr   loggerregister_moduletext_summarizationtext_generationr   r'   r'   r'   r(   <module>   s   