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
50 lines
2.6 KiB
Python
50 lines
2.6 KiB
Python
"""Real inputs for the output head: the last layer's output, pre-final-norm."""
|
|
import importlib.util, json, sys, types
|
|
from pathlib import Path
|
|
import numpy as np, torch
|
|
|
|
ROOT = Path("/data/zhoutaichang/embedding_infer/vllm-omni")
|
|
HERE = Path("/data/zhoutaichang/embedding_infer/analysis/experiments/spark_edge")
|
|
def _load(n, p):
|
|
sp = importlib.util.spec_from_file_location(n, p); m = importlib.util.module_from_spec(sp)
|
|
sys.modules[n] = m; sp.loader.exec_module(m); return m
|
|
for pkg in ("vllm_omni", "vllm_omni.edge"):
|
|
mod = types.ModuleType(pkg); mod.__path__ = []; sys.modules[pkg] = mod
|
|
_load("vllm_omni.edge.qnn_export", ROOT / "vllm_omni/edge/qnn_export.py")
|
|
se = _load("vllm_omni.edge.spark_export", ROOT / "vllm_omni/edge/spark_export.py")
|
|
|
|
from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
MODEL = "XHToken/Spark-X2.5-1.7B"
|
|
SNAP = ("/data/zhoutaichang/.cache/huggingface/hub/models--XHToken--Spark-X2.5-1.7B/"
|
|
"snapshots/448e61eb392c00f2c403185c5b56d5e0665bfaab")
|
|
TEXTS = ["The quick brown fox jumps over the lazy dog. " * 60,
|
|
"Engineers argued about memory bandwidth on the train home. " * 60,
|
|
"def forward(self, x):\n return self.down(self.act(self.gate(x)))\n" * 60,
|
|
"移动端推理的瓶颈通常是内存带宽而不是算力。" * 80]
|
|
|
|
tok = AutoTokenizer.from_pretrained(MODEL, trust_remote_code=True)
|
|
m = AutoModelForCausalLM.from_pretrained(MODEL, trust_remote_code=True,
|
|
dtype=torch.float32).eval()
|
|
hf = json.loads(Path(f"{SNAP}/config.json").read_text())
|
|
cfg = se.config_from_spark(hf, slice(0, 0), include_lm_head=True)
|
|
step = se.SparkDecodeStep(cfg); se.load_spark_weights(step, SNAP); step.eval()
|
|
|
|
grabbed = {}
|
|
h = m.model.layers[-1].register_forward_hook(
|
|
lambda mod, inp, out: grabbed.__setitem__("h", out[0] if isinstance(out, tuple) else out))
|
|
xs, outs = [], []
|
|
for t in TEXTS:
|
|
ids = tok(t, add_special_tokens=False)["input_ids"][:256]
|
|
with torch.no_grad():
|
|
m(torch.tensor([ids]))
|
|
x = grabbed["h"][:, -1:, :].float()
|
|
logits = step(x, *[torch.zeros(1)] * 0) if False else step(
|
|
x, torch.zeros(1,1,1,4), torch.zeros(1,1,1,4),
|
|
torch.zeros(1,1,1,4), torch.zeros(1,1,1,4),
|
|
torch.zeros(1,1,1,1), torch.zeros(1,1,1,1))[0]
|
|
xs.append(x.numpy().astype(np.float32)); outs.append(logits.numpy().astype(np.float32))
|
|
h.remove()
|
|
np.savez(HERE / "real_acts_lmhead.npz", x=np.stack(xs), hidden_out=np.stack(outs))
|
|
print("captured", len(TEXTS), "| x absmax", np.abs(np.stack(xs)).max(),
|
|
"| logits absmax", np.abs(np.stack(outs)).max())
|