-
Notifications
You must be signed in to change notification settings - Fork 141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Doc Strings to Config Files #465
base: main
Are you sure you want to change the base?
Changes from 22 commits
9334097
72534f6
f35ad57
e9d7bb0
291a92c
4f25938
bf50f2d
1a96a1f
3ca0960
bf65e27
9b753af
caae117
095f277
b10f9da
e3f6f13
79a3e35
4f7ee64
dda8266
5d225b3
262b1cd
4c33274
5815119
73af85b
ab38bd5
d809e39
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
model: | ||
base_params: | ||
model_name: "meta-llama/Llama-3.1-8B-Instruct" #Qwen/Qwen2.5-14B" #Qwen/Qwen2.5-7B" | ||
model_name: "meta-llama/Llama-3.1-8B-Instruct" #Qwen/Qwen2.5-14B" #Qwen/Qwen2.5-7B". #To see the full list of parameters, please see here: https://huggingface.co/docs/lighteval/package_reference/models#endpoints-based-models |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,15 +62,48 @@ | |
|
||
@dataclass | ||
class OpenAIModelConfig: | ||
""" | ||
Configuration class to create an [[OpenAIModel]], to call via its API at inference for evaluation. | ||
|
||
Attributes: | ||
model (str): name or identifier of the OpenAI model to be used for inference. | ||
generation_parameters(None,GenerationParameters): Parameters for model generation. If not | ||
provided, defaults to a new instance | ||
of `GenerationParameters`. | ||
""" | ||
|
||
model: str | ||
generation_parameters: GenerationParameters = None | ||
|
||
def __post_init__(self): | ||
""" | ||
|
||
Post-initialization that ensures the `generation_parameters` is set | ||
to a valid `GenerationParameters`. If not provided, initializes a default one. | ||
""" | ||
if not self.generation_parameters: | ||
self.generation_parameters = GenerationParameters() | ||
|
||
@classmethod | ||
def from_path(cls, path: str) -> "OpenAIModelConfig": | ||
""" | ||
Creates an instance of `OpenAIModelConfig` from a YAML configuration file. | ||
|
||
Loads the model configuration from a given file path and initializes the | ||
`OpenAIModelConfig` with the model name and corresponding `GenerationParameters` parsed | ||
from the file. | ||
|
||
Args: | ||
path (str): Path to the YAML configuration file containing the model configuration. | ||
|
||
Returns: | ||
OpenAIModelConfig: An instance of `OpenAIModelConfig` with the configuration loaded | ||
from the specified YAML file. | ||
|
||
Raises: | ||
FileNotFoundError: If the specified file path does not exist. | ||
KeyError: If required keys are missing in the YAML configuration file. | ||
""" | ||
import yaml | ||
|
||
with open(path, "r") as f: | ||
|
@@ -162,11 +195,11 @@ def greedy_until( | |
Generates responses using a greedy decoding strategy until certain ending conditions are met. | ||
|
||
Args: | ||
requests (list[Request]): list of requests containing the context and ending conditions. | ||
requests (list[GreedyUntilRequest]): list of requests containing the context and ending conditions. | ||
override_bs (int, optional): Override the batch size for generation. Defaults to None. | ||
|
||
Returns: | ||
list[GenerativeResponse]: list of generated responses. | ||
list [GenerativeResponse]: list of generated responses. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove extra space |
||
""" | ||
for request in requests: | ||
request.tokenized_context = self.tok_encode(request.context) | ||
|
@@ -251,7 +284,7 @@ def _loglikelihood_tokens( | |
), "Only single token continuations are supported when using openai API." | ||
|
||
for i in range(len(dataset)): | ||
logit_bias = {tok: 100 for tok in dataset[i].tokenized_continuation} | ||
logit_bias = dict.fromkeys(dataset[i].tokenized_continuation, 100) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please leave initial formulation |
||
logit_biass.append(logit_bias) | ||
|
||
outputs = self.__call_api_parallel( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,15 @@ def divide_chunks(array, n): | |
|
||
@dataclass | ||
class TGIModelConfig: | ||
""" | ||
Provides a streamlined configuration for integrating with Text Generation Inference (TGI) endpoints. To know more, please click here: https://huggingface.co/docs/text-generation-inference/index | ||
|
||
Attributes: | ||
inference_server_address (str, required):Endpoint address of the inference server hosting the model. | ||
inference_server_auth (str, required): Authentication credentials or tokens required to access the server. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it should only be a token |
||
model_id (str, required): Identifier for the model hosted on the inference server. | ||
""" | ||
|
||
inference_server_address: str | ||
inference_server_auth: str | ||
model_id: str | ||
|
ParagEkbote marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,7 @@ | |
import torch | ||
from transformers import AutoModelForCausalLM, PreTrainedTokenizer | ||
|
||
from lighteval.models.transformers.transformers_model import TransformersModel, TransformersModelConfig | ||
from lighteval.models.transformers.base_model import BaseModel, BaseModelConfig | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This path is incorrect |
||
from lighteval.models.utils import _get_dtype | ||
from lighteval.utils.imports import NO_PEFT_ERROR_MSG, is_peft_available | ||
from lighteval.utils.utils import EnvConfig | ||
|
@@ -40,7 +40,16 @@ | |
|
||
|
||
@dataclass | ||
class AdapterModelConfig(TransformersModelConfig): | ||
class AdapterModelConfig(BaseModelConfig): | ||
""" | ||
Manages the configuration of adapter models. Adapter models are designed to extend or adapt a | ||
base model's functionality for specific tasks while keeping most of the base model's parameters frozen. | ||
ParagEkbote marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Attributes: | ||
base_model (str): The name of the parent base model. This model provides the tokenizer and configuration for the adapter model. | ||
Defaults to None if not specified. | ||
""" | ||
|
||
# Adapter models have the specificity that they look at the base model (= the parent) for the tokenizer and config | ||
base_model: str = None | ||
|
||
|
@@ -54,11 +63,33 @@ def __post_init__(self): | |
return super().__post_init__() | ||
|
||
def init_configs(self, env_config: EnvConfig): | ||
""" | ||
Initializes the configurations of adapter models. | ||
|
||
Args: | ||
env_configs(EnvConfig): An instance of EnvConfig. | ||
|
||
Returns: | ||
Any: Result of the configuration initialization. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not informative, expand or remove |
||
""" | ||
return self._init_configs(self.base_model, env_config) | ||
|
||
|
||
class AdapterModel(TransformersModel): | ||
class AdapterModel(BaseModel): | ||
""" | ||
Integrates the adapter models with a pre-trained base model. | ||
""" | ||
Comment on lines
+79
to
+81
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be informative, it would be good to explain what adapter weights are. |
||
|
||
def _create_auto_tokenizer(self, config: AdapterModelConfig, env_config: EnvConfig) -> PreTrainedTokenizer: | ||
""" | ||
Creates and configures the adapter model by applying adapter weights to the base model. | ||
|
||
Args: | ||
config(AdapterModelConfig): An instance of AdapterModelConfig. | ||
env_config(EnvConfig): An instance of EnvConfig. | ||
|
||
Returns: PreTrainedTokenizer | ||
Comment on lines
+87
to
+91
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not adding new info, you can remove |
||
""" | ||
# By default, we look at the model config for the model stored in `base_model` | ||
# (= the parent model, not the model of interest) | ||
return self._create_auto_tokenizer_with_name( | ||
|
@@ -71,7 +102,15 @@ def _create_auto_tokenizer(self, config: AdapterModelConfig, env_config: EnvConf | |
) | ||
|
||
def _create_auto_model(self, config: AdapterModelConfig, env_config: EnvConfig) -> AutoModelForCausalLM: | ||
"""Returns a PeftModel from a base model and a version fined tuned using PEFT.""" | ||
""" | ||
Returns a PeftModel from a base model and a version fined tuned using PEFT. | ||
|
||
Args: | ||
config(AdapterModelConfig): An instance of AdapterModelConfig. | ||
env_config(EnvConfig): An instance of EnvConfig. | ||
|
||
Returns: AutoModelForCasualLM | ||
Comment on lines
+108
to
+112
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not adding new information, you should remove it |
||
""" | ||
torch_dtype = _get_dtype(config.dtype, self._config) | ||
config.model_parallel, max_memory, device_map = self.init_model_parallel(config.model_parallel) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,7 @@ | |
from tqdm import tqdm | ||
from transformers import AutoModelForCausalLM | ||
|
||
from lighteval.models.transformers.transformers_model import TransformersModel, TransformersModelConfig | ||
from lighteval.models.transformers.base_model import BaseModel, BaseModelConfig | ||
from lighteval.models.utils import _get_dtype, _get_model_sha | ||
from lighteval.utils.utils import EnvConfig | ||
|
||
|
@@ -37,7 +37,11 @@ | |
|
||
|
||
@dataclass | ||
class DeltaModelConfig(TransformersModelConfig): | ||
class DeltaModelConfig(BaseModelConfig): | ||
""" | ||
This class is used to manage the configuration class for delta models. | ||
""" | ||
Comment on lines
+41
to
+43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Explain what delta weights are |
||
|
||
# Delta models look at the pretrained (= the delta weights) for the tokenizer and model config | ||
base_model: str = None | ||
|
||
|
@@ -53,13 +57,21 @@ def get_model_sha(self): | |
return _get_model_sha(repo_id=self.pretrained, revision="main") | ||
|
||
|
||
class DeltaModel(TransformersModel): | ||
class DeltaModel(BaseModel): | ||
def _create_auto_model( | ||
self, | ||
config: DeltaModelConfig, | ||
env_config: EnvConfig, | ||
) -> AutoModelForCausalLM: | ||
"""Returns a model created by adding the weights of a delta model to a base model.""" | ||
""" | ||
It returns a model created by adding the weights of a delta model to a base model. | ||
|
||
Args: | ||
config(AdapterModelConfig): An instance of AdapterModelConfig. | ||
env_config(EnvConfig): An instance of EnvConfig. | ||
|
||
Returns: AutoModelForCasualLM | ||
Comment on lines
+69
to
+73
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The args and returns are not adding new ifnformation, remove |
||
""" | ||
config.model_parallel, max_memory, device_map = self.init_model_parallel(config.model_parallel) | ||
torch_dtype = _get_dtype(config.dtype, self._config) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't change the default model