Datasets:
Download code/kaggle_runner.py from ahkamboh/stepmold-bench: direct link, hf CLI and curl.
- Browser
- Download file 4.35 kB
-
https://huggingface.co/datasets/ahkamboh/stepmold-bench/resolve/main/code/kaggle_runner.py
- Command line
-
hf download hf://datasets/ahkamboh/stepmold-bench/code/kaggle_runner.py
-
curl -L -o kaggle_runner.py https://huggingface.co/datasets/ahkamboh/stepmold-bench/resolve/main/code/kaggle_runner.py
4.35 kB
| """Serve each small model with vLLM on Kaggle's two T4s, run the stepmold bench, keep the results. | |
| Runs top to bottom with no input, so it works as a "Save & Run All" commit. Each model's | |
| results go to /kaggle/working/results/<label>.jsonl, appended and resumable, so a rerun only | |
| does the case-runs that are missing. | |
| """ | |
| import hashlib | |
| import json | |
| import os | |
| import signal | |
| import subprocess | |
| import sys | |
| import tarfile | |
| import time | |
| import urllib.request | |
| WORK = "/kaggle/working" | |
| OUT = os.path.join(WORK, "results") | |
| BENCH = os.path.join(WORK, "stepmold-bench") | |
| STEPMOLD = os.path.join(WORK, "stepmold") # a clone at 38235ab: pip installs leave out examples/ | |
| PORT = 8000 | |
| # One sampling setup for every model, so three runs of a case show how consistent it is. | |
| # 0.7 and top_p 0.8 are Qwen's recommended non-thinking settings. Qwen3 runs with thinking | |
| # off, the same way the stepmold GPU Space runs Qwen3 8B. | |
| QWEN = {"temperature": 0.7, "top_p": 0.8} | |
| NO_THINK = {"chat_template_kwargs": {"enable_thinking": False}} | |
| MODELS = [ | |
| # label, Hugging Face id, tensor-parallel size, request extras | |
| ("qwen2.5-0.5b-instruct", "Qwen/Qwen2.5-0.5B-Instruct", 1, QWEN), | |
| ("qwen2.5-1.5b-instruct", "Qwen/Qwen2.5-1.5B-Instruct", 1, QWEN), | |
| ("qwen3-4b", "Qwen/Qwen3-4B", 1, dict(QWEN, **NO_THINK)), | |
| ("qwen2.5-7b-instruct", "Qwen/Qwen2.5-7B-Instruct", 2, QWEN), | |
| ("qwen3-8b", "Qwen/Qwen3-8B", 2, dict(QWEN, **NO_THINK)), | |
| ] | |
| def wait_ready(proc, timeout=1500): | |
| deadline = time.time() + timeout | |
| while time.time() < deadline: | |
| if proc.poll() is not None: | |
| raise RuntimeError("vLLM exited with code %s" % proc.returncode) | |
| try: | |
| with urllib.request.urlopen("http://localhost:%d/v1/models" % PORT, timeout=5) as reply: | |
| if reply.status == 200: | |
| return | |
| except Exception: | |
| pass | |
| time.sleep(5) | |
| raise TimeoutError("vLLM did not come up within %ds" % timeout) | |
| def serve(model, tp, log): | |
| cmd = [ | |
| "vllm", "serve", model, | |
| "--dtype", "half", # a T4 has no bf16 | |
| "--tensor-parallel-size", str(tp), | |
| "--max-model-len", "4096", | |
| "--gpu-memory-utilization", "0.90", | |
| "--port", str(PORT), | |
| ] | |
| return subprocess.Popen(cmd, stdout=log, stderr=subprocess.STDOUT, start_new_session=True) | |
| def stop(proc): | |
| try: | |
| os.killpg(proc.pid, signal.SIGTERM) | |
| proc.wait(timeout=120) | |
| except subprocess.TimeoutExpired: | |
| os.killpg(proc.pid, signal.SIGKILL) | |
| except ProcessLookupError: | |
| pass | |
| time.sleep(15) # let the GPUs release their memory before the next model loads | |
| def run_model(label, model, tp, extra): | |
| started = time.time() | |
| with open(os.path.join(OUT, label + ".vllm.log"), "w") as log: | |
| proc = serve(model, tp, log) | |
| try: | |
| wait_ready(proc) | |
| print("%s: server ready in %.0fs" % (label, time.time() - started), flush=True) | |
| subprocess.run([ | |
| sys.executable, os.path.join(BENCH, "bench.py"), | |
| "--stepmold", STEPMOLD, | |
| "--model", "openai:http://localhost:%d/v1#%s" % (PORT, model), | |
| "--label", label, | |
| "--arms", "stepmold,plain_schema,plain", | |
| "--runs", "3", | |
| "--packs", "all", | |
| "--concurrency", "16", | |
| "--extra-body", json.dumps(extra), | |
| "--out", os.path.join(OUT, label + ".jsonl"), | |
| ], check=False) | |
| except Exception as exc: | |
| print("%s: FAILED: %s" % (label, exc), flush=True) | |
| finally: | |
| stop(proc) | |
| print("%s: finished in %.0fs" % (label, time.time() - started), flush=True) | |
| def main(only=None): | |
| os.makedirs(OUT, exist_ok=True) | |
| digest = hashlib.sha256(open(os.path.join(BENCH, "bench.py"), "rb").read()).hexdigest()[:12] | |
| print("bench.py sha256", digest, flush=True) | |
| for label, model, tp, extra in MODELS: | |
| if not only or label in only: | |
| run_model(label, model, tp, extra) | |
| with tarfile.open(os.path.join(WORK, "stepmold-bench-kaggle-results.tar.gz"), "w:gz") as tar: | |
| tar.add(OUT, arcname="results") | |
| print("packed", os.path.join(WORK, "stepmold-bench-kaggle-results.tar.gz"), flush=True) | |
| if __name__ == "__main__": | |
| main(set(sys.argv[1:]) or None) | |