Skip to content

Commit 7f59b39

Browse files
vastzubyclaude
andcommitted
docs(examples): demo workload_calculator in vllm and train_mnist
Use max_tokens as the workload for the vllm generate() endpoint (the LLM-standard metric) and input pixel count for the train_mnist infer() endpoint. Left off the square example since its cost is constant. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 6337103 commit 7f59b39

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

examples/deployments/train_mnist/deploy.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,13 @@ async def __aexit__(self, *exc):
6464
pass
6565

6666

67-
@app.remote(benchmark_dataset=[{"pixel_values": [[0.0] * 28] * 28}])
67+
# Optional: workload = input pixel count, so bigger images count as more work.
68+
@app.remote(
69+
benchmark_dataset=[{"pixel_values": [[0.0] * 28] * 28}],
70+
workload_calculator=lambda pixel_values: float(
71+
len(pixel_values) * len(pixel_values[0])
72+
),
73+
)
6874
async def infer(pixel_values: list[list[float]]) -> dict:
6975
"""Classify a 28x28 grayscale MNIST image.
7076

examples/deployments/vllm/deploy.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ async def __aexit__(self, *exc):
2424
self.engine.shutdown_background_loop()
2525

2626

27-
@app.remote(benchmark_dataset=[{"prompt": "Hello"}])
27+
# Optional: workload = max_tokens, so the autoscaler sizes by total tokens/sec.
28+
@app.remote(
29+
benchmark_dataset=[{"prompt": "Hello"}],
30+
workload_calculator=lambda prompt, max_tokens=128: float(max_tokens),
31+
)
2832
async def generate(prompt: str, max_tokens: int = 128) -> str:
2933
from vllm import SamplingParams
3034
import uuid

0 commit comments

Comments
 (0)