o
    ߥi                     @   s   d dl 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jejejd	G d
d deeZdS )    )RobertaForMaskedLM)Models)Model
TorchModel)MODELS)AttentionFillMaskModelOutput)Tasks   )
VecoConfig)module_namec                       s@   e Zd ZdZeZ fddZ fddZe fddZ	  Z
S )VecoForMaskedLMa  Veco Model transformer with a masked language model head on top (a linear layer on top of the
    pooled output).

    This model inherits from [`PreTrainedModel`]. Check the superclass documentation for the generic
    methods the library implements for all its model (such as downloading or saving, resizing the input embeddings,
    pruning heads etc.)

    This model is also a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module)
    subclass. Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to
    general usage and behavior.

    Preprocessor:
        This is the fill_mask model of StructBERT, the preprocessor of this model
        is `modelscope.preprocessors.FillMaskTransformersPreprocessor`.

    Parameters:
        config ([`VecoConfig`]): Model configuration class with all the parameters of the
            model. Initializing with a config file does not load the weights associated with the model, only the
            configuration. Check out the [`~PreTrainedModel.from_pretrained`] method to load the model
            weights.

    This class overrides [`RobertaForMaskedLM`]. Please check the superclass for the
    appropriate documentation alongside usage examples.
    c                    s*   t  j|jfi | t t| | d S )N)super__init__name_or_pathr   )selfconfigkwargs	__class__ X/home/ubuntu/.local/lib/python3.10/site-packages/modelscope/models/nlp/veco/fill_mask.pyr   9   s   zVecoForMaskedLM.__init__c                    s<   d|d< t t| j|i |}t|j|j|j|j|d dS )uK  
        Returns:
            Returns `modelscope.outputs.AttentionFillMaskModelOutput`

        Examples:
            >>> from modelscope.models import Model
            >>> from modelscope.preprocessors import Preprocessor
            >>> model = Model.from_pretrained('damo/nlp_veco_fill-mask-large')
            >>> preprocessor = Preprocessor.from_pretrained('damo/nlp_veco_fill-mask-large')
            >>> # Call the model, return some tensors
            >>> print(model(**preprocessor('你师父差得动你，你师父可<mask>不动我。')))
            >>> # Call the pipeline
            >>> from modelscope.pipelines import pipeline
            >>> pipeline_ins = pipeline('fill-mask', model=model, preprocessor=preprocessor)
            >>> print(pipeline_ins('你师父差得动你，你师父可<mask>不动我。'))
        Treturn_dict	input_ids)losslogitshidden_states
attentionsr   )r   r   forwardr   r   r   r   r   )r   argsr   outputsr   r   r   r   =   s   zVecoForMaskedLM.forwardc                    sD   | dd }|d u rtdi |}| |}|S tt| j|d}|S )N	model_dir)pretrained_model_name_or_pathr   )popr
   r   r   from_pretrained)clsr   r    ponet_configmodelr   r   r   _instantiateY   s   zVecoForMaskedLM._instantiate)__name__
__module____qualname____doc__r
   config_classr   r   classmethodr'   __classcell__r   r   r   r   r      s    r   N)transformersr   modelscope.metainfor   modelscope.modelsr   r   modelscope.models.builderr   modelscope.outputsr   modelscope.utils.constantr   configurationr
   register_module	fill_maskvecor   r   r   r   r   <module>   s   