-
Notifications
You must be signed in to change notification settings - Fork 162
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
Let lighteval support sglang #552
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f39de46
support sglang
Jayon02 22dc29b
output bugs
Jayon02 b23063b
Update vllm_output.txt
Jayon02 85954f2
fix outputs bug
Jayon02 75290a9
Merge branch 'main' of https://github.com/Jayon02/lighteval
Jayon02 985d366
fix outputs bug
Jayon02 c395b1e
adjust precision
9c0f7cb
adjust precision
b733c86
Squashed commit of the following:
Jayon02 2358360
Update use-sglang-as-backend.mdx
Jayon02 50f3695
Merge remote-tracking branch 'upstream/main'
Jayon02 d8841a9
Squashed commit of the following:
Jayon02 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# Use SGLang as backend | ||
|
||
Lighteval allows you to use `sglang` as backend allowing great speedups. | ||
To use, simply change the `model_args` to reflect the arguments you want to pass to sglang. | ||
|
||
```bash | ||
lighteval sglang \ | ||
"pretrained=HuggingFaceH4/zephyr-7b-beta,dtype=float16" \ | ||
"leaderboard|truthfulqa:mc|0|0" | ||
``` | ||
|
||
`sglang` is able to distribute the model across multiple GPUs using data | ||
parallelism and tensor parallelism. | ||
You can choose the parallelism method by setting in the the `model_args`. | ||
|
||
For example if you have 4 GPUs you can split it across using `tp_size`: | ||
|
||
```bash | ||
lighteval sglang \ | ||
"pretrained=HuggingFaceH4/zephyr-7b-beta,dtype=float16,tp_size=4" \ | ||
"leaderboard|truthfulqa:mc|0|0" | ||
``` | ||
|
||
Or, if your model fits on a single GPU, you can use `dp_size` to speed up the evaluation: | ||
|
||
```bash | ||
lighteval sglang \ | ||
"pretrained=HuggingFaceH4/zephyr-7b-beta,dtype=float16,dp_size=4" \ | ||
"leaderboard|truthfulqa:mc|0|0" | ||
``` | ||
|
||
## Use a config file | ||
|
||
For more advanced configurations, you can use a config file for the model. | ||
An example of a config file is shown below and can be found at `examples/model_configs/sglang_model_config.yaml`. | ||
|
||
```bash | ||
lighteval sglang \ | ||
"examples/model_configs/sglang_model_config.yaml" \ | ||
"leaderboard|truthfulqa:mc|0|0" | ||
``` | ||
|
||
```yaml | ||
model: # Model specific parameters | ||
base_params: | ||
model_args: "pretrained=HuggingFaceTB/SmolLM-1.7B,dtype=float16,chunked_prefill_size=4096,mem_fraction_static=0.9" # Model args that you would pass in the command line | ||
generation: # Generation specific parameters | ||
temperature: 0.3 | ||
repetition_penalty: 1.0 | ||
frequency_penalty: 0.0 | ||
presence_penalty: 0.0 | ||
top_k: -1 | ||
min_p: 0.0 | ||
top_p: 0.9 | ||
max_new_tokens: 256 | ||
stop_tokens: ["<EOS>", "<PAD>"] | ||
``` | ||
|
||
> [!WARNING] | ||
> In the case of OOM issues, you might need to reduce the context size of the | ||
> model as well as reduce the `mem_fraction_static` and `chunked_prefill_size` parameter. | ||
NathanHB marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
model: | ||
base_params: | ||
model_args: "pretrained=HuggingFaceTB/SmolLM-1.7B,dtype=float16,chunked_prefill_size=4096,mem_fraction_static=0.9" | ||
generation: | ||
temperature: 0.3 | ||
repetition_penalty: 1.0 | ||
frequency_penalty: 0.0 | ||
presence_penalty: 0.0 | ||
top_k: -1 | ||
min_p: 0.0 | ||
top_p: 0.9 | ||
max_new_tokens: 256 | ||
stop_tokens: ["<EOS>", "<PAD>"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
# MIT License | ||
|
||
# Copyright (c) 2024 The SGLang Team | ||
|
||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
|
||
# The above copyright notice and this permission notice shall be included in all | ||
# copies or substantial portions of the Software. | ||
|
||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
# SOFTWARE. | ||
import os | ||
from typing import Optional | ||
|
||
from typer import Argument, Option | ||
from typing_extensions import Annotated | ||
|
||
|
||
TOKEN = os.getenv("HF_TOKEN") | ||
CACHE_DIR: str = os.getenv("HF_HOME", "/scratch") | ||
|
||
HELP_PANEL_NAME_1 = "Common Parameters" | ||
HELP_PANEL_NAME_2 = "Logging Parameters" | ||
HELP_PANEL_NAME_3 = "Debug Parameters" | ||
HELP_PANEL_NAME_4 = "Modeling Parameters" | ||
|
||
|
||
def sglang( | ||
# === general === | ||
model_args: Annotated[ | ||
str, | ||
Argument( | ||
help="Model arguments in the form key1=value1,key2=value2,... or path to yaml config file (see examples/model_configs/transformers_model.yaml)" | ||
), | ||
], | ||
tasks: Annotated[str, Argument(help="Comma-separated list of tasks to evaluate on.")], | ||
# === Common parameters === | ||
use_chat_template: Annotated[ | ||
bool, Option(help="Use chat template for evaluation.", rich_help_panel=HELP_PANEL_NAME_4) | ||
] = False, | ||
system_prompt: Annotated[ | ||
Optional[str], Option(help="Use system prompt for evaluation.", rich_help_panel=HELP_PANEL_NAME_4) | ||
] = None, | ||
dataset_loading_processes: Annotated[ | ||
int, Option(help="Number of processes to use for dataset loading.", rich_help_panel=HELP_PANEL_NAME_1) | ||
] = 1, | ||
custom_tasks: Annotated[ | ||
Optional[str], Option(help="Path to custom tasks directory.", rich_help_panel=HELP_PANEL_NAME_1) | ||
] = None, | ||
cache_dir: Annotated[ | ||
str, Option(help="Cache directory for datasets and models.", rich_help_panel=HELP_PANEL_NAME_1) | ||
] = CACHE_DIR, | ||
num_fewshot_seeds: Annotated[ | ||
int, Option(help="Number of seeds to use for few-shot evaluation.", rich_help_panel=HELP_PANEL_NAME_1) | ||
] = 1, | ||
load_responses_from_details_date_id: Annotated[ | ||
Optional[str], Option(help="Load responses from details directory.", rich_help_panel=HELP_PANEL_NAME_1) | ||
] = None, | ||
# === saving === | ||
output_dir: Annotated[ | ||
str, Option(help="Output directory for evaluation results.", rich_help_panel=HELP_PANEL_NAME_2) | ||
] = "results", | ||
push_to_hub: Annotated[ | ||
bool, Option(help="Push results to the huggingface hub.", rich_help_panel=HELP_PANEL_NAME_2) | ||
] = False, | ||
push_to_tensorboard: Annotated[ | ||
bool, Option(help="Push results to tensorboard.", rich_help_panel=HELP_PANEL_NAME_2) | ||
] = False, | ||
public_run: Annotated[ | ||
bool, Option(help="Push results and details to a public repo.", rich_help_panel=HELP_PANEL_NAME_2) | ||
] = False, | ||
results_org: Annotated[ | ||
Optional[str], Option(help="Organization to push results to.", rich_help_panel=HELP_PANEL_NAME_2) | ||
] = None, | ||
save_details: Annotated[ | ||
bool, Option(help="Save detailed, sample per sample, results.", rich_help_panel=HELP_PANEL_NAME_2) | ||
] = False, | ||
# === debug === | ||
max_samples: Annotated[ | ||
Optional[int], Option(help="Maximum number of samples to evaluate on.", rich_help_panel=HELP_PANEL_NAME_3) | ||
] = None, | ||
job_id: Annotated[ | ||
int, Option(help="Optional job id for future reference.", rich_help_panel=HELP_PANEL_NAME_3) | ||
] = 0, | ||
): | ||
""" | ||
Evaluate models using vllm as backend. | ||
""" | ||
import yaml | ||
|
||
from lighteval.logging.evaluation_tracker import EvaluationTracker | ||
from lighteval.models.model_input import GenerationParameters | ||
from lighteval.models.sglang.sglang_model import SGLangModelConfig | ||
from lighteval.pipeline import EnvConfig, ParallelismManager, Pipeline, PipelineParameters | ||
|
||
TOKEN = os.getenv("HF_TOKEN") | ||
|
||
env_config = EnvConfig(token=TOKEN, cache_dir=cache_dir) | ||
|
||
evaluation_tracker = EvaluationTracker( | ||
output_dir=output_dir, | ||
save_details=save_details, | ||
push_to_hub=push_to_hub, | ||
push_to_tensorboard=push_to_tensorboard, | ||
public=public_run, | ||
hub_results_org=results_org, | ||
) | ||
|
||
pipeline_params = PipelineParameters( | ||
launcher_type=ParallelismManager.SGLANG, | ||
env_config=env_config, | ||
job_id=job_id, | ||
dataset_loading_processes=dataset_loading_processes, | ||
custom_tasks_directory=custom_tasks, | ||
override_batch_size=-1, | ||
num_fewshot_seeds=num_fewshot_seeds, | ||
max_samples=max_samples, | ||
use_chat_template=use_chat_template, | ||
system_prompt=system_prompt, | ||
load_responses_from_details_date_id=load_responses_from_details_date_id, | ||
) | ||
|
||
if model_args.endswith(".yaml"): | ||
with open(model_args, "r") as f: | ||
config = yaml.safe_load(f)["model"] | ||
model_args = config["base_params"]["model_args"] | ||
generation_parameters = GenerationParameters.from_dict(config) | ||
else: | ||
generation_parameters = GenerationParameters() | ||
|
||
model_args_dict: dict = {k.split("=")[0]: k.split("=")[1] if "=" in k else True for k in model_args.split(",")} | ||
model_config = SGLangModelConfig(**model_args_dict, generation_parameters=generation_parameters) | ||
|
||
pipeline = Pipeline( | ||
tasks=tasks, | ||
pipeline_parameters=pipeline_params, | ||
evaluation_tracker=evaluation_tracker, | ||
model_config=model_config, | ||
) | ||
|
||
pipeline.evaluate() | ||
|
||
pipeline.show_results() | ||
|
||
results = pipeline.get_results() | ||
|
||
pipeline.save_and_push_results() | ||
NathanHB marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return results |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
You did not modify the
pyproject
file to reflect this extraThere 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.
I link
sglang document
for user to install here. SGLang has some limitation which can't be added bypyproject
. If we addsglang = [sglang>=0.4.2.post]
,pip install lighteval[sglang]
can't install dependency correctly. So I hope user can install sglang with sglang document.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.
Great ! Well in that case, it's not really an extra and I would not add it to the table