Download scripts/read_calls.py from humanfia-lab/hmz-logits: direct link, hf CLI and curl.
- Browser
- Download file 1.84 kB
-
https://huggingface.co/datasets/humanfia-lab/hmz-logits/resolve/main/scripts/read_calls.py
- Command line
-
hf download hf://datasets/humanfia-lab/hmz-logits/scripts/read_calls.py
-
curl -L -o read_calls.py https://huggingface.co/datasets/humanfia-lab/hmz-logits/resolve/main/scripts/read_calls.py
1.84 kB
| """read_calls.py TREE_DIR [N]: print the first N Qwen calls of a tree with their LOT session and the top | |
| logprobs of the first generated tokens, and show how a call's prompt is rebuilt from blobs.jsonl.zst. | |
| pip install zstandard | |
| python scripts/read_calls.py imo2025-qwen3.8-27b-lot/IMO2025-P4 3 | |
| """ | |
| import glob | |
| import io | |
| import json | |
| import math | |
| import sys | |
| import zstandard | |
| def jsonl_zst(path): | |
| with open(path, "rb") as fh: | |
| for line in io.TextIOWrapper(zstandard.ZstdDecompressor().stream_reader(fh), encoding="utf-8"): | |
| if line.strip(): | |
| yield json.loads(line) | |
| def calls(tree_dir): | |
| for path in sorted(glob.glob(f"{tree_dir}/calls/*.jsonl.zst")): | |
| yield from jsonl_zst(path) | |
| def blobs(tree_dir): | |
| return {b["h"]: b["v"] for b in jsonl_zst(f"{tree_dir}/blobs.jsonl.zst")} | |
| def prompt(call, blob): | |
| """The Anthropic Messages request Claude Code sent, with system, tools and messages filled in.""" | |
| req = dict(call["request"]) | |
| for k in ("system", "tools"): | |
| if k in req: | |
| req[k] = blob[req[k]] | |
| req["messages"] = [blob[h] for h in req["messages"]] | |
| return req | |
| if __name__ == "__main__": | |
| tree_dir, n = sys.argv[1], int(sys.argv[2]) if len(sys.argv) > 2 else 3 | |
| blob = blobs(tree_dir) | |
| for i, c in enumerate(calls(tree_dir)): | |
| if i >= n: | |
| break | |
| req = prompt(c, blob) | |
| out = c["output"] | |
| print(f"=== call {c['call_id']} LOT session {c['option']} ({c['role']} on {c['obligation']}) " | |
| f"{len(req['messages'])} messages in, {len(c['logprobs'])} tokens out, finish {out['finish_reason']}") | |
| for tok, lp, top in c["logprobs"][:5]: | |
| alts = ", ".join(f"{t!r}:{math.exp(l):.3f}" for t, l in top[:5]) | |
| print(f" {tok!r} p={math.exp(lp):.3f} top5: {alts}") | |