BaseModelInterface
BaseInferenceModel
Bases: ABC
Base class for inference models. This class should be extended by specific model implementations.
Source code in easyroutine/inference/base_model_interface.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | |
append_with_chat_template(message, role='user', chat_history=[])
Apply chat template to the message.
Source code in easyroutine/inference/base_model_interface.py
46 47 48 49 50 51 52 53 54 | |
chat(chat_messages, **kwargs)
abstractmethod
Generate a response based on the provided chat messages.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chat_messages
|
list
|
List of chat messages to process. |
required |
**kwargs
|
Additional parameters for the model. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
list
|
The generated response from the model. |
Source code in easyroutine/inference/base_model_interface.py
69 70 71 72 73 74 75 76 77 78 79 80 81 | |
convert_chat_messages_to_custom_format(chat_messages)
abstractmethod
Convert chat messages to a custom format required by the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chat_messages
|
List[dict[str, str]]
|
List of chat messages to convert. |
required |
Returns:
| Type | Description |
|---|---|
Union[List[dict[str, str]], str]
|
Union[List[dict[str, str]], str]: Converted chat messages in the required format. |
Source code in easyroutine/inference/base_model_interface.py
56 57 58 59 60 61 62 63 64 65 66 67 | |
init_model(model_name, n_gpus=1, dtype='bfloat16')
classmethod
Initialize the model with the given configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_name
|
str
|
Name of the model to initialize. |
required |
n_gpus
|
int
|
Number of GPUs to use. |
1
|
dtype
|
str
|
Data type for the model. |
'bfloat16'
|
Returns:
InferenceModel: An instance of the model.
Source code in easyroutine/inference/base_model_interface.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | |
BaseInferenceModelConfig
dataclass
Configuration for the model interface.
Source code in easyroutine/inference/base_model_interface.py
6 7 8 9 10 11 12 13 14 15 16 | |