Add tail threshold v2 code (numeric quantile tails, no concentration)
Browse files
evaluation/tail/tail_threshold_code_v2/scripts/run_tail_threshold_v2.py
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Run the v2 tail-threshold experiment with numeric quantile ranges."""
|
| 3 |
+
|
| 4 |
+
from __future__ import annotations
|
| 5 |
+
|
| 6 |
+
import argparse
|
| 7 |
+
import json
|
| 8 |
+
import sys
|
| 9 |
+
from pathlib import Path
|
| 10 |
+
|
| 11 |
+
PROJECT_ROOT = Path(__file__).resolve().parents[1]
|
| 12 |
+
if str(PROJECT_ROOT) not in sys.path:
|
| 13 |
+
sys.path.insert(0, str(PROJECT_ROOT))
|
| 14 |
+
|
| 15 |
+
from src.eval.tail_threshold_v2.runner import DEFAULT_THRESHOLD_PCTS, run_tail_threshold_experiment_v2
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def parse_args() -> argparse.Namespace:
|
| 19 |
+
parser = argparse.ArgumentParser(description="Run tail-threshold v2 diagnostics.")
|
| 20 |
+
parser.add_argument("--run-tag", type=str, default=None, help="Optional output run tag.")
|
| 21 |
+
parser.add_argument("--datasets", type=str, default="", help="Optional comma-separated dataset ids. Empty means all datasets.")
|
| 22 |
+
parser.add_argument(
|
| 23 |
+
"--root-names",
|
| 24 |
+
type=str,
|
| 25 |
+
default="",
|
| 26 |
+
help="Optional comma-separated synthetic root names. Example: TabQueryBench-SynDataSuccess-main",
|
| 27 |
+
)
|
| 28 |
+
parser.add_argument(
|
| 29 |
+
"--threshold-percentages",
|
| 30 |
+
type=str,
|
| 31 |
+
default=",".join(f"{value:g}" for value in DEFAULT_THRESHOLD_PCTS),
|
| 32 |
+
help="Comma-separated tail thresholds in percentage points.",
|
| 33 |
+
)
|
| 34 |
+
parser.add_argument("--all-asset-runs", action="store_true", help="Disable latest-only filtering within the same model/server.")
|
| 35 |
+
parser.add_argument("--max-workers", type=int, default=4, help="Parallel workers across datasets.")
|
| 36 |
+
parser.add_argument("--numeric-bins", type=int, default=10, help="Reserved for categorical-vs-numeric mode detection.")
|
| 37 |
+
return parser.parse_args()
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def _parse_threshold_percentages(text: str) -> list[float]:
|
| 41 |
+
values: list[float] = []
|
| 42 |
+
for chunk in text.split(","):
|
| 43 |
+
token = chunk.strip()
|
| 44 |
+
if token:
|
| 45 |
+
values.append(float(token))
|
| 46 |
+
return values
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
def main() -> None:
|
| 50 |
+
args = parse_args()
|
| 51 |
+
datasets = [item.strip() for item in args.datasets.split(",") if item.strip()] or None
|
| 52 |
+
root_names = [item.strip() for item in args.root_names.split(",") if item.strip()] or None
|
| 53 |
+
manifest = run_tail_threshold_experiment_v2(
|
| 54 |
+
run_tag=args.run_tag,
|
| 55 |
+
datasets=datasets,
|
| 56 |
+
latest_only=not args.all_asset_runs,
|
| 57 |
+
root_names=root_names,
|
| 58 |
+
threshold_percentages=_parse_threshold_percentages(args.threshold_percentages),
|
| 59 |
+
max_workers=max(1, args.max_workers),
|
| 60 |
+
numeric_bins=max(2, args.numeric_bins),
|
| 61 |
+
)
|
| 62 |
+
print(json.dumps(manifest, ensure_ascii=False, indent=2))
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
if __name__ == "__main__":
|
| 66 |
+
main()
|