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

48 lines
1.8 KiB
Python

"""Export the sliding layer with F.rms_norm at a higher opset.
The calibrated layer spends ~11% of its cycles in an unfused RMSNorm
(Pow/ReduceMean/Div/Mul), where the earlier build had a single fused `rms`
op at 1%. ONNX opset 23 has a real RMSNormalization node; if the exporter
emits it and QNN maps it to its fused kernel, that 11% largely goes away.
"""
import json, sys
from pathlib import Path
import torch
sys.path.insert(0, "/data/zhoutaichang/embedding_infer/vllm-omni")
import vllm_omni.edge.spark_export as se
SNAP = ("/data/zhoutaichang/.cache/huggingface/hub/models--XHToken--Spark-X2.5-1.7B/"
"snapshots/448e61eb392c00f2c403185c5b56d5e0665bfaab")
HERE = Path("/data/zhoutaichang/embedding_infer/analysis/experiments/spark_edge")
_orig = se._rms
def _rms_fused(x, weight, eps):
return torch.nn.functional.rms_norm(x, (x.shape[-1],), weight=weight, eps=eps)
hf = json.loads(Path(f"{SNAP}/config.json").read_text())
i = hf["layer_types"].index(se.SLIDING)
for tag, fn, opset in (("rmsfused_op23", _rms_fused, 23),
("rmsfused_op18", _rms_fused, 18)):
se._rms = fn
cfg = se.config_from_spark(hf, slice(i, i + 1), include_lm_head=False,
cache_layout="ring")
step = se.SparkDecodeStep(cfg)
se.load_spark_weights(step, SNAP)
out = HERE / f"onnx/{tag}_sliding.onnx"
try:
info = se.export_onnx(step, 1024, out, opset=opset)
import onnx
g = onnx.load(str(out), load_external_data=False)
ops = {n.op_type for n in g.graph.node}
print(tag, "OK ->", out.name,
"| RMSNormalization" if "RMSNormalization" in ops else "| decomposed",
"| ops:", len(g.graph.node), flush=True)
except Exception as e:
print(tag, "export FAILED:", str(e)[:200], flush=True)
se._rms = _orig