Wrappers
Reference information for the language model Wrappers API.
eva.language.models.wrappers.HuggingFaceModel
Bases: LanguageModel
Wrapper class for loading HuggingFace transformers models.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_name_or_path |
str
|
The model name or path to load the model from.
This can be a local path or a model name from the |
required |
model_class |
str
|
The class of the model to use (e.g., "AutoModelForCausalLM"). |
required |
model_kwargs |
Dict[str, Any] | None
|
Additional arguments for configuring the model. |
None
|
system_prompt |
str | None
|
System prompt to use. |
None
|
processor_kwargs |
Dict[str, Any] | None
|
Additional processor/tokenizer arguments. |
None
|
generation_kwargs |
Dict[str, Any] | None
|
Additional generation parameters (temperature, max_length, etc.). |
None
|
chat_template |
str | None
|
Optional chat template name to use with the processor. If None, will use the template stored in the checkpoint's processor config. |
None
|
Source code in src/eva/language/models/wrappers/huggingface.py
configure_model
Use configure_model hook to load model in lazy fashion.
Source code in src/eva/language/models/wrappers/huggingface.py
load_model
Loads the model from HuggingFace.
Raises:
| Type | Description |
|---|---|
ValueError
|
If the model class is not found in transformers or if the model does not support generation. |
Source code in src/eva/language/models/wrappers/huggingface.py
load_processor
Initialize the processor.
Note: For text-only models, AutoProcessor returns the tokenizer.
Source code in src/eva/language/models/wrappers/huggingface.py
format_inputs
Formats inputs for HuggingFace models.
Note: If multiple system messages are present, they will be combined into a single message, given that many models only support a single system prompt.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch |
TextBatch
|
A batch of text inputs. |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Tensor]
|
A dictionary produced by the tokenizer following a format like: |
Dict[str, Tensor]
|
{ "input_ids": ..., "attention_mask": ..., |
Dict[str, Tensor]
|
} |
Source code in src/eva/language/models/wrappers/huggingface.py
model_forward
Generates text using the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch |
Dict[str, Tensor]
|
A dictionary containing the tokenized input data. |
required |
Returns:
| Type | Description |
|---|---|
ModelOutput
|
The model output containing generated text. |
Source code in src/eva/language/models/wrappers/huggingface.py
eva.language.models.wrappers.LiteLLMModel
Bases: LanguageModel
Wrapper class for LiteLLM language models.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_name |
str
|
The name of the model to use. |
required |
model_kwargs |
Dict[str, Any] | None
|
Additional keyword arguments to pass during
generation (e.g., |
None
|
system_prompt |
str | None
|
The system prompt to use (optional). |
None
|
log_level |
int | None
|
Optional logging level for LiteLLM. Defaults to WARNING. |
INFO
|
Source code in src/eva/language/models/wrappers/litellm.py
format_inputs
Formats inputs for LiteLLM.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch |
TextBatch
|
A batch of text inputs. |
required |
Returns:
| Type | Description |
|---|---|
List[List[Dict[str, Any]]]
|
A list of messages in the following format: |
List[List[Dict[str, Any]]]
|
[ { "role": ... "content": ... }, ... |
List[List[Dict[str, Any]]]
|
] |
Source code in src/eva/language/models/wrappers/litellm.py
model_forward
Generates output text through API calls via LiteLLM's batch completion functionality.
Source code in src/eva/language/models/wrappers/litellm.py
eva.language.models.wrappers.VllmModel
Bases: LanguageModel
Wrapper class for using vLLM for text generation.
This wrapper loads a vLLM model, sets up the tokenizer and sampling parameters, and uses a chat template to format inputs for generation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_name_or_path |
str
|
The model identifier - e.g., a HuggingFace repo ID or local path). Note that the model must be compatible with vLLM. |
required |
model_kwargs |
Dict[str, Any] | None
|
Arguments required to initialize the vLLM model, see link for more information. |
None
|
system_prompt |
str | None
|
System prompt to use. |
None
|
generation_kwargs |
Dict[str, Any] | None
|
Arguments required to generate the output. See vllm.SamplingParams. |
None
|
chat_template |
str | None
|
Optional chat template name to use with the tokenizer. If None, will use the template stored in the checkpoint's tokenizer config. |
None
|
Source code in src/eva/language/models/wrappers/vllm.py
configure_model
Use configure_model hook to load model in lazy fashion.
Source code in src/eva/language/models/wrappers/vllm.py
load_model
Loads the vLLM model.
Source code in src/eva/language/models/wrappers/vllm.py
load_tokenizer
Loads the tokenizer.
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the tokenizer does not have a chat template. |
Source code in src/eva/language/models/wrappers/vllm.py
format_inputs
Formats inputs for vLLM models.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch |
TextBatch
|
A batch of text inputs. |
required |
Returns:
| Type | Description |
|---|---|
List[Dict[str, Any]]
|
A list of input dictionaries with "prompt" key. |
Source code in src/eva/language/models/wrappers/vllm.py
model_forward
Generates text using the vLLM model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch |
List[Dict[str, Any]]
|
A list of input dictionaries containing "prompt" key
(output of |
required |
Returns:
| Type | Description |
|---|---|
ModelOutput
|
ModelOutput containing the generated text responses. |