bench_serving: add Zipfian shared-prefix sampling to generated-shared-prefix (#26378)
This commit is contained in:
@@ -17,6 +17,7 @@ import asyncio
|
||||
import copy
|
||||
import importlib.util
|
||||
import json
|
||||
import math
|
||||
import os
|
||||
import random
|
||||
import shutil
|
||||
@@ -1930,6 +1931,44 @@ def run_benchmark(args_: argparse.Namespace):
|
||||
)
|
||||
|
||||
|
||||
def _finite_positive_float(value) -> float:
|
||||
"""argparse type for a finite, strictly positive float."""
|
||||
try:
|
||||
parsed = float(value)
|
||||
except (TypeError, ValueError) as exc:
|
||||
raise argparse.ArgumentTypeError(
|
||||
f"expected a finite float > 0, got {value!r}"
|
||||
) from exc
|
||||
if not math.isfinite(parsed) or parsed <= 0:
|
||||
raise argparse.ArgumentTypeError(f"expected a finite float > 0, got {value!r}")
|
||||
return parsed
|
||||
|
||||
|
||||
def _validate_parsed_gsp_args(
|
||||
parser: argparse.ArgumentParser, args: argparse.Namespace
|
||||
) -> None:
|
||||
"""Reject malformed GSP distribution/alpha combinations at parse time.
|
||||
|
||||
Invoked from the CLI entry point right after ``parser.parse_args()`` so
|
||||
users see a clear argparse-style error before any server, model, or
|
||||
tokenizer setup runs and masks the real cause with an unrelated network
|
||||
failure.
|
||||
"""
|
||||
distribution = getattr(args, "gsp_group_distribution", None)
|
||||
alpha = getattr(args, "gsp_zipf_alpha", None)
|
||||
if distribution == "zipf" and alpha is None:
|
||||
parser.error(
|
||||
"--gsp-group-distribution=zipf requires --gsp-zipf-alpha "
|
||||
"(a finite float > 0)"
|
||||
)
|
||||
if distribution == "uniform" and alpha is not None:
|
||||
parser.error(
|
||||
"--gsp-zipf-alpha is only meaningful with "
|
||||
"--gsp-group-distribution=zipf; remove --gsp-zipf-alpha "
|
||||
"or set --gsp-group-distribution=zipf"
|
||||
)
|
||||
|
||||
|
||||
class LoRAPathAction(argparse.Action):
|
||||
def __call__(self, parser, namespace, values, option_string=None):
|
||||
setattr(namespace, self.dest, [])
|
||||
@@ -2366,6 +2405,37 @@ if __name__ == "__main__":
|
||||
action="store_true",
|
||||
help="Keep requests in order without shuffling. By default, requests are shuffled randomly.",
|
||||
)
|
||||
group.add_argument(
|
||||
"--gsp-group-distribution",
|
||||
type=str,
|
||||
choices=["uniform", "zipf"],
|
||||
default="uniform",
|
||||
help=(
|
||||
"Prefix-group sampling distribution for generated-shared-prefix. "
|
||||
"'uniform' (default) assigns each group an equal number of requests. "
|
||||
"'zipf' samples each request's group by rank with "
|
||||
"p(rank) = (1/rank**alpha) / sum_k(1/k**alpha); rank starts at 1 "
|
||||
"and group index 0 is the hottest. Requires --gsp-zipf-alpha "
|
||||
"(a finite float > 0) when set to 'zipf'. Total request count is "
|
||||
"still num_groups * prompts_per_group, identical to uniform mode; "
|
||||
"only the per-request group assignment changes. The on-disk "
|
||||
"dataset cache uses a distinct key per (group_distribution, "
|
||||
"zipf_alpha), so uniform-mode caches are never mixed with "
|
||||
"zipf-mode caches and zipf runs with different alpha use "
|
||||
"separate files."
|
||||
),
|
||||
)
|
||||
group.add_argument(
|
||||
"--gsp-zipf-alpha",
|
||||
type=_finite_positive_float,
|
||||
default=None,
|
||||
help=(
|
||||
"Zipf exponent alpha for --gsp-group-distribution=zipf, with "
|
||||
"p(rank) = (1/rank**alpha) / sum_k(1/k**alpha) and rank starting "
|
||||
"at 1. Must be a finite float strictly greater than 0; larger "
|
||||
"values concentrate requests on lower-ranked (hotter) groups."
|
||||
),
|
||||
)
|
||||
mooncake_group = parser.add_argument_group("mooncake dataset arguments")
|
||||
mooncake_group.add_argument(
|
||||
"--mooncake-slowdown-factor",
|
||||
@@ -2413,4 +2483,5 @@ if __name__ == "__main__":
|
||||
help="Custom HTTP headers in Key=Value format. Example: --header MyHeader=MY_VALUE MyAnotherHeader=myanothervalue",
|
||||
)
|
||||
args = parser.parse_args()
|
||||
_validate_parsed_gsp_args(parser, args)
|
||||
run_benchmark(args)
|
||||
|
||||
Reference in New Issue
Block a user