Add replay time scaling for smoke tuning

This commit is contained in:
2026-04-04 22:40:49 +08:00
parent dcb972014a
commit 56fa6747d2
4 changed files with 95 additions and 2 deletions

View File

@@ -152,6 +152,7 @@ class TraceSpec:
max_concurrency: int
max_requests_per_probe: int | None = None
synthetic_prompt_cap_tokens: int | None = None
replay_time_scale: float = 1.0
@classmethod
def from_dict(cls, data: Mapping[str, Any]) -> "TraceSpec":
@@ -172,6 +173,9 @@ class TraceSpec:
synthetic_prompt_cap_tokens=(
int(synthetic_prompt_cap) if synthetic_prompt_cap is not None else None
),
replay_time_scale=_require_float(
data.get("replay_time_scale", 1.0), context="trace.replay_time_scale"
),
)

View File

@@ -134,6 +134,18 @@ def _downsample_requests(
def load_trace_requests(study: StudySpec, *, study_spec_path: Path) -> tuple[WindowRecord, list[TraceRequest]]:
window = resolve_window_record(study, study_spec_path=study_spec_path)
time_scale = float(study.trace.replay_time_scale)
if time_scale <= 0:
raise TraceError("trace.replay_time_scale must be > 0")
if time_scale != 1.0:
window = WindowRecord(
window_id=window.window_id,
trace_path=window.trace_path,
trace_type=window.trace_type,
window_start=window.window_start * time_scale,
window_end=window.window_end * time_scale,
source_payload=dict(window.source_payload),
)
requests: list[TraceRequest] = []
with window.trace_path.open("r", encoding="utf-8") as handle:
for idx, raw in enumerate(handle):
@@ -181,7 +193,7 @@ def load_trace_requests(study: StudySpec, *, study_spec_path: Path) -> tuple[Win
requests.append(
TraceRequest(
row_id=str(row.get("request_id") or row.get("id") or idx),
arrival_s=float(timestamp),
arrival_s=float(timestamp) * time_scale,
sampling_u=float(sampling_u),
body=body,
prompt_tokens_hint=prompt_tokens_hint,