ranjith035's picture
Upload folder using huggingface_hub
ff11803 verified
Raw History Blame Contribute Delete
2.74 kB
"""Experiment 001 Step 2: GPU offload sweep (0, 8, 16, 24, 99) with telemetry."""
from __future__ import annotations
import argparse
from pathlib import Path
import time
from engine.benchmark import run_single_benchmark
from engine.llama_runner import LlamaRunner
from monitoring.gpu_monitor import GPUMonitor
from monitoring.metrics import append_results_csv
from scheduler.memory_manager import load_hardware_config
def run_offload_sweep(
cfg: dict,
model_path: str,
layers_sweep: list[int],
results_csv: str,
sample_interval_sec: float = 0.5,
cooldown_sec: float = 5.0,
) -> Path:
"""Run a GPU-layer offload sweep and append results to CSV."""
paths = cfg["paths"]
defaults = cfg["inference_defaults"]
monitor = GPUMonitor()
runner = LlamaRunner(bench_exe=paths["llama_bench_exe"], cli_exe=paths.get("llama_cli_exe"))
records = []
try:
for idx, ngl in enumerate(layers_sweep):
print(f"[{idx + 1}/{len(layers_sweep)}] Testing gpu_layers={ngl}...")
record = run_single_benchmark(
runner=runner,
monitor=monitor,
model_path=model_path,
gpu_layers=ngl,
prompt_tokens=int(defaults["prompt_tokens"]),
gen_tokens=int(defaults["gen_tokens"]),
repetitions=int(defaults["repetitions"]),
sample_interval_sec=sample_interval_sec,
)
records.append(record.to_dict())
print(
f" status={record.status} | pp={record.prompt_tok_s} tok/s | "
f"tg={record.gen_tok_s} tok/s | peak_vram={record.peak_vram_mb} MiB | "
f"peak_temp={record.peak_gpu_temp_c} C"
)
if idx < len(layers_sweep) - 1 and cooldown_sec > 0:
time.sleep(cooldown_sec)
out = append_results_csv(records, results_csv)
print(f"Saved {len(records)} records to {Path(out)}")
return Path(out)
finally:
monitor.close()
def main() -> None:
parser = argparse.ArgumentParser(description="Run Experiment 001 GPU offload sweep.")
parser.add_argument("--config", default="config/hardware.yaml", help="Path to hardware.yaml")
args = parser.parse_args()
cfg = load_hardware_config(args.config)
paths = cfg["paths"]
exp = cfg["experiment_001"]
run_offload_sweep(
cfg=cfg,
model_path=paths["model_path"],
layers_sweep=[int(x) for x in exp["layers_sweep"]],
results_csv=paths["results_csv"],
sample_interval_sec=float(exp.get("sample_interval_sec", 0.5)),
cooldown_sec=float(exp.get("cooldown_sec", 5)),
)
if __name__ == "__main__":
main()