Files
wehub-resource-sync 426e9eeabd
Voice Workbench / headless workbench (mocked backends) (push) Has been cancelled
Voice Workbench / real acoustic lane (nightly, provisioned only) (push) Has been cancelled
ci / test (push) Has been cancelled
ci / lint-and-format (push) Has been cancelled
ci / build (push) Has been cancelled
ci / dev-startup (push) Has been cancelled
gitleaks / gitleaks (push) Has been cancelled
Markdown Links / Relative Markdown Links (push) Has been cancelled
Quality (Extended) / Homepage Build (PR smoke) (push) Has been cancelled
Quality (Extended) / Comment-only diff guard (push) Has been cancelled
Quality (Extended) / Format + Type Safety Ratchet (push) Has been cancelled
Quality (Extended) / Develop Gate (secret scan + UI determinism) (push) Has been cancelled
Quality (Extended) / Develop Gate (lint) (push) Has been cancelled
Chat shell gestures / Chat shell gesture + parity e2e (push) Has been cancelled
Cloud Gateway Discord / Test (push) Has been cancelled
Benchmark Bridge Tests / benchmark (bunx @biomejs/biome check packages/lifeops-bench/src, benchmark-lint) (push) Has been cancelled
Benchmark Bridge Tests / benchmark (bunx vitest run --config packages/lifeops-bench/vitest.config.ts --root packages/lifeops-bench --passWithNoTests, benchmark-tests) (push) Has been cancelled
Build Agent Image / build-and-push (push) Has been cancelled
Dev Smoke / bun run dev onboarding chat (push) Has been cancelled
Dev Smoke / Vite HMR dependency-level smoke (push) Has been cancelled
Electrobun Submodule Guard / electrobun gitlink is fetchable (push) Has been cancelled
Publish @elizaos/example-code / check_npm (push) Has been cancelled
Publish @elizaos/example-code / publish_npm (push) Has been cancelled
Publish @elizaos/plugin-elizacloud / verify_version (push) Has been cancelled
Publish @elizaos/plugin-elizacloud / publish_npm (push) Has been cancelled
Sandbox Live Smoke / Sandbox live smoke (push) Has been cancelled
Snap Build & Test / Build Snap (amd64) (push) Has been cancelled
Snap Build & Test / Build Snap (arm64) (push) Has been cancelled
Test Packaging / elizaos CLI global-install smoke (node + bun) (push) Has been cancelled
Cloud Gateway Webhook / Test (push) Has been cancelled
Cloud Tests / lint-and-types (push) Has been cancelled
Cloud Tests / unit-tests (push) Has been cancelled
Cloud Tests / integration-tests (push) Has been cancelled
Cloud Tests / e2e-tests (push) Has been cancelled
CodeQL Advanced / Analyze (javascript-typescript) (push) Has been cancelled
Deploy Apps Worker (Product 2) / Determine environment (push) Has been cancelled
Deploy Apps Worker (Product 2) / Deploy apps worker to apps-control host (${{ needs.determine-env.outputs.environment }}) (push) Has been cancelled
Deploy Eliza Provisioning Worker / Determine environment (push) Has been cancelled
Deploy Eliza Provisioning Worker / Deploy worker to Hetzner host (${{ needs.determine-env.outputs.environment }} @ ${{ needs.determine-env.outputs.deployment_sha }}) (push) Has been cancelled
Dev Smoke / Classify changed paths (push) Has been cancelled
supply-chain / sbom (push) Has been cancelled
supply-chain / vulnerability-scan (push) Has been cancelled
Build, Push & Deploy to Phala Cloud / build-and-push (push) Has been cancelled
Test Packaging / Validate Packaging Configs (push) Has been cancelled
Test Packaging / Build & Test PyPI Package (push) Has been cancelled
Test Packaging / PyPI on Python ${{ matrix.python }} (push) Has been cancelled
Test Packaging / Pack & Test JS Tarballs (push) Has been cancelled
UI Fixture E2E / ui-fixture-e2e (push) Has been cancelled
UI Fixture E2E / fixture-e2e (push) Has been cancelled
UI Story Gate / story-gate (push) Has been cancelled
vault-ci / test (macos-latest) (push) Has been cancelled
vault-ci / test (ubuntu-latest) (push) Has been cancelled
vault-ci / test (windows-latest) (push) Has been cancelled
vault-ci / app-core wiring tests (push) Has been cancelled
verify-patches / verify patches/CHECKSUMS.sha256 (push) Has been cancelled
Voice Benchmark Smoke / voice-emotion fixture smoke (push) Has been cancelled
Voice Benchmark Smoke / voiceagentbench fixture smoke (push) Has been cancelled
Voice Benchmark Smoke / voicebench-quality unit smoke (push) Has been cancelled
Voice Benchmark Smoke / voicebench TypeScript unit (no audio) (push) Has been cancelled
Voice Benchmark Smoke / voice bench smoke summary (push) Has been cancelled
Windows CI / windows ([bun run --cwd packages/app-core test bun run --cwd packages/elizaos test bun run --cwd packages/cloud/shared test], app-and-cli) (push) Has been cancelled
Windows CI / windows ([bun run --cwd packages/scenario-runner test bun run --cwd packages/vault test bun run --cwd packages/security test bun run --cwd plugins/plugin-coding-tools test], framework-packages) (push) Has been cancelled
Windows CI / windows ([bun run --cwd plugins/plugin-elizacloud test bun run --cwd plugins/plugin-discord test bun run --cwd plugins/plugin-anthropic test bun run --cwd plugins/plugin-openai test bun run --cwd plugins/plugin-app-control test bun run --cwd plugins/pl… (push) Has been cancelled
Windows CI / windows ([node packages/scripts/run-turbo.mjs run build --filter=@elizaos/core --filter=@elizaos/shared --filter=@elizaos/agent --concurrency=4 node packages/scripts/run-bash-linux-only.mjs scripts/verify-riscv64-buildpaths.sh node packages/scripts/run… (push) Has been cancelled
Windows CI / windows ([node packages/scripts/run-turbo.mjs run typecheck --filter=@elizaos/core --filter=@elizaos/shared --filter=@elizaos/cloud-shared --concurrency=4 bun run --cwd packages/core test bun run --cwd packages/shared test], core-runtime, 75) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:43:05 +08:00

161 lines
6.4 KiB
Python

"""Kernel manifest fragment helper — zero deps on torch / transformers.
Per packages/training/AGENTS.md §3, every quantization recipe MUST emit a
sidecar manifest fragment recording: kernel target, block layout version,
codebook hash, expected per-block tolerance. The fragment is consumed by
the inference manifest builder at publish time.
This module owns the canonical pin between training-side recipes and the
kernel references in ``plugins/plugin-local-inference/native/{reference,verify}``
and ``packages/native/plugins/{qjl-cpu,polarquant-cpu}``. When a kernel
constant changes, the matching pinned sha256 here MUST be bumped in lockstep,
otherwise recipe sidecar generation fails.
The helper has no torch/transformers imports so unit tests can validate
manifest correctness without loading a model.
"""
from __future__ import annotations
import hashlib
from pathlib import Path
_REPO_ROOT = Path(__file__).resolve().parents[4]
# Content hashed for each target. QJL has no centroid table; its pin covers the
# public block-layout header that defines the 34-byte qjl1_256 cache record.
KERNEL_CODEBOOK_HASH_SOURCES = {
"turbo3": ("plugins/plugin-local-inference/native/reference/turbo_kernels.c",),
"turbo4": ("plugins/plugin-local-inference/native/reference/turbo_kernels.c",),
"turbo3_tcq": ("plugins/plugin-local-inference/native/reference/turbo_kernels.c",),
"polar_q4": (
"packages/native/plugins/polarquant-cpu/include/polarquant/polar_centroids.h",
),
"qjl1_256": ("packages/native/plugins/qjl-cpu/include/qjl/qjl.h",),
}
PINNED_KERNEL_CODEBOOK_SHA256 = {
"turbo3": "d2fe34ddf270c3de0ea78dc840bf18f8bc9c9175c32489700ed62e70c7a95429",
"turbo4": "d2fe34ddf270c3de0ea78dc840bf18f8bc9c9175c32489700ed62e70c7a95429",
"turbo3_tcq": "d2fe34ddf270c3de0ea78dc840bf18f8bc9c9175c32489700ed62e70c7a95429",
"polar_q4": "6f0e9e204f10df190385e8f0f60055db2adbfabc611ade503be3f888eb04d399",
"qjl1_256": "84048dea7812cf87e0c002aa2be69443e4228c10b326a9e5b1aa2d3668fbab58",
}
KERNEL_CODEBOOK_HASHES = {
target: f"sha256:{digest}"
for target, digest in PINNED_KERNEL_CODEBOOK_SHA256.items()
}
# Block layout versions. A non-backward-compatible change to any of these
# layouts MUST bump the version string and force a re-encode of every
# shipped bundle. The version strings are read by the runtime loader.
KERNEL_BLOCK_LAYOUT_VERSIONS = {
"turbo3": "block_turbo3_0:v1",
"turbo4": "block_turbo4_0:v1",
"turbo3_tcq": "block_turbo3_tcq:v1",
"polar_q4": "block_q4_polar:v1:82bytes:packed",
"qjl1_256": "block_qjl1_256:v1:34bytes:packed",
}
# Kernel targets per recipe. The runtime checks these against the device's
# kernel capabilities before activating a bundle (see inference/AGENTS.md §6
# manifest schema, kernels.required field).
KERNEL_TARGETS = {
"turboquant": ["turbo3", "turbo4", "turbo3_tcq"],
"fused-turboquant": ["turbo3", "turbo4", "turbo3_tcq"],
"qjl": ["qjl1_256"],
"polarquant": ["polar_q4"],
}
KERNEL_RECIPE_TARGET_CLASSES = {
"turboquant": "kv-cache",
"fused-turboquant": "kv-cache",
"qjl": "kv-cache",
"polarquant": "weights",
}
# Expected per-block tolerance (max-abs reconstruction error vs fp32) at the
# canonical settings. Used by the verify/* harnesses and the publish gate.
# Numbers come from the published papers + the verify/ harness self-test.
KERNEL_PER_BLOCK_TOLERANCE = {
"turbo3": 5.0e-2, # 3-bit, 8 levels, post-rotation
"turbo4": 1.0e-2, # 4-bit, 16 levels
"turbo3_tcq": 3.0e-2, # 3-bit trellis, 512-state Viterbi
"qjl1_256": 5.0e-2, # 1-bit JL — sign-only, looser tol
"polar_q4": 1.0e-3, # 4-bit Lloyd-Max + Hadamard, near-lossless
}
def _sha256_sources(relative_paths: tuple[str, ...]) -> str:
"""Hash one or more source files in the order declared for a target."""
digest = hashlib.sha256()
for rel in relative_paths:
path = _REPO_ROOT / rel
if not path.is_file():
raise RuntimeError(f"kernel hash source missing: {rel}")
digest.update(path.read_bytes())
return digest.hexdigest()
def verify_kernel_codebook_hashes(
targets: list[str] | tuple[str, ...] | None = None,
) -> dict[str, str]:
"""Return actual source sha256 values, failing if any pin has drifted."""
selected = list(targets) if targets is not None else sorted(KERNEL_TARGETS_BY_NAME)
actual: dict[str, str] = {}
errors: list[str] = []
for target in selected:
sources = KERNEL_CODEBOOK_HASH_SOURCES.get(target)
expected = PINNED_KERNEL_CODEBOOK_SHA256.get(target)
if sources is None or expected is None:
errors.append(f"{target}: missing hash source or pinned digest")
continue
got = _sha256_sources(sources)
actual[target] = got
if got != expected:
errors.append(f"{target}: expected {expected}, got {got}")
if errors:
raise RuntimeError("kernel codebook hash drift: " + "; ".join(errors))
return actual
KERNEL_TARGETS_BY_NAME = {
target
for targets in KERNEL_TARGETS.values()
for target in targets
}
def kernel_manifest_fragment(method: str) -> dict[str, object]:
"""Build the AGENTS.md §3 sidecar manifest fragment for a recipe.
Returns a dict carrying:
- ``kernel_target``: list of kernel names this recipe expects on device
- ``block_layout_version``: per-target block layout version strings
- ``codebook_hash``: per-target codebook identifier
- ``per_block_tolerance``: per-target reconstruction tolerance (fp32)
The fields are required by the publish gate. A recipe that omits any of
them is publish-blocking. See AUDIT_2026-05-10.md for the rationale.
"""
if method not in KERNEL_TARGETS:
raise ValueError(
f"kernel_manifest_fragment: unknown method {method!r}; "
f"known: {sorted(KERNEL_TARGETS)}"
)
targets = KERNEL_TARGETS[method]
verify_kernel_codebook_hashes(tuple(targets))
return {
"kernel_target": list(targets),
"block_layout_version": {t: KERNEL_BLOCK_LAYOUT_VERSIONS[t] for t in targets},
"codebook_hash": {t: KERNEL_CODEBOOK_HASHES[t] for t in targets},
"codebook_hash_source": {
t: list(KERNEL_CODEBOOK_HASH_SOURCES[t]) for t in targets
},
"per_block_tolerance": {t: KERNEL_PER_BLOCK_TOLERANCE[t] for t in targets},
"target_class": KERNEL_RECIPE_TARGET_CLASSES[method],
}