Files
vllm-omni/benchmarks/edge_harness/experiments/ppl_vllm.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

58 lines
2.1 KiB
Python

"""Teacher-forced perplexity of a text file under a vLLM model.
Quantization is scored against the same engine's own bf16 run, not against
llama.cpp's: each engine tokenizes and chunks its own way, and comparing the
*increase* over an in-engine baseline cancels that, where comparing absolute
perplexity across engines would not.
"""
import argparse, json, math
def main():
ap = argparse.ArgumentParser()
ap.add_argument("--model", required=True)
ap.add_argument("--corpus", required=True)
ap.add_argument("--window", type=int, default=512)
ap.add_argument("--max-chunks", type=int, default=0)
ap.add_argument("--tag", default="")
ap.add_argument("--out", default="ppl.jsonl")
a = ap.parse_args()
import vllm_omni # noqa: F401
from vllm import LLM, SamplingParams
llm = LLM(model=a.model, dtype="bfloat16", max_model_len=a.window + 8,
max_num_seqs=1, enable_prefix_caching=False,
trust_remote_code=False, disable_log_stats=True)
tok = llm.get_tokenizer()
ids = tok(open(a.corpus).read(), add_special_tokens=False)["input_ids"]
chunks = [ids[i:i + a.window] for i in range(0, len(ids) - a.window + 1, a.window)]
if a.max_chunks:
chunks = chunks[: a.max_chunks]
sp = SamplingParams(temperature=0.0, max_tokens=1, prompt_logprobs=0,
ignore_eos=True, detokenize=False)
outs = llm.generate([{"prompt_token_ids": c} for c in chunks], sp, use_tqdm=False)
total_nll, n = 0.0, 0
for o, c in zip(outs, chunks):
pl = o.prompt_logprobs
# position 0 has no prediction behind it
for pos in range(1, len(c)):
entry = pl[pos]
lp = entry[c[pos]].logprob
total_nll -= lp
n += 1
ppl = math.exp(total_nll / n)
rec = {"tag": a.tag or a.model, "model": a.model, "window": a.window,
"chunks": len(chunks), "scored_tokens": n,
"nll": total_nll / n, "ppl": ppl}
print(json.dumps(rec, indent=2))
with open(a.out, "a") as f:
f.write(json.dumps(rec) + "\n")
if __name__ == "__main__":
main()