-
Notifications
You must be signed in to change notification settings - Fork 4
Add cnn_dailymail processing for summarization, and offline/online run config yamls #67
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e71ddc7
Add dataset processor and offline/online configs
attafosu 70f90d2
Add README
attafosu cad561d
Rename READE.md to README.md
attafosu 6d22838
Merge branch 'main' into feat/attafosu/llama3.1-8b
attafosu 37974fd
Linter issues
attafosu 3b932c4
Apply suggestions from code review
attafosu 47e6466
Update examples/05_Llama3.1-8B_Example/offline_llama3_8b_cnn.yaml
attafosu 5610710
Linter issue
attafosu b9517ad
Sync generation parameters to legacy
attafosu 0047d21
Update examples/05_Llama3.1-8B_Example/README.md
attafosu 37b7a9c
Apply suggestion from @Copilot
attafosu d2c792d
Update (known) params
attafosu 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 hidden or 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,52 @@ | ||
| # Running Endpoints with [Llama3.1-8B](https://huggingface.co/meta-llama/Llama-3.1-8B-Instruct) | ||
|
|
||
| ## Download dataset | ||
| The Llama3.1-8B benchmark uses the [cnn/dailymail](https://huggingface.co/datasets/abisee/cnn_dailymail) dataset (for summarization). Download, modify the input prompt and save | ||
|
|
||
| ``` | ||
| python download_cnndm.py --save-dir data --split validation | ||
| # Processed data will be saved at data/cnn_dailymail_validation.json | ||
| ``` | ||
|
|
||
| + To generate calibration dataset, users can use the [cnn-dailymail-calibration-list](https://github.com/mlcommons/inference/blob/master/calibration/CNNDailyMail/calibration-list.txt) | ||
attafosu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ``` | ||
| curl -OL https://raw.githubusercontent.com/mlcommons/inference/refs/heads/master/calibration/CNNDailyMail/calibration-list.txt | ||
attafosu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| python download_cnndm.py --save-dir data --calibration-ids-file calibration-list.txt --split train | ||
| ``` | ||
|
|
||
| ## Launch the server | ||
|
|
||
| The following environment variables are used by the commands below to make the scripts easier to run | ||
|
|
||
| ``` | ||
| export HF_TOKEN=<your Hugging Face token> | ||
| export HF_HOME=<Path to your hf_home, usually /USERNAME/.cache/huggingface> | ||
attafosu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| export MODEL_NAME=<model to run, for instance meta-llama/Llama-3.1-8B-Instruct> | ||
| ``` | ||
|
|
||
| It is convenient to download the model prior to launch so that the container can reuse the model instead of having to download it post-launch. This can be done via `hf download $MODEL_NAME`. The models downloaded can be verified via `hf cache scan` | ||
attafosu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ### [vLLM](https://github.com/vllm-project/vllm) | ||
|
|
||
| We can launch the latest docker image for vllm using the command below: | ||
|
|
||
| ``` | ||
| docker run --runtime nvidia --gpus all -v ${HF_HOME}:/root/.cache/huggingface --env "HUGGING_FACE_HUB_TOKEN=$HF_TOKEN" -p 8000:8000 --ipc=host vllm/vllm-openai:latest --model ${MODEL_NAME} | ||
|
|
||
| ``` | ||
|
|
||
| ### To run Offline mode | ||
| **Note** Double-check the config file for correct parameters | ||
|
|
||
| + Launch the benchmark with config yaml | ||
attafosu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ``` | ||
| inference-endpoint benchmark from-config -c offline_llama3_8b_cnn.yaml --timeout 600 | ||
| ``` | ||
|
|
||
| ### To run Online mode | ||
| **Note** Double-check the config file for correct parameters | ||
|
|
||
| + Launch the benchmark with config yaml | ||
attafosu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ``` | ||
| inference-endpoint benchmark from-config -c online_llama3_8b_cnn.yaml --timeout 600 | ||
| ``` | ||
This file contains hidden or 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,110 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import json | ||
| import os | ||
| import warnings | ||
| from argparse import ArgumentParser | ||
|
|
||
| from datasets import load_dataset | ||
| from tqdm import tqdm | ||
|
|
||
| PROMPT = "Summarize the following news article in 128 tokens. Please output the summary only, without any other text.\n\nArticle:\n{input}\n\nSummary:" | ||
|
|
||
|
|
||
| def download_cnndm( | ||
| save_dir: str, split: str = "validation", calibration_ids_file: str = None | ||
| ) -> None: | ||
| """Download the CNN/DailyMail dataset and save it to the specified directory. | ||
|
|
||
| Args: | ||
| save_dir (str): The directory where the dataset will be saved. | ||
| split (str): The dataset split to download (default: validation). | ||
| calibration_ids_file (str): Path to a file containing calibration IDs (one per line). | ||
| If provided, 'split' must be 'train' and only examples with these IDs will be prepared and saved. | ||
| """ | ||
| os.makedirs(save_dir, exist_ok=True) | ||
| dataset = load_dataset("cnn_dailymail", "3.0.0", split=split) | ||
|
|
||
| output_file_tag = split | ||
| calibration_ids = set() | ||
| if calibration_ids_file: | ||
| with open(calibration_ids_file) as id_file: | ||
attafosu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| for line in id_file: | ||
| calibration_ids.add(line.strip()) | ||
| output_file_tag = "calibration" | ||
| fname = f"cnn_dailymail_{output_file_tag}.json" | ||
| output_file = os.path.join(save_dir, fname) | ||
|
|
||
| # Add the custom prompt to each example and filter if calibration IDs are provided | ||
| with open(output_file, "w", encoding="utf-8") as f: | ||
| for _, example in tqdm( | ||
| enumerate(dataset), total=len(dataset), desc="Processing examples" | ||
| ): | ||
attafosu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if calibration_ids and str(example["id"]) not in calibration_ids: | ||
| continue | ||
| f.write( | ||
| json.dumps( | ||
| { | ||
| "id": example["id"], | ||
| "input": PROMPT.format(input=example["article"]), | ||
| "highlights": example["highlights"], | ||
| } | ||
| ) | ||
| + "\n" | ||
| ) | ||
| print(f"Dataset saved to {output_file}") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| parser = ArgumentParser(description="Download CNN/DailyMail dataset") | ||
| parser.add_argument( | ||
| "--save-dir", | ||
| type=str, | ||
| required=True, | ||
| help="Directory to save the downloaded dataset", | ||
| ) | ||
| parser.add_argument( | ||
| "--split", | ||
| type=str, | ||
| default="validation", | ||
| help="Dataset split to download (default: validation)", | ||
| ) | ||
| parser.add_argument( | ||
| "--calibration-ids-file", | ||
| type=str, | ||
| default=None, | ||
| help="Path to a file containing calibration IDs (one per line)." | ||
| " If provided and available, 'split' must be 'train' and only examples with these IDs will be saved.", | ||
attafosu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) | ||
|
|
||
| args = parser.parse_args() | ||
| if args.calibration_ids_file and args.split != "train": | ||
| warnings.warn( | ||
| "When --calibration-ids-file is provided, --split must be 'train'. Setting split to 'train'.", | ||
| stacklevel=2, | ||
| ) | ||
| args.split = "train" | ||
|
|
||
| if args.calibration_ids_file and not os.path.isfile(args.calibration_ids_file): | ||
| raise FileNotFoundError( | ||
| f"Provided Calibration IDs file not found: {args.calibration_ids_file}" | ||
attafosu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) | ||
|
|
||
| download_cnndm( | ||
| save_dir=args.save_dir, | ||
| split=args.split, | ||
| calibration_ids_file=args.calibration_ids_file, | ||
| ) | ||
42 changes: 42 additions & 0 deletions
42
examples/05_Llama3.1-8B_Example/offline_llama3_8b_cnn.yaml
This file contains hidden or 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,42 @@ | ||
| # Offline Throughput Benchmark | ||
| name: "offline-llama3.1-8b-cnn-benchmark" | ||
| version: "1.0" | ||
| type: "offline" | ||
|
|
||
| model_params: | ||
| name: "meta-llama/Llama-3.1-8B-Instruct" # Path to the model | ||
attafosu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| temperature: 0.7 | ||
attafosu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| top_p: 0.9 | ||
| max_new_tokens: 128 | ||
|
|
||
| datasets: | ||
| - name: "perf-test" | ||
| type: "performance" | ||
| path: "data/cnn_dailymail_validation.json" # Path to the dataset. Note: This should be the file generated with download_cnndm.py | ||
| samples: 13368 # Number of samples in the dataset (validation has 13.3k samples, while training has 26k samples) | ||
attafosu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
attafosu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| parser: | ||
| prompt: "input" | ||
|
|
||
| settings: | ||
| runtime: | ||
| min_duration_ms: 6000 # 6 seconds | ||
| max_duration_ms: 60000 # 1 minute | ||
attafosu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| scheduler_random_seed: 137 # For Poisson/distribution sampling | ||
| dataloader_random_seed: 111 # For dataset shuffling | ||
|
|
||
| load_pattern: | ||
| type: "max_throughput" | ||
|
|
||
| client: | ||
| workers: 1 # Number of client workers | ||
attafosu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| metrics: | ||
| collect: | ||
| - "throughput" | ||
| - "latency" | ||
| - "ttft" | ||
| - "tpot" | ||
|
|
||
| endpoint_config: | ||
| endpoint: "http://localhost:8000" | ||
| api_key: null | ||
This file contains hidden or 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,45 @@ | ||
| # Online Benchmark | ||
| name: "online-llama3.1-8b-cnn-benchmark" | ||
| version: "1.0" | ||
| type: "online" | ||
|
|
||
| model_params: | ||
| name: meta-llama/Llama-3.1-8B-Instruct # Path to the model | ||
attafosu marked this conversation as resolved.
Show resolved
Hide resolved
attafosu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| temperature: 0.7 | ||
| top_p: 0.9 | ||
| max_new_tokens: 128 | ||
|
|
||
| datasets: | ||
| - name: "perf-test" | ||
| type: "performance" | ||
| path: "data/cnn_dailymail_validation.json" # Path to the dataset. Note: This should be the file generated with download_cnndm.py | ||
| format: "json" | ||
attafosu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| samples: 13368 | ||
| parser: | ||
| prompt: "input" | ||
attafosu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| eval_method: "rouge" | ||
attafosu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| settings: | ||
| runtime: | ||
| min_duration_ms: 6000 # 6 seconds | ||
| max_duration_ms: 60000 # 1 minute | ||
| scheduler_random_seed: 137 # For Poisson/distribution sampling | ||
| dataloader_random_seed: 111 # For dataset shuffling | ||
|
|
||
| load_pattern: | ||
| type: "poisson" | ||
| target_qps: 3 # This is the target queries per second for the Poisson load pattern (Legacy Loadgen) | ||
|
|
||
| client: | ||
| workers: 1 # Number of client workers | ||
attafosu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| metrics: | ||
| collect: | ||
| - "throughput" | ||
| - "latency" | ||
| - "ttft" | ||
| - "tpot" | ||
|
|
||
| endpoint_config: | ||
| endpoint: "http://localhost:8000" | ||
| api_key: null | ||
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.
Uh oh!
There was an error while loading. Please reload this page.