MCPcopy Create free account
hub / github.com/Luce-Org/lucebox-hub / run_cases

Function run_cases

server/scripts/phase_split_dual_gpu.py:498–658  ·  view source on GitHub ↗
(args, cases: list[tuple[str, str, str | None, str | None]])

Source from the content-addressed store, hash-verified

496
497
498def run_cases(args, cases: list[tuple[str, str, str | None, str | None]]) -> None:
499 args.report_dir.mkdir(parents=True, exist_ok=True)
500 tokenizer = load_tokenizer(args)
501 target_tokenizer = load_target_tokenizer(args) if args.run_target else None
502 pflash_monitor = GpuMonitor(args.report_dir / f"pflash_gpu_monitor_{args.pflash_backend}.csv",
503 args.pflash_backend)
504 target_monitor = (
505 GpuMonitor(args.report_dir / f"target_gpu_monitor_{args.target_backend}.csv",
506 args.target_backend)
507 if args.run_target else None
508 )
509 monitors = [pflash_monitor] + ([target_monitor] if target_monitor else [])
510 daemon = PFlashDaemon(
511 binary=args.pflash_bin,
512 drafter=args.pflash_drafter,
513 gpu=args.pflash_gpu,
514 backend=args.pflash_backend,
515 visible_devices=args.pflash_visible_devices,
516 log_path=args.report_dir / "pflash_daemon.log",
517 env=make_pflash_env(args),
518 )
519 results: list[CompressionCase] = []
520 target_failures: list[dict[str, int | str]] = []
521 try:
522 for monitor in monitors:
523 monitor.start()
524 set_monitor_phase(monitors, "pflash_load")
525 ready_s = daemon.start()
526 for name, text, key, answer in cases:
527 case_dir = args.report_dir / name
528 case_dir.mkdir(parents=True, exist_ok=True)
529 ids = tokenizer.encode(text, add_special_tokens=False)
530 (case_dir / "prompt.txt").write_text(text, encoding="utf-8")
531 counted = case_dir / "prompt_counted.bin"
532 write_counted_i32(counted, ids)
533
534 set_monitor_phase(monitors, name)
535 kept, wall_s = daemon.compress(
536 counted,
537 keep_ratio=args.keep_ratio,
538 lookahead=args.lookahead,
539 chunk_size=args.chunk_size,
540 pool_kernel=args.pool_kernel,
541 )
542 if not kept:
543 raise RuntimeError(
544 f"PFlash compression returned no tokens; see {args.report_dir / 'pflash_daemon.log'}")
545 compressed_text = tokenizer.decode(kept, skip_special_tokens=True)
546 (case_dir / "compressed.txt").write_text(compressed_text, encoding="utf-8")
547 write_counted_i32(case_dir / "compressed_counted.bin", kept)
548
549 target_result: dict[str, float | int | str] | None = None
550 if args.run_target:
551 set_monitor_phase(monitors, f"{name}_target")
552 assert target_tokenizer is not None
553 target_result = run_target_generation(
554 args, case_dir, compressed_text, target_tokenizer)
555

Callers 2

run_promptFunction · 0.85
run_bench_niahFunction · 0.85

Calls 15

startMethod · 0.95
compressMethod · 0.95
stopMethod · 0.95
load_tokenizerFunction · 0.85
load_target_tokenizerFunction · 0.85
GpuMonitorClass · 0.85
PFlashDaemonClass · 0.85
make_pflash_envFunction · 0.85
set_monitor_phaseFunction · 0.85
run_target_generationFunction · 0.85
CompressionCaseClass · 0.85
parse_device_listFunction · 0.85

Tested by

no test coverage detected