o
    ॵi
                     @   sZ   d dl Zd dlmZ d dlmZmZ d dlZd dl	m
Z
mZ d dlmZ G dd dZdS )    N)abstractmethod)ListUnion)read_configsnapshot_download)Configc                   @   sv   e Zd ZdefddZedeee eee  f dee fddZ	defd	d
Z
edefddZedddZdS )InferFrameworkmodel_id_or_dirc                 K   s   t j|r
|| _nt|| _| |}t| j}|d}|dur)|p(| |}t j| jd}t j	|rLt
|}|d}|durL|pK| |}|sUtd| dS )z
        Args:
            model_id_or_dir(`str`): The model id of the modelhub or a local dir containing model files.
        z
model.typeNzconfig.json
model_typez"Model accelerating not supported: )ospathexists	model_dirr   model_type_supportedr   safe_getjoinisfiler   	from_file
ValueError)selfr	   kwargsmodel_supportedconfigr
   config_file r   X/home/ubuntu/.local/lib/python3.10/site-packages/modelscope/pipelines/accelerate/base.py__init__   s.   





zInferFramework.__init__promptsreturnc                 K      dS )z
        Args:
            prompts(`Union[List[str], List[List[int]]]`):
                The string batch or the token list batch to input to the model.
        Returns:
            The answers in list according to the input prompt batch.
        Nr   )r   r   r   r   r   r   __call__)   s   
zInferFramework.__call__r
   c                 C   r   )NFr   )r   r
   r   r   r   r   5   s   z#InferFramework.model_type_supportedmajor_versionc                 C   s   t j \}}|| kS )z%Check the GPU compatibility.
        )torchcudaget_device_capability)r!   major_r   r   r   check_gpu_compatibility8   s   z&InferFramework.check_gpu_compatibilityvllmc                 K   s<   |dkrddl m} ||fi |}||_|S td| )a  Instantiate the model wrapped by an accelerate framework.
        Args:
            model_id_or_dir(`str`): The model id of the modelhub or a local dir containing model files.
            framework(`str`): The framework to use.
        Returns:
            The wrapped model.
        r(      )VllmzFramework not supported: )r(   r*   llm_frameworkr   )clsr	   	frameworkr   r*   r(   r   r   r   from_pretrained?   s   	zInferFramework.from_pretrainedN)r(   )__name__
__module____qualname__strr   r   r   r   intr    r   staticmethodr'   classmethodr.   r   r   r   r   r      s    r   )os.pathr   abcr   typingr   r   
torch.cudar"   
modelscoper   r   modelscope.utils.configr   r   r   r   r   r   <module>   s    