Add simulator-aware fidelity pilot audit
This commit is contained in:
75
runs/fidelity-headroom/test_strong_pilot.py
Normal file
75
runs/fidelity-headroom/test_strong_pilot.py
Normal file
@@ -0,0 +1,75 @@
|
||||
#!/usr/bin/env python3
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
import numpy as np
|
||||
|
||||
from analyze_prefixes import PrefixExample
|
||||
from analyze_strong_pilot import (
|
||||
fit_model,
|
||||
load_pilot_simulator,
|
||||
predict_model,
|
||||
)
|
||||
|
||||
|
||||
def example(index: int) -> PrefixExample:
|
||||
label = int(index >= 4)
|
||||
return PrefixExample(
|
||||
cell=f"cell-{index // 2}",
|
||||
anchor=float(index),
|
||||
cutoff_s=5.0,
|
||||
tp=1,
|
||||
full_elapsed_s=10.0,
|
||||
feasible=label,
|
||||
primary_feasible=label,
|
||||
outcome=tuple(float(index + offset) for offset in range(13)),
|
||||
instrumentation=tuple(float(index * offset + 1) for offset in range(17)),
|
||||
completion_time_source="exact_monotonic",
|
||||
)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
examples = [example(index) for index in range(8)]
|
||||
simulator = [(float(index), index / 10.0, float(index >= 4)) for index in range(8)]
|
||||
for instrumentation_aware in (False, True):
|
||||
model = fit_model(
|
||||
examples,
|
||||
simulator,
|
||||
instrumentation_aware=instrumentation_aware,
|
||||
regularization=1.0,
|
||||
)
|
||||
probability = predict_model(model, examples, simulator)
|
||||
assert probability.shape == (8,)
|
||||
assert np.all((probability >= 0.0) & (probability <= 1.0))
|
||||
|
||||
payload = {
|
||||
"status": "PASS",
|
||||
"results": [
|
||||
{
|
||||
"cell": f"cell-{index // 2}",
|
||||
"role": "low1" if index % 2 == 0 else "high1",
|
||||
"scorer": {
|
||||
"throughput_requests_per_second_per_gpu": 1.0 + index,
|
||||
"slo": {
|
||||
"pass_rate": index / 12.0,
|
||||
"feasible": index % 2 == 0,
|
||||
},
|
||||
},
|
||||
}
|
||||
for index in range(12)
|
||||
],
|
||||
}
|
||||
with tempfile.TemporaryDirectory() as temporary:
|
||||
path = Path(temporary) / "metrics.json"
|
||||
path.write_text(json.dumps(payload), encoding="utf-8")
|
||||
features, red_flags = load_pilot_simulator(path)
|
||||
assert len(features) == 12
|
||||
assert red_flags == []
|
||||
print("fidelity strong pilot: PASS")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user