Audit Frontier prefix-cache trace contract

This commit is contained in:
2026-07-17 22:42:57 +08:00
parent e7b482658e
commit d3be91dd58
5 changed files with 705 additions and 3 deletions

View File

@@ -21,6 +21,11 @@ def parse_args() -> argparse.Namespace:
parser.add_argument("--port", type=int, required=True)
parser.add_argument("--requests-file", type=Path, required=True)
parser.add_argument("--output", type=Path, required=True)
parser.add_argument(
"--served-model",
default=None,
help="Optional server-side model alias used only for HTTP routing.",
)
parser.add_argument("--tpot-slo-ms", type=float, default=150.0)
parser.add_argument("--timeout-seconds", type=float, default=1800.0)
return parser.parse_args()
@@ -64,6 +69,7 @@ async def request_one(
scheduled_at: float,
benchmark_start: float,
tpot_slo_ms: float,
served_model: str | None,
) -> dict[str, Any]:
loop = asyncio.get_running_loop()
delay = scheduled_at - loop.time()
@@ -81,6 +87,8 @@ async def request_one(
"success": False,
}
body = dict(row["body"])
if served_model is not None:
body["model"] = served_model
body.update(
{
"temperature": 0,
@@ -178,6 +186,7 @@ async def replay(args: argparse.Namespace, rows: list[dict[str, Any]]) -> list[d
scheduled_at=benchmark_start + float(row["arrived_at"]),
benchmark_start=benchmark_start,
tpot_slo_ms=args.tpot_slo_ms,
served_model=args.served_model,
)
)
for row in rows
@@ -219,6 +228,7 @@ def main() -> None:
"last_arrival_s": arrivals[-1],
"arrival": "original_trace_timestamp_and_order",
"input_output_prompt": "exact_source_values",
"served_model_alias": args.served_model,
"ttft_slo": "1000ms + 1000ms * input_tokens / 8000",
"tpot_slo_ms": args.tpot_slo_ms,
"target_pass_rate": TARGET_PASS_RATE,

View File

@@ -84,8 +84,21 @@ def percentile(values: list[float], fraction: float) -> float | None:
return ordered[math.ceil(fraction * len(ordered)) - 1]
def manifest_offered_rate(path: Path) -> tuple[float | None, str | None]:
manifest_path = path.with_name("manifest.json")
if not manifest_path.is_file():
return None, None
manifest = json.loads(manifest_path.read_text())
if manifest.get("public_csv") != str(path):
return None, None
rate = manifest.get("global_offered_request_rate")
if not isinstance(rate, (int, float)) or not math.isfinite(rate) or rate <= 0:
raise ValueError(f"invalid global_offered_request_rate in {manifest_path}")
return float(rate), str(manifest_path)
def parse_trace(
specification: str, *, rate_contract: str = "trace-window"
specification: str, *, rate_contract: str = "trace-window", prefix_caching: bool
) -> dict[str, Any]:
if "=" not in specification:
raise ValueError(f"trace must be LABEL=PATH: {specification}")
@@ -114,7 +127,12 @@ def parse_trace(
if any(right < left for left, right in zip(arrivals, arrivals[1:])):
raise ValueError(f"arrival order drift in {path}")
if rate_contract == "trace-window":
offered_request_rate = len(rows) / WINDOW_SECONDS
offered_request_rate, rate_manifest = manifest_offered_rate(path)
if offered_request_rate is None:
offered_request_rate = len(rows) / WINDOW_SECONDS
rate_source = "legacy_fixed_600_second_window"
else:
rate_source = f"manifest:{rate_manifest}"
elif rate_contract == "uniform-spacing":
if len(rows) < 2 or arrivals[-1] <= arrivals[0]:
raise ValueError("uniform-spacing traces require at least two arrivals")
@@ -123,6 +141,7 @@ def parse_trace(
if any(abs(value - expected_interval) > 1e-9 for value in intervals):
raise ValueError(f"non-uniform fixed trace: {path}")
offered_request_rate = 1.0 / expected_interval
rate_source = "uniform_spacing"
else:
raise ValueError(f"unknown rate contract: {rate_contract}")
shapes = [
@@ -131,12 +150,22 @@ def parse_trace(
]
if any(prefill <= 0 or decode <= 0 or prefill + decode > 40960 for prefill, decode in shapes):
raise ValueError(f"out-of-contract shape in {path}")
if prefix_caching:
for index, (row, (prefill, _)) in enumerate(zip(rows, shapes, strict=True)):
block_ids = [value for value in row["block_hash_ids"].split("|") if value]
if len(block_ids) != prefill // 16:
raise ValueError(
"Frontier prefix-cache trace must expose only complete "
f"16-token blocks: row={index}, ISL={prefill}, "
f"ids={len(block_ids)}, expected={prefill // 16}"
)
return {
"label": label,
"path": path,
"sha256": BASE.sha256(path),
"requests": len(rows),
"offered_request_rate": offered_request_rate,
"offered_request_rate_source": rate_source,
"first_arrival_s": arrivals[0],
"last_arrival_s": arrivals[-1],
"shapes": shapes,
@@ -236,7 +265,11 @@ def main() -> None:
if args.allreduce_csv is not None:
args.allreduce_csv = args.allreduce_csv.resolve()
traces = [
parse_trace(specification, rate_contract=args.rate_contract)
parse_trace(
specification,
rate_contract=args.rate_contract,
prefix_caching=args.prefix_caching,
)
for specification in args.trace
]
if len({trace["label"] for trace in traces}) != len(traces):