Files
vllm-omni/benchmarks/edge_harness/experiments/ref_hf.py
T
tzhouamandClaude Opus 5 3834de3105 Rename the project to edge-infer, and complete the packaging audit
Renamed from vllm-embedding: nothing here is about embeddings, and the name had
come from the parent working directory. edge-infer says what it does. The
GitHub repository is renamed to match; nothing had been pushed yet.

The audit found the packaging was incomplete in two ways.

Scripts: 56 of them produced results that are published in this repo but were
not included, so the numbers could be read and not checked. Added under
benchmarks/edge_harness/experiments/ (one-off drivers: the AI Hub on-device
runs, the 4-bit GEMM microbenchmark, fidelity and parity checks, checkpoint
build and round-trip, activation capture, and the load generator used to prove
the contention guard actually refuses) and benchmarks/edge_harness/runs/ (the
24 shell drivers behind published grids). Both directories carry a README
saying plainly that they are a record of what was run rather than a supported
interface -- most hardcode absolute paths from the machine they ran on. The
supported entry points remain the tools one level up.

One broken relative link fixed (comparison.md is under docs/engines/, not
docs/analysis/). All other links and every script reference in the docs now
resolve inside the repo.

Secret scan: the token in ~/.qai_hub/client.ini is absent from the worktree and
from all 61 commits. Worth noting that an earlier version of my own check
reported a false positive, because `grep -rl ... | head` takes its exit status
from head, which always succeeds -- the same class of mistake as the measurement
errors this project keeps recording. The AI Hub scripts authenticate by reading
that file at runtime and contain no credential.

README reframed for the new name and the wider scope: the repository is the
engine changes, the harness, the raw results, the baselines and the analyses,
not just a patch set.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L1ax5wYLA6XbqEL1i8L9gZ
2026-09-14 14:21:07 +08:00

74 lines
2.9 KiB
Python

"""Ground-truth Spark-X2.5 run using the official remote code on
transformers 4.57.1 (the version config.json was written for)."""
import argparse, json
import numpy as np
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
MODEL = "XHToken/Spark-X2.5-1.7B"
def build_msgs(scenario):
if scenario == "short":
return [{"role": "user", "content": "What is the capital of France? Answer in one word."}]
if scenario == "long":
# >512 tokens so the 512-window sliding layers actually slide and
# diverge from the full-attention layers.
filler = " ".join(
f"Item {i}: the code for warehouse district {i} is {1000 + i * 7}."
for i in range(1, 121)
)
return [{"role": "user", "content":
"Here is an inventory listing.\n" + filler +
"\nWhat is the code for warehouse district 73? Answer with just the number."}]
if scenario == "tools":
return [
{"role": "system", "content": "You are a helpful assistant with tools."},
{"role": "user", "content": "What is the weather in Shenzhen right now, in celsius?"},
]
raise ValueError(scenario)
TOOLS = [{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather for a city.",
"parameters": {
"type": "object",
"properties": {
"city": {"type": "string", "description": "City name"},
"unit": {"type": "string", "enum": ["celsius", "fahrenheit"]},
},
"required": ["city"],
},
},
}]
ap = argparse.ArgumentParser()
ap.add_argument("--n-new", type=int, default=24)
ap.add_argument("--dtype", default="bfloat16")
ap.add_argument("--scenario", default="short", choices=["short","long","tools"])
ap.add_argument("--out", default="ref.json")
ap.add_argument("--logits-out", default="ref_logits.npy")
a = ap.parse_args()
tok = AutoTokenizer.from_pretrained(MODEL, trust_remote_code=True)
kw = {"tools": TOOLS} if a.scenario == "tools" else {}
prompt = tok.apply_chat_template(build_msgs(a.scenario), tokenize=False,
add_generation_prompt=True, **kw)
ids = tok(prompt, add_special_tokens=False)["input_ids"]
m = AutoModelForCausalLM.from_pretrained(
MODEL, trust_remote_code=True, dtype=getattr(torch, a.dtype)).eval()
t = torch.tensor([ids])
with torch.no_grad():
logits = m(t).logits[0, -1].float().numpy()
gen = m.generate(t, max_new_tokens=a.n_new, do_sample=False, pad_token_id=2)
new = gen[0, len(ids):].tolist()
np.save(a.logits_out, logits)
json.dump({"prompt": prompt, "prompt_ids": ids, "new_ids": new,
"text": tok.decode(new), "dtype": a.dtype,
"top1": int(np.argmax(logits)), "scenario": a.scenario}, open(a.out, "w"), indent=2)
print("prompt_len", len(ids), "| top1", int(np.argmax(logits)))
print("text:", repr(tok.decode(new)))