Skip to content

Commit a44df83

Browse files
committed
drop dummy dataset files
1 parent 7b365a8 commit a44df83

4 files changed

Lines changed: 80 additions & 243 deletions

File tree

‎examples/03_BenchmarkComparison/README.md‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,11 @@ Compare `inference-endpoint` with vLLM's benchmarking tool using identical promp
44

55
## Prerequisites
66

7-
1. **Running inference server** (OpenAI-compatible):
7+
**Running inference server** (OpenAI-compatible):
88

9-
```bash
10-
vllm serve Qwen/Qwen2.5-0.5B-Instruct --port 8000
11-
```
12-
13-
2. **Pre-generated dataset files** (included in this directory):
14-
- `dummy_prompts_vllm.jsonl` - vLLM format: `{"prompt": "..."}`
15-
- `dummy_prompts_ie.jsonl` - inference-endpoint format: `{"text_input": "..."}`
9+
```bash
10+
vllm serve Qwen/Qwen2.5-0.5B-Instruct --port 8000
11+
```
1612

1713
## Usage
1814

‎examples/03_BenchmarkComparison/compare_with_vllm.py‎

Lines changed: 76 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,44 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
"""Compare inference-endpoint and vLLM benchmarking tools using JSONL datasets.
17+
"""Compare inference-endpoint and vLLM benchmarking tools.
1818
19-
Prerequisites:
20-
- Pre-generated dataset files in the same directory:
21-
- dummy_prompts_vllm.jsonl (vLLM custom format)
22-
- dummy_prompts_ie.jsonl (inference-endpoint format)
23-
- Contain the same text prompts.
19+
Generates dummy prompts on the fly from a base set of 10 phrases.
20+
Prompts are cycled if num-prompts exceeds the base set size.
2421
2522
Usage:
2623
python compare_with_vllm.py --model "Qwen/Qwen2.5-0.5B-Instruct" --num-prompts 100
2724
"""
2825

2926
import argparse
27+
import json
3028
import logging
3129
import re
3230
import subprocess
3331
import sys
32+
import tempfile
3433
import time
34+
from collections.abc import Generator
35+
from contextlib import contextmanager
3536
from pathlib import Path
3637
from typing import Any
3738

3839
import requests
3940

41+
# Base prompts for generating benchmark datasets (cycled as needed)
42+
BASE_PROMPTS = [
43+
"Explain quantum entanglement in simple terms.",
44+
"What is machine learning and how does it work?",
45+
"Describe the process of photosynthesis.",
46+
"How does blockchain technology work?",
47+
"What are the health benefits of regular exercise?",
48+
"Explain the theory of relativity in simple terms.",
49+
"How do neural networks learn from data?",
50+
"What causes climate change and its effects?",
51+
"Describe how the internet works at a high level.",
52+
"What is the difference between AI and machine learning?",
53+
]
54+
4055
# Constants
4156
DEFAULT_ENDPOINT = "http://localhost:8000"
4257
DEFAULT_NUM_PROMPTS = 100
@@ -50,6 +65,38 @@
5065
logger = logging.getLogger(__name__)
5166

5267

68+
@contextmanager
69+
def temp_dataset_files(num_prompts: int) -> Generator[tuple[Path, Path], None, None]:
70+
"""Context manager that creates temporary dataset files for benchmarking.
71+
72+
Generates prompts by cycling through BASE_PROMPTS and creates two JSONL files:
73+
- vLLM format: {"prompt": "..."}
74+
- inference-endpoint format: {"text_input": "..."}
75+
76+
Args:
77+
num_prompts: Number of prompts to generate
78+
79+
Yields:
80+
Tuple of (vllm_dataset_path, ie_dataset_path)
81+
"""
82+
with tempfile.TemporaryDirectory() as temp_dir:
83+
temp_path = Path(temp_dir)
84+
prompts = [BASE_PROMPTS[i % len(BASE_PROMPTS)] for i in range(num_prompts)]
85+
86+
vllm_path = temp_path / "prompts_vllm.jsonl"
87+
ie_path = temp_path / "prompts_ie.jsonl"
88+
89+
with open(vllm_path, "w") as f:
90+
for prompt in prompts:
91+
f.write(json.dumps({"prompt": prompt}) + "\n")
92+
93+
with open(ie_path, "w") as f:
94+
for prompt in prompts:
95+
f.write(json.dumps({"text_input": prompt}) + "\n")
96+
97+
yield vllm_path, ie_path
98+
99+
53100
def parse_args() -> argparse.Namespace:
54101
"""Parse command line arguments."""
55102
parser = argparse.ArgumentParser(
@@ -457,27 +504,10 @@ def warmup_server(url: str, model: str, timeout: int = 120):
457504
def main():
458505
args = parse_args()
459506

460-
# Dataset files are expected to exist in the script directory
461-
script_dir = Path(__file__).parent
462-
vllm_dataset = script_dir / "dummy_prompts_vllm.jsonl"
463-
ie_dataset = script_dir / "dummy_prompts_ie.jsonl"
464-
465-
# Validate dataset files exist
466-
if not vllm_dataset.exists():
467-
logger.error(f"vLLM dataset not found: {vllm_dataset}")
468-
logger.error("Run: python convert_dataset.py dummy_prompts.json")
469-
sys.exit(1)
470-
if not ie_dataset.exists():
471-
logger.error(f"inference-endpoint dataset not found: {ie_dataset}")
472-
logger.error("Run: python convert_dataset.py dummy_prompts.json")
473-
sys.exit(1)
474-
475507
logger.info(f"Model: {args.model}")
476508
logger.info(f"Endpoint: {args.endpoint}")
477509
logger.info(f"Number of prompts: {args.num_prompts}")
478510
logger.info(f"Max output tokens: {args.max_output_tokens}")
479-
logger.info(f"vLLM dataset: {vllm_dataset}")
480-
logger.info(f"IE dataset: {ie_dataset}")
481511
if args.dry:
482512
logger.info("DRY RUN MODE: Commands will be printed but not executed")
483513

@@ -492,26 +522,29 @@ def main():
492522
else:
493523
logger.info("Skipping warmup in dry run mode")
494524

495-
# Run benchmarks
496-
vllm_res = run_vllm_benchmark(
497-
args.model,
498-
vllm_dataset,
499-
args.endpoint,
500-
args.num_prompts,
501-
args.max_output_tokens,
502-
dry_run=args.dry,
503-
)
504-
505-
ie_res = run_inference_endpoint(
506-
args.model,
507-
ie_dataset,
508-
args.endpoint,
509-
args.num_prompts,
510-
args.max_output_tokens,
511-
args.timeout,
512-
args.workers,
513-
dry_run=args.dry,
514-
)
525+
# Generate temp dataset files and run benchmarks
526+
with temp_dataset_files(args.num_prompts) as (vllm_dataset, ie_dataset):
527+
logger.info(f"Generated {args.num_prompts} prompts in temp directory")
528+
529+
vllm_res = run_vllm_benchmark(
530+
args.model,
531+
vllm_dataset,
532+
args.endpoint,
533+
args.num_prompts,
534+
args.max_output_tokens,
535+
dry_run=args.dry,
536+
)
537+
538+
ie_res = run_inference_endpoint(
539+
args.model,
540+
ie_dataset,
541+
args.endpoint,
542+
args.num_prompts,
543+
args.max_output_tokens,
544+
args.timeout,
545+
args.workers,
546+
dry_run=args.dry,
547+
)
515548

516549
if not args.dry:
517550
print_comparison(ie_res, vllm_res)

‎examples/03_BenchmarkComparison/dummy_prompts_ie.jsonl‎

Lines changed: 0 additions & 96 deletions
This file was deleted.

‎examples/03_BenchmarkComparison/dummy_prompts_vllm.jsonl‎

Lines changed: 0 additions & 96 deletions
This file was deleted.

0 commit comments

Comments
 (0)