o
    *j                     @   s   d dl mZ d dlmZmZ d dlZd dlmZmZm	Z	 d dl
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 e ZdgZejejejdG dd deeZdS )    )OrderedDict)Dict	GeneratorN)
AutoConfigAutoModelForCausalLMAutoTokenizer)Models)Tensor
TorchModel)MODELS)Tasks)
get_logger)StreamingOutputMixinPolyLMForTextGeneration)module_namec                       sf   e Zd Zdef fddZ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 )
r   	model_dirc                    sd   t  j|g|R i | tj|ddd| _| jd| d|d tj|d| jd| _| j	  dS )	zinitialize the text generation model from the `model_dir` path.

        Args:
            model_dir (str): the model path.
        F)legacyZuse_fastz3Use trust_remote_code=True. Will invoke codes from z9. Please make sure that you can trust the external codes.)Zinfo_strr   auto)Z
device_maptrust_remote_codeN)
super__init__r   Zfrom_pretrained	tokenizerZcheck_trust_remote_coder   r   modeleval)selfr   argskwargs	__class__ m/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/modelscope/models/nlp/polylm/text_generation.pyr      s   
z PolyLMForTextGeneration.__init__inputreturnc                 K   s   | j |fi |}|S )zreturn the result by the model

        Args:
            input (Dict[str, Tensor]): the preprocessed data

        Returns:
            Dict[str, Tensor]: results
        )generate)r   r!   r   resr   r   r    forward-   s   	zPolyLMForTextGeneration.forwardc                 K   sV   | j j}| j|dd}| j j|j|fd|j|i|}| jj|d dd}|S )Npt)Zreturn_tensorsattention_maskr   T)Zskip_special_tokens)r   devicer   r#   Z	input_idstor'   decode)r   r!   r   r(   ZinputsZoutputspredr   r   r    r#   9   s   

z PolyLMForTextGeneration.generate)
__name__
__module____qualname__strr   r   r	   r%   r#   __classcell__r   r   r   r    r      s    "
)collectionsr   typingr   r   ZtorchZtransformersr   r   r   Zmodelscope.metainfor   Zmodelscope.models.baser	   r
   Zmodelscope.models.builderr   Zmodelscope.utils.constantr   Zmodelscope.utils.loggerr   Z!modelscope.utils.streaming_outputr   logger__all__Zregister_moduleZtext_generationZpolylmr   r   r   r   r    <module>   s   