Audit Frontier prefix-cache trace contract
This commit is contained in:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user