Stream trace window materialization
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
@@ -258,7 +259,101 @@ class CoreFlowTests(unittest.TestCase):
|
||||
self.assertTrue(evaluations[0].passed)
|
||||
self.assertFalse(evaluations[1].passed)
|
||||
self.assertEqual(summary["slo_pass_rate"], 0.5)
|
||||
self.assertFalse(summary["feasible"])
|
||||
|
||||
def test_prepare_trace_windows_materializes_repo_local_assets(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
tmp_path = Path(tmp)
|
||||
legacy_source = tmp_path / "legacy"
|
||||
thinking_source = tmp_path / "thinking"
|
||||
legacy_source.mkdir()
|
||||
thinking_source.mkdir()
|
||||
|
||||
for filename in [
|
||||
"qwen_chat_blksz_64_031109-031111",
|
||||
"qwen_chat_blksz_64_031121-031123",
|
||||
"qwen_chat_blksz_64_031209-031211",
|
||||
"qwen_chat_blksz_64_031221-031223",
|
||||
"qwen_chat_blksz_64_031309-031311",
|
||||
"qwen_chat_blksz_64_031321-031323",
|
||||
"qwen_chat_blksz_64_031609-031611",
|
||||
"qwen_chat_blksz_64_031621-031623",
|
||||
"qwen_chat_blksz_64_031709-031711",
|
||||
"qwen_chat_blksz_64_031721-031723",
|
||||
]:
|
||||
for suffix in [".jsonl", "_prompt.jsonl"]:
|
||||
path = legacy_source / f"{filename}{suffix}"
|
||||
path.write_text("", encoding="utf-8")
|
||||
|
||||
peak_trace = legacy_source / "qwen_chat_blksz_64_031109-031111.jsonl"
|
||||
peak_prompt = legacy_source / "qwen_chat_blksz_64_031109-031111_prompt.jsonl"
|
||||
peak_trace.write_text(
|
||||
"\n".join(
|
||||
[
|
||||
json.dumps(
|
||||
{
|
||||
"chat_id": "c1",
|
||||
"turn": 1,
|
||||
"timestamp": 3599.0,
|
||||
"input_length": 10,
|
||||
"output_length": 3,
|
||||
}
|
||||
),
|
||||
json.dumps(
|
||||
{
|
||||
"chat_id": "c2",
|
||||
"turn": 2,
|
||||
"timestamp": 3605.0,
|
||||
"input_length": 20,
|
||||
"output_length": 7,
|
||||
}
|
||||
),
|
||||
]
|
||||
)
|
||||
+ "\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
peak_prompt.write_text(
|
||||
"\n".join(
|
||||
[
|
||||
json.dumps({"chat_id": "c1", "turn": 1, "prompt": "ignore me"}),
|
||||
json.dumps({"chat_id": "c2", "turn": 2, "prompt": "real prompt"}),
|
||||
]
|
||||
)
|
||||
+ "\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
output_root = tmp_path / "trace_windows"
|
||||
subprocess.run(
|
||||
[
|
||||
"python3",
|
||||
"scripts/prepare_trace_windows.py",
|
||||
"--legacy-source",
|
||||
str(legacy_source),
|
||||
"--thinking-source",
|
||||
str(thinking_source),
|
||||
"--output-root",
|
||||
str(output_root),
|
||||
"--workloads",
|
||||
"chat",
|
||||
"--overwrite",
|
||||
],
|
||||
check=True,
|
||||
cwd="/home/gahow/phd/aituner",
|
||||
)
|
||||
|
||||
windows_payload = json.loads((output_root / "windows.json").read_text(encoding="utf-8"))
|
||||
windows = {item["window_id"]: item for item in windows_payload["windows"]}
|
||||
self.assertIn("chat_w20260311_peak_1000", windows)
|
||||
self.assertEqual(windows["chat_w20260311_peak_1000"]["num_requests"], 1)
|
||||
|
||||
trace_path = output_root / windows["chat_w20260311_peak_1000"]["trace_file"]
|
||||
rows = [json.loads(line) for line in trace_path.read_text(encoding="utf-8").splitlines()]
|
||||
self.assertEqual(len(rows), 1)
|
||||
self.assertEqual(rows[0]["prompt"], "real prompt")
|
||||
self.assertEqual(rows[0]["timestamp"], 5.0)
|
||||
self.assertEqual(rows[0]["output_length"], 7)
|
||||
self.assertIsInstance(rows[0]["sampling_u"], float)
|
||||
|
||||
def test_binary_search_max_feasible(self) -> None:
|
||||
result = binary_search_max_feasible(
|
||||
|
||||
Reference in New Issue
Block a user