Harden prefill scheduler harness
This commit is contained in:
@@ -3510,6 +3510,397 @@ class CoreFlowTests(unittest.TestCase):
|
||||
action["score_factors"]["uncovered_scheduler_dimension_bonus"],
|
||||
0.0,
|
||||
)
|
||||
families = {
|
||||
item["knob_family"] for item in context["experiment_plan"]["candidate_actions"]
|
||||
}
|
||||
self.assertNotIn("enable-chunked-prefill", families)
|
||||
|
||||
def test_prefill_scheduler_admission_pressure_only_uses_normalized_seq_cap(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
tmp_path = Path(tmp)
|
||||
study_path = _write_study_assets(
|
||||
tmp_path,
|
||||
trace_overrides={"max_concurrency": 64},
|
||||
engine_overrides={
|
||||
"base_flags": {
|
||||
"host": "127.0.0.1",
|
||||
"port": 8000,
|
||||
"tensor-parallel-size": 8,
|
||||
"data-parallel-size": 1,
|
||||
"max-num-batched-tokens": 8192,
|
||||
"max-num-seqs": 8,
|
||||
"enable-chunked-prefill": True,
|
||||
},
|
||||
"tunable_flags": [
|
||||
"tensor-parallel-size",
|
||||
"data-parallel-size",
|
||||
"max-num-batched-tokens",
|
||||
"max-num-seqs",
|
||||
"enable-chunked-prefill",
|
||||
],
|
||||
"topology_constraints": {
|
||||
"allowed_tensor_parallel_sizes": [8],
|
||||
"allowed_data_parallel_sizes": [1],
|
||||
"allowed_tp_dp_products": [8],
|
||||
},
|
||||
},
|
||||
)
|
||||
result_path = tmp_path / "trial-0001.json"
|
||||
result_path.write_text(
|
||||
json.dumps(
|
||||
{
|
||||
"status": "completed",
|
||||
"best_sampling_u": 0.5,
|
||||
"best_request_rate": 2.0,
|
||||
"best_pass_rate": 0.5,
|
||||
"probes": [
|
||||
{
|
||||
"threshold": 0.5,
|
||||
"feasible": False,
|
||||
"payload": {
|
||||
"request_rate": 2.0,
|
||||
"pass_rate": 0.5,
|
||||
"early_stop_reason": "slo_pass_rate_unrecoverable",
|
||||
"latency_summary": {"failed_reason_counts": {}},
|
||||
},
|
||||
}
|
||||
],
|
||||
}
|
||||
),
|
||||
encoding="utf-8",
|
||||
)
|
||||
study = load_study_spec(study_path)
|
||||
state = StudyState(
|
||||
study_id=study.study_id,
|
||||
best_trial_id="trial-0001",
|
||||
best_parallel_size=8,
|
||||
best_request_rate=2.0,
|
||||
best_request_rate_per_gpu=0.25,
|
||||
trials=[
|
||||
TrialSummary(
|
||||
trial_id="trial-0001",
|
||||
status="completed",
|
||||
parallel_size=8,
|
||||
best_request_rate=2.0,
|
||||
best_request_rate_per_gpu=0.25,
|
||||
result_path=str(result_path),
|
||||
config_patch={"env_patch": {}, "flag_patch": {}},
|
||||
)
|
||||
],
|
||||
)
|
||||
|
||||
context = build_harness_context(
|
||||
study=study,
|
||||
window_summary={"prompt_tokens_p95": 8192, "prompt_tail_ratio_p95_p50": 4.0},
|
||||
state=state,
|
||||
)
|
||||
|
||||
action = context["experiment_plan"]["next_action"]
|
||||
flag_patch = action["config_patch"]["flag_patch"]
|
||||
self.assertEqual(action["knob_family"], "prefill-scheduler-interaction")
|
||||
self.assertEqual(action["action_id"], "raise_admission_pressure_with_chunked_prefill")
|
||||
self.assertEqual(flag_patch["max-num-seqs"], 16)
|
||||
self.assertNotIn("max-num-batched-tokens", flag_patch)
|
||||
self.assertEqual(action["score_factors"]["admission_pressure_direction"], "raise")
|
||||
self.assertLess(
|
||||
action["score_factors"]["admission_pressure_ratio_current"],
|
||||
action["score_factors"]["admission_pressure_ratio_target"],
|
||||
)
|
||||
|
||||
def test_prefill_scheduler_lowers_excess_admission_pressure(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
tmp_path = Path(tmp)
|
||||
study_path = _write_study_assets(
|
||||
tmp_path,
|
||||
trace_overrides={"max_concurrency": 64},
|
||||
engine_overrides={
|
||||
"base_flags": {
|
||||
"host": "127.0.0.1",
|
||||
"port": 8000,
|
||||
"tensor-parallel-size": 8,
|
||||
"data-parallel-size": 1,
|
||||
"max-num-batched-tokens": 8192,
|
||||
"max-num-seqs": 128,
|
||||
"enable-chunked-prefill": True,
|
||||
},
|
||||
"tunable_flags": [
|
||||
"tensor-parallel-size",
|
||||
"data-parallel-size",
|
||||
"max-num-batched-tokens",
|
||||
"max-num-seqs",
|
||||
"enable-chunked-prefill",
|
||||
],
|
||||
"topology_constraints": {
|
||||
"allowed_tensor_parallel_sizes": [8],
|
||||
"allowed_data_parallel_sizes": [1],
|
||||
"allowed_tp_dp_products": [8],
|
||||
},
|
||||
},
|
||||
)
|
||||
result_path = tmp_path / "trial-0001.json"
|
||||
result_path.write_text(
|
||||
json.dumps(
|
||||
{
|
||||
"status": "completed",
|
||||
"best_sampling_u": 0.5,
|
||||
"best_request_rate": 2.0,
|
||||
"best_pass_rate": 0.95,
|
||||
"probes": [
|
||||
{
|
||||
"threshold": 0.5,
|
||||
"feasible": True,
|
||||
"payload": {
|
||||
"request_rate": 2.0,
|
||||
"pass_rate": 0.95,
|
||||
"latency_summary": {
|
||||
"failed_reason_counts": {"ttft_ms>4000.0": 24}
|
||||
},
|
||||
},
|
||||
}
|
||||
],
|
||||
}
|
||||
),
|
||||
encoding="utf-8",
|
||||
)
|
||||
study = load_study_spec(study_path)
|
||||
state = StudyState(
|
||||
study_id=study.study_id,
|
||||
best_trial_id="trial-0001",
|
||||
best_parallel_size=8,
|
||||
best_request_rate=2.0,
|
||||
best_request_rate_per_gpu=0.25,
|
||||
trials=[
|
||||
TrialSummary(
|
||||
trial_id="trial-0001",
|
||||
status="completed",
|
||||
parallel_size=8,
|
||||
best_request_rate=2.0,
|
||||
best_request_rate_per_gpu=0.25,
|
||||
result_path=str(result_path),
|
||||
config_patch={"env_patch": {}, "flag_patch": {}},
|
||||
)
|
||||
],
|
||||
)
|
||||
|
||||
context = build_harness_context(
|
||||
study=study,
|
||||
window_summary={"prompt_tokens_p95": 8192, "prompt_tail_ratio_p95_p50": 4.0},
|
||||
state=state,
|
||||
)
|
||||
|
||||
action = context["experiment_plan"]["next_action"]
|
||||
flag_patch = action["config_patch"]["flag_patch"]
|
||||
self.assertEqual(action["knob_family"], "prefill-scheduler-interaction")
|
||||
self.assertEqual(action["action_id"], "lower_admission_pressure_with_chunked_prefill")
|
||||
self.assertLess(flag_patch["max-num-seqs"], 128)
|
||||
self.assertNotIn("max-num-batched-tokens", flag_patch)
|
||||
self.assertEqual(action["score_factors"]["admission_pressure_direction"], "lower")
|
||||
self.assertLess(
|
||||
action["score_factors"]["admission_pressure_ratio_target"],
|
||||
action["score_factors"]["admission_pressure_ratio_current"],
|
||||
)
|
||||
|
||||
def test_prefill_scheduler_negative_applicability_matrix(self) -> None:
|
||||
variants = [
|
||||
(
|
||||
{"request_mode": "decode_only"},
|
||||
{"prompt_tokens_p95": 8192, "prompt_tail_ratio_p95_p50": 4.0},
|
||||
),
|
||||
(
|
||||
{},
|
||||
{
|
||||
"prompt_tokens_p95": 8192,
|
||||
"prompt_tail_ratio_p95_p50": 4.0,
|
||||
"prefix_cache": {"repeated_token_ratio_estimate": 0.75},
|
||||
},
|
||||
),
|
||||
(
|
||||
{},
|
||||
{"prompt_tokens_p95": 2048, "prompt_tail_ratio_p95_p50": 1.0},
|
||||
),
|
||||
]
|
||||
for trace_overrides, window_summary in variants:
|
||||
with self.subTest(trace_overrides=trace_overrides, window_summary=window_summary):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
tmp_path = Path(tmp)
|
||||
study_path = _write_study_assets(
|
||||
tmp_path,
|
||||
trace_overrides=trace_overrides,
|
||||
engine_overrides={
|
||||
"base_flags": {
|
||||
"host": "127.0.0.1",
|
||||
"port": 8000,
|
||||
"tensor-parallel-size": 8,
|
||||
"data-parallel-size": 1,
|
||||
"max-num-batched-tokens": 8192,
|
||||
"max-num-seqs": 8,
|
||||
"enable-chunked-prefill": True,
|
||||
},
|
||||
"tunable_flags": [
|
||||
"tensor-parallel-size",
|
||||
"data-parallel-size",
|
||||
"max-num-batched-tokens",
|
||||
"max-num-seqs",
|
||||
"enable-chunked-prefill",
|
||||
],
|
||||
"topology_constraints": {
|
||||
"allowed_tensor_parallel_sizes": [8],
|
||||
"allowed_data_parallel_sizes": [1],
|
||||
"allowed_tp_dp_products": [8],
|
||||
},
|
||||
},
|
||||
)
|
||||
result_path = tmp_path / "trial-0001.json"
|
||||
result_path.write_text(
|
||||
json.dumps(
|
||||
{
|
||||
"status": "completed",
|
||||
"best_sampling_u": 0.5,
|
||||
"best_request_rate": 2.0,
|
||||
"best_pass_rate": 0.95,
|
||||
"probes": [
|
||||
{
|
||||
"threshold": 0.5,
|
||||
"feasible": True,
|
||||
"payload": {
|
||||
"request_rate": 2.0,
|
||||
"pass_rate": 0.95,
|
||||
"latency_summary": {
|
||||
"failed_reason_counts": {
|
||||
"ttft_ms>4000.0": 24
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
],
|
||||
}
|
||||
),
|
||||
encoding="utf-8",
|
||||
)
|
||||
study = load_study_spec(study_path)
|
||||
state = StudyState(
|
||||
study_id=study.study_id,
|
||||
best_trial_id="trial-0001",
|
||||
best_parallel_size=8,
|
||||
best_request_rate=2.0,
|
||||
best_request_rate_per_gpu=0.25,
|
||||
trials=[
|
||||
TrialSummary(
|
||||
trial_id="trial-0001",
|
||||
status="completed",
|
||||
parallel_size=8,
|
||||
best_request_rate=2.0,
|
||||
best_request_rate_per_gpu=0.25,
|
||||
result_path=str(result_path),
|
||||
config_patch={"env_patch": {}, "flag_patch": {}},
|
||||
)
|
||||
],
|
||||
)
|
||||
|
||||
context = build_harness_context(
|
||||
study=study,
|
||||
window_summary=window_summary,
|
||||
state=state,
|
||||
)
|
||||
families = {
|
||||
item["knob_family"]
|
||||
for item in context["experiment_plan"]["candidate_actions"]
|
||||
}
|
||||
self.assertNotIn("prefill-scheduler-interaction", families)
|
||||
|
||||
def test_prefill_scheduler_does_not_preempt_open_topology_frontier(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
tmp_path = Path(tmp)
|
||||
study_path = _write_study_assets(
|
||||
tmp_path,
|
||||
engine_overrides={
|
||||
"base_flags": {
|
||||
"host": "127.0.0.1",
|
||||
"port": 8000,
|
||||
"tensor-parallel-size": 2,
|
||||
"data-parallel-size": 1,
|
||||
"max-num-batched-tokens": 8192,
|
||||
"max-num-seqs": 8,
|
||||
"enable-chunked-prefill": True,
|
||||
},
|
||||
"tunable_flags": [
|
||||
"tensor-parallel-size",
|
||||
"data-parallel-size",
|
||||
"max-num-batched-tokens",
|
||||
"max-num-seqs",
|
||||
"enable-chunked-prefill",
|
||||
],
|
||||
"topology_constraints": {
|
||||
"allowed_tensor_parallel_sizes": [2, 4],
|
||||
"allowed_data_parallel_sizes": [1, 2],
|
||||
"allowed_tp_dp_products": [4, 8],
|
||||
},
|
||||
},
|
||||
)
|
||||
result_path = tmp_path / "trial-0001.json"
|
||||
result_path.write_text(
|
||||
json.dumps(
|
||||
{
|
||||
"status": "completed",
|
||||
"best_sampling_u": 0.5,
|
||||
"best_request_rate": 2.0,
|
||||
"best_pass_rate": 0.95,
|
||||
"probes": [
|
||||
{
|
||||
"threshold": 0.5,
|
||||
"feasible": True,
|
||||
"payload": {
|
||||
"request_rate": 2.0,
|
||||
"pass_rate": 0.95,
|
||||
"latency_summary": {
|
||||
"failed_reason_counts": {"ttft_ms>4000.0": 24}
|
||||
},
|
||||
},
|
||||
}
|
||||
],
|
||||
}
|
||||
),
|
||||
encoding="utf-8",
|
||||
)
|
||||
study = load_study_spec(study_path)
|
||||
state = StudyState(
|
||||
study_id=study.study_id,
|
||||
best_trial_id="trial-0001",
|
||||
best_parallel_size=4,
|
||||
best_request_rate=2.0,
|
||||
best_request_rate_per_gpu=0.5,
|
||||
trials=[
|
||||
TrialSummary(
|
||||
trial_id="trial-0001",
|
||||
status="completed",
|
||||
parallel_size=4,
|
||||
best_request_rate=2.0,
|
||||
best_request_rate_per_gpu=0.5,
|
||||
result_path=str(result_path),
|
||||
config_patch={
|
||||
"env_patch": {},
|
||||
"flag_patch": {"data-parallel-size": 2},
|
||||
},
|
||||
)
|
||||
],
|
||||
)
|
||||
|
||||
context = build_harness_context(
|
||||
study=study,
|
||||
window_summary={"prompt_tokens_p95": 8192, "prompt_tail_ratio_p95_p50": 4.0},
|
||||
state=state,
|
||||
)
|
||||
|
||||
action = context["experiment_plan"]["next_action"]
|
||||
self.assertEqual(action["knob_family"], "topology")
|
||||
self.assertEqual(
|
||||
action["config_patch"]["flag_patch"],
|
||||
{"tensor-parallel-size": 4, "data-parallel-size": 2},
|
||||
)
|
||||
families = {
|
||||
item["knob_family"] for item in context["experiment_plan"]["candidate_actions"]
|
||||
}
|
||||
self.assertNotIn("prefill-scheduler-interaction", families)
|
||||
|
||||
def test_prefill_scheduler_not_active_for_short_prompt_workload(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
|
||||
Reference in New Issue
Block a user