o
    ߥi                     @   s   d Z 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 d	d
lmZ e Zg Ze	jejejdG dd deeZdS )zSPyTorch Veco model. mainly copied from :module:`~transformers.modeling_xlm_roberta`    )RobertaModel)Models)Model
TorchModel)MODELS)AttentionBackboneModelOutput)logger)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 )	VecoModela4  The bare Veco Model transformer outputting raw hidden-states without any specific head on top.

    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.

    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 [`RobertaModel`]. 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__ W/home/ubuntu/.local/lib/python3.10/site-packages/modelscope/models/nlp/veco/backbone.pyr   :   s   zVecoModel.__init__c                    s>   d|d< t t| j|i |}t|j|j|j|j|j|j	dS )u  
        Returns:
            Returns `modelscope.outputs.AttentionBackboneModelOutputWithEmbedding`

        Examples:
            >>> from modelscope.models import Model
            >>> from modelscope.preprocessors import Preprocessor
            >>> model = Model.from_pretrained('damo/nlp_veco_fill-mask-large', task='backbone')
            >>> preprocessor = Preprocessor.from_pretrained('damo/nlp_veco_fill-mask-large')
            >>> print(model(**preprocessor('这是个测试')))

        Treturn_dict)last_hidden_statepooler_outputpast_key_valueshidden_states
attentionscross_attentions)
r   r   forwardr   r   r   r   r   r   r   )r   argsr   outputsr   r   r   r   >   s   zVecoModel.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   _instantiateV   s   zVecoModel._instantiate)__name__
__module____qualname____doc__r   config_classr   r   classmethodr)   __classcell__r   r   r   r   r   "   s    r   N)r-   transformersr   modelscope.metainfor   modelscope.modelsr   r   modelscope.models.builderr   modelscope.outputsr   modelscope.utilsr   loggingmodelscope.utils.constantr	   configurationr   
get_logger"VECO_PRETRAINED_MODEL_ARCHIVE_LISTregister_modulebackbonevecor   r   r   r   r   <module>   s   