6262 QUERIES_METRIC ,
6363 build_pool_accuracy_prompt ,
6464 extract_pool_answer ,
65+ resolve_model_path ,
6566 run_pool_ab ,
6667 run_pool_hit_sequence ,
68+ snapshot_metrics ,
6769)
70+ from tools .aisbench import run_aisbench_cases
6871
6972BLOCK_SIZE = 128
7073POOL_SECRET = "7391"
@@ -118,6 +121,7 @@ class PoolABCase:
118121 perf_batch_requests : int = 8
119122 perf_sample_count : int = 3
120123 perf_warmup_count : int = 1
124+ perf_aisbench : dict [str , Any ] | None = None
121125 token_identity : bool = False
122126 acceptance_ratio : float | None = None
123127
@@ -617,6 +621,50 @@ def _run_follower_legs(
617621 channel .close ()
618622
619623
624+ def _aisbench_perf_case (
625+ config : ExternalDPConfig ,
626+ spec : dict [str , Any ],
627+ * ,
628+ name : str ,
629+ num_prompts : int ,
630+ batch_size : int ,
631+ ) -> dict [str , Any ]:
632+ """Build one AISBench performance case that reads the 128K prefix90 dataset."""
633+ case = {
634+ "benchmark_name" : name ,
635+ "case_type" : "performance" ,
636+ "dataset_path" : spec ["dataset_path" ],
637+ "dataset_conf" : spec ["dataset_conf" ],
638+ "request_conf" : spec ["request_conf" ],
639+ "model_path" : spec .get ("model_path" ) or config .model ,
640+ "num_prompts" : int (num_prompts ),
641+ "batch_size" : int (batch_size ),
642+ "max_out_len" : int (spec .get ("max_out_len" , 1 )),
643+ "request_rate" : int (spec .get ("request_rate" , 0 )),
644+ }
645+ if spec .get ("seed" ) is not None :
646+ case ["seed" ] = int (spec ["seed" ])
647+ # CI has no shared dataset mount: only pin dataset_path_local when the case
648+ # YAML provides one, otherwise AISBench downloads the ModelScope dataset.
649+ local_path = spec .get ("dataset_path_local" ) or os .environ .get ("KV_POOL_PERF_DATASET_LOCAL" )
650+ if local_path :
651+ case ["dataset_path_local" ] = local_path
652+ return case
653+
654+
655+ def _aisbench_input_throughput (result : Any ) -> float :
656+ """Extract the input token throughput (token/s) from an AISBench perf result."""
657+ payload = result [1 ] if isinstance (result , (list , tuple )) and len (result ) > 1 else result
658+ if not isinstance (payload , dict ):
659+ raise RuntimeError (f"unexpected AISBench perf result: { type (result ).__name__ } " )
660+ value : Any = payload .get ("Input Token Throughput" )
661+ if isinstance (value , dict ):
662+ value = value .get ("total" ) or next (iter (value .values ()), None )
663+ if value is None :
664+ raise RuntimeError (f"Input Token Throughput missing in AISBench result: { list (payload )} " )
665+ return float (str (value ).replace ("token/s" , "" ).strip ())
666+
667+
620668def run_pool_ab_case () -> None :
621669 """Run the pool A/B watch described by ``CONFIG_YAML_PATH``."""
622670 config , case = load_case ()
@@ -634,7 +682,9 @@ def run_pool_ab_case() -> None:
634682 return
635683
636684 max_model_len = _max_model_len (config )
637- tokenizer = AutoTokenizer .from_pretrained (config .model , trust_remote_code = True )
685+ tokenizer = AutoTokenizer .from_pretrained (
686+ resolve_model_path (config .model ), trust_remote_code = True
687+ )
638688 prefix = build_pool_accuracy_prompt (
639689 tokenizer , case .prompt_tokens , max_model_len , secret = case .secret
640690 )
@@ -673,6 +723,59 @@ def hit(runner: Any) -> dict[str, Any]:
673723 summary ["hit_outputs" ] = summary ["hit_outputs" ][:1 ]
674724 return summary
675725
726+ def perf (runner : Any , use_pool : bool ) -> float :
727+ spec = case .perf_aisbench
728+ if not spec :
729+ raise RuntimeError ("pool_ab.perf_aisbench is required for the AISBench perf phase" )
730+ warmup = spec .get ("warmup" ) or {}
731+ if warmup :
732+ run_aisbench_cases (
733+ model = runner .served_model_name ,
734+ port = runner .proxy_port ,
735+ host_ip = runner .proxy_host ,
736+ aisbench_cases = [
737+ _aisbench_perf_case (
738+ config ,
739+ spec ,
740+ name = "kv_pool_prefix90_warmup" ,
741+ num_prompts = int (warmup .get ("num_prompts" , 4 )),
742+ batch_size = int (warmup .get ("batch_size" , 4 )),
743+ )
744+ ],
745+ )
746+ before = snapshot_metrics (runner ) if use_pool else None
747+ results = run_aisbench_cases (
748+ model = runner .served_model_name ,
749+ port = runner .proxy_port ,
750+ host_ip = runner .proxy_host ,
751+ aisbench_cases = [
752+ _aisbench_perf_case (
753+ config ,
754+ spec ,
755+ name = "kv_pool_prefix90" ,
756+ num_prompts = int (spec ["num_prompts" ]),
757+ batch_size = int (spec ["batch_size" ]),
758+ )
759+ ],
760+ )
761+ if use_pool and before is not None :
762+ after = snapshot_metrics (runner )
763+ queries = after .queries - before .queries
764+ hits = after .hits - before .hits
765+ ratio = hits / queries if queries > 0 else 0.0
766+ target = float (spec .get ("hit_rate_target" ) or 0.0 )
767+ tolerance = float (spec .get ("hit_rate_tolerance" , 0.03 ))
768+ print (
769+ f"[kv_pool_hitrate] leg=a hit_tokens={ hits :.0f} query_tokens={ queries :.0f} "
770+ f"ratio={ ratio :.4f} target={ target :.4f} " ,
771+ flush = True ,
772+ )
773+ if target and abs (ratio - target ) > tolerance :
774+ raise AssertionError (
775+ f"perf hit ratio { ratio :.4f} outside { target :.4f} ±{ tolerance :.4f} "
776+ )
777+ return _aisbench_input_throughput (results [- 1 ])
778+
676779 with _ControlServer (case .control_port , expected_clients = config .num_nodes - 1 ) as control :
677780
678781 def build_leg (use_pool : bool , case_name : str ):
@@ -701,5 +804,7 @@ def build_leg(use_pool: bool, case_name: str):
701804 perf_batch_requests = case .perf_batch_requests ,
702805 perf_sample_count = case .perf_sample_count ,
703806 perf_warmup_count = case .perf_warmup_count ,
807+ # Cases without pool_ab.perf_aisbench keep the legacy local sampling.
808+ perf_fn = perf if case .perf_aisbench else None ,
704809 perf_gate = case .perf_gate ,
705810 )
0 commit comments