
    vj
                     h    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          ZdS )    N)abstractmethod)ListUnion)read_configsnapshot_download)Configc                       e Zd ZdefdZedeee         eee                  f         dee         fd            Z	defdZ
edefd	            Zedd            ZdS )InferFrameworkmodel_id_or_dirc                 ^   t           j                            |          r|| _        nt	          |          | _        |                     |          }t          | j                  }|                    d          }||p|                     |          }t           j                            | j        d          }t           j        	                    |          rBt          j        |          }|                    d          }||p|                     |          }|st          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_files          t/lsinfo/ai/hellotax_ai/data_center/backend/venv/lib/python3.11/site-packages/modelscope/pipelines/accelerate/base.py__init__zInferFramework.__init__   s5   
 7>>/** 	@,DNN.??DN33ODD$T^44__\22
!- 1J1J2 2Ogll4>=AA7>>+&& 	 %k22F66J%"1 # T5N5N6  6   	HF_FFH H H	H 	H    promptsreturnc                     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.
        N )r   r    r   s      r   __call__zInferFramework.__call__)   s	     	r   r   c                     dS )NFr#   )r   r   s     r   r   z#InferFramework.model_type_supported5   s    ur   major_versionc                 P    t           j                                        \  }}|| k    S )z%Check the GPU compatibility.
        )torchcudaget_device_capability)r&   major_s      r   check_gpu_compatibilityz&InferFramework.check_gpu_compatibility8   s&     :3355q%%r   vllmc                 b    |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.   r1   llm_frameworkr   )clsr   	frameworkr   r1   r.   s         r   from_pretrainedzInferFramework.from_pretrained?   s\     """"""422622D!*DKDDDEEEr   N)r.   )__name__
__module____qualname__strr   r   r   r   intr$   r   staticmethodr-   classmethodr5   r#   r   r   r
   r
      s        H H H H H8 	d3id3i&@ A 	"3i	 	 	 ^	s     &s & & & \& F F F [F F Fr   r
   )os.pathr   abcr   typingr   r   
torch.cudar(   
modelscoper   r   modelscope.utils.configr   r
   r#   r   r   <module>rC      s                       5 5 5 5 5 5 5 5 * * * * * *CF CF CF CF CF CF CF CF CF CFr   