o
    ߥim                     @   s   d 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
mZ ddlmZ ddlmZ dd	lmZ e ZG d
d dZG dd deeeZejejejdejejejdG dd deeeZdS )z PyTorch LLaMA model.    )LlamaConfig)
LlamaModel)LlamaPreTrainedModel)Models)Model
TorchModel)MODELS)Tasks)
get_loggerc                       s    e Zd Ze fddZ  ZS )MsModelMixinc                    sv   | dd}| dd}|du rtdi |}| |}ntt| jdd|i|}||_d|v s4|du r6|S ||S )ah  Instantiate the model.

        Args:
            kwargs: Input args.
                    model_dir: The model dir used to load the checkpoint and the label information.
                    num_labels: An optional arg to tell the model how many classes to initialize.
                                    Method will call utils.parse_label_mapping if num_labels not supplied.
                                    If num_labels is not found, the model will use the default setting (2 classes).

        Returns:
            The loaded model, which is initialized by transformers.PreTrainedModel.from_pretrained
        	model_dirNdevicepretrained_model_name_or_path
device_map )popr   superr   from_pretrainedr   to)clskwargsr   r   configmodel	__class__r   X/home/ubuntu/.local/lib/python3.10/site-packages/modelscope/models/nlp/llama/backbone.py_instantiate%   s    
zMsModelMixin._instantiate)__name__
__module____qualname__classmethodr   __classcell__r   r   r   r   r   #   s    r   c                   @      e Zd ZdS )r   Nr   r   r   r   r   r   r   r   @   s    r   )module_namec                   @   r"   )r   Nr#   r   r   r   r   r   D   s    r   N)__doc__transformers.models.llamar   r   LlamaModelHFr   LlamaPreTrainedModelHFmodelscope.metainfor   modelscope.modelsr   r   modelscope.models.builderr   modelscope.utils.constantr	   modelscope.utils.loggerr
   loggerr   register_modulebackbonellama2llamar   r   r   r   <module>   s   