Files
benchmarks/dev/tests/test_model_hash.py
T
claudeandClaude Opus 5.5 5bb750cece
ci / check (push) Successful in 58s
0.5.0: model hash check, energy per phase, honest bandwidth %, CI
- The served model is hashed (cached) and checked against dev/models.tsv;
  the model_file note says standard or not, with warnings for a foreign
  file or a --quant that doesn't match. HASH_MODEL=0 skips it.
- The BetterBench build (git commit or describe) goes into meta and, when
  it isn't the release, into the run note.
- Energy per phase from a timestamped timeline.tsv: J/token for decode and
  each concurrency level, J/1k tokens for prefill.
- Bandwidth %: vLLM's loaded weight size when available, MTP files left out
  of the stored size, bandwidth scaled by tp.
- The notes and post-run Python moved to dev/notes.py and dev/postrun.py,
  with pytest tests; CI runs shellcheck, build --check and the tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-29 14:00:00 +01:00

32 lines
1.2 KiB
Python

"""model_hash.py must match the README's commands exactly."""
import os
import subprocess
import sys
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import model_hash # noqa: E402
def sh(cmd, cwd):
return subprocess.run(["sh", "-c", cmd], cwd=cwd, capture_output=True, text=True,
check=True).stdout.split()[0]
def test_directory_hash_matches_sha256sum(tmp_path):
# model_mtp sorts before model. in en_US but after it in C: the README pins C
(tmp_path / "model.safetensors").write_bytes(b"weights" * 1000)
(tmp_path / "model_mtp.safetensors").write_bytes(b"mtp head")
(tmp_path / "config.json").write_text("{}")
want = sh("sha256sum *.safetensors | LC_ALL=C sort -k2 | sha256sum", tmp_path)
assert model_hash.model_sha256(str(tmp_path), cache={}) == want
def test_file_hash_and_cache(tmp_path):
f = tmp_path / "m.gguf"
f.write_bytes(b"gguf" * 5000)
cache = {}
assert model_hash.model_sha256(str(f), cache) == sh("sha256sum m.gguf", tmp_path)
key = next(iter(cache))
cache[key] = "cached"
assert model_hash.model_sha256(str(f), cache) == "cached" # same size and mtime: no rehash