Skip to content

Kyojin: open-source engine that runs 100 GB-class open models (GLM-5.3, Qwen3.8, DeepSeek V4.1) on one desktop machine. AMD Strix Halo, NVIDIA RTX and Apple Mac. OpenAI API, built on ExLlamaV3.

Hy4 decode: column-tiled few-row dense Q8_0 GEMV (HY4_DENSE_V2, default off): activations in registers, next column prefetched, bit-identical to fq_gemv_q8_0; micro test, ABBA driver, opbench flag hash

YanissAmz833de84e6edb
diff --git a/exllamav3/gm_ext/gm_bindings.cpp b/exllamav3/gm_ext/gm_bindings.cpp
index 4abd50e..496039d 100644
--- a/exllamav3/gm_ext/gm_bindings.cpp
+++ b/exllamav3/gm_ext/gm_bindings.cpp
@@ -2,6 +2,7 @@
#include <pybind11/stl.h>
#include "gm_router.cuh"
#include "gm_moe.cuh"
+#include "gm_dense_q8.cuh"
PYBIND11_MODULE(TORCH_EXTENSION_NAME, m)
{
m.def("gm_routing_std_bsz1", &gm_routing_std_bsz1, "gm_routing_std_bsz1");
@@ -10,6 +11,7 @@ PYBIND11_MODULE(TORCH_EXTENSION_NAME, m)
py::arg("down_ptrs"), py::arg("gate_stride"), py::arg("up_stride"), py::arg("down_stride"), py::arg("fmt_d"), py::arg("act"), py::arg("qb"),
py::arg("partial"), py::arg("out"), py::arg("resid"), py::arg("fmt_gu") = 0, py::arg("lim") = 0.0, py::arg("meta") = at::Tensor());
m.def("gm_q8_swiglu_down", &gm_q8_swiglu_down, "gm_q8_swiglu_down");
+ m.def("gm_dense_q8", &gm_dense_q8, "gm_dense_q8");
m.def("gm_route", &gm_route, "gm_route");
m.def("gm_pf_gate_up", &gm_pf_gate_up, "gm_pf_gate_up");
m.def("gm_pf_down", &gm_pf_down, "gm_pf_down");
diff --git a/exllamav3/gm_ext/gm_dense_q8.cu b/exllamav3/gm_ext/gm_dense_q8.cu
new file mode 100644
index 0000000..aeac4cf
--- /dev/null
+++ b/exllamav3/gm_ext/gm_dense_q8.cu
@@ -0,0 +1,200 @@
+// Dense Q8_0 x q8_1 decode GEMV, few rows, column-tiled (HY4_DENSE_V2): one block = nt threads (the thread -> chunk map of
+// fq_gemv_q8_q8_kernel / fq_gemv_q8_q8_mrows_kernel, exllamav3_ext/foreign_quant/fq_gemv_q8.cu) walks `cpb` consecutive columns.
+// What changes against the stock kernels: the q8_1 activation blocks of every row are loaded ONCE per thread into registers
+// (stock: reloaded for every column, 9 loads per row per chunk), the weight block of the next column is in flight while the
+// current one is dotted, and one barrier + one ordered reduction per column replace one block launch per column.
+// Arithmetic per output is identical to the stock kernels (same int8 dot, same per-thread fp32 chain over chunk tid, tid + nt, ...,
+// same sequential sum over the nt thread slots): bit-identical at every row count.
+#if defined(USE_ROCM)
+
+#include <hip/hip_runtime.h>
+#include <hip/hip_fp16.h>
+#include <ATen/cuda/CUDAContext.h>
+#include <c10/cuda/CUDAGuard.h>
+#include <torch/extension.h>
+#include <cstdint>
+#include <cstring>
+#include <type_traits>
+#include "gm_dense_q8.cuh"
+
+#define GDQ_Q8_1_BYTES 36
+#define GDQ_Q8_0_BYTES 34
+
+namespace {
+
+__device__ __forceinline__ int gdq_dp4a(int a, int b, int c)
+{
+ return __builtin_amdgcn_sudot4(true, a, true, b, c, false);
+}
+
+template <int NCH>
+struct GdqW
+{
+ int32_t q[NCH][8];
+ float d[NCH];
+};
+
+template <int NCH>
+__device__ __forceinline__ void gdq_load_w(GdqW<NCH>& w, const uint8_t* wr, int tid, int nt, int nchunks, bool on)
+{
+ #pragma unroll
+ for (int ch = 0; ch < NCH; ch++)
+ {
+ int c = tid + ch * nt;
+ if (on && c < nchunks)
+ {
+ const uint8_t* blk = wr + (size_t)c * GDQ_Q8_0_BYTES;
+ __half dwh;
+ memcpy(&dwh, blk, 2);
+ w.d[ch] = __half2float(dwh);
+ const uint16_t* w16 = reinterpret_cast<const uint16_t*>(blk + 2);
+ #pragma unroll
+ for (int j2 = 0; j2 < 8; j2++)
+ w.q[ch][j2] = (int32_t)(w16[j2 * 2] | ((uint32_t)w16[j2 * 2 + 1] << 16));
+ }
+ }
+}
+
+template <typename OUT, int MR, int NCH>
+__global__ void gdq_kernel(const uint8_t* __restrict__ aqb, const uint8_t* __restrict__ packed, OUT* __restrict__ out,
+ int M, int N, int K, int64_t packed_stride, int64_t qb_stride, int cpb)
+{
+ const int tid = threadIdx.x, nt = blockDim.x;
+ const int n0 = blockIdx.x * cpb;
+ const int m0 = blockIdx.y * MR;
+ const int mc = min(MR, M - m0);
+ const int nchunks = K / 32;
+ const int rs = nt + 4; // padded row stride of the reduction buffer (float4 reads, spread banks)
+ extern __shared__ float red[]; // [2][MR][rs]
+
+ int32_t aq[NCH][MR][8];
+ float da[NCH][MR];
+ #pragma unroll
+ for (int ch = 0; ch < NCH; ch++)
+ {
+ int c = tid + ch * nt;
+ #pragma unroll
+ for (int r = 0; r < MR; r++)
+ {
+ if (r < mc && c < nchunks)
+ {
+ const uint8_t* ab = aqb + (int64_t)(m0 + r) * qb_stride + (size_t)c * GDQ_Q8_1_BYTES;
+ __half dah;
+ memcpy(&dah, ab, 2);
+ da[ch][r] = __half2float(dah);
+ const int32_t* aq32 = reinterpret_cast<const int32_t*>(ab + 4);
+ #pragma unroll
+ for (int j2 = 0; j2 < 8; j2++)
+ aq[ch][r][j2] = aq32[j2];
+ }
+ }
+ }
+
+ GdqW<NCH> cur, nxt;
+ gdq_load_w<NCH>(cur, packed + (int64_t)n0 * packed_stride, tid, nt, nchunks, n0 < N);
+ for (int j = 0; j < cpb; j++)
+ {
+ const int n = n0 + j;
+ if (n >= N)
+ break;
+ gdq_load_w<NCH>(nxt, packed + (int64_t)(n + 1) * packed_stride, tid, nt, nchunks, j + 1 < cpb && n + 1 < N);
+ float acc[MR];
+ #pragma unroll
+ for (int r = 0; r < MR; r++) acc[r] = 0.0f;
+ #pragma unroll
+ for (int ch = 0; ch < NCH; ch++)
+ {
+ if (tid + ch * nt < nchunks)
+ {
+ #pragma unroll
+ for (int r = 0; r < MR; r++)
+ {
+ if (r < mc)
+ {
+ int sumi = 0;
+ #pragma unroll
+ for (int j2 = 0; j2 < 8; j2++)
+ sumi = gdq_dp4a(cur.q[ch][j2], aq[ch][r][j2], sumi);
+ acc[r] = __fadd_rn(acc[r], __fmul_rn(__fmul_rn(cur.d[ch], da[ch][r]), (float)sumi));
+ }
+ }
+ }
+ }
+ float* rb = red + (size_t)(j & 1) * MR * rs;
+ #pragma unroll
+ for (int r = 0; r < MR; r++) rb[r * rs + tid] = acc[r];
+ __syncthreads();
+ if (tid < mc)
+ {
+ const float4* p = reinterpret_cast<const float4*>(rb + tid * rs);
+ float s = 0.0f;
+ #pragma unroll 4
+ for (int l = 0; l < nt / 4; l++)
+ {
+ float4 v = p[l];
+ s = __fadd_rn(s, v.x);
+ s = __fadd_rn(s, v.y);
+ s = __fadd_rn(s, v.z);
+ s = __fadd_rn(s, v.w);
+ }
+ if constexpr (std::is_same<OUT, __half>::value)
+ out[(int64_t)(m0 + tid) * N + n] = __float2half_rn(s);
+ else
+ out[(int64_t)(m0 + tid) * N + n] = s;
+ }
+ cur = nxt;
+ }
+}
+
+template <typename OUT, int MR, int NCH>
+void gdq_launch(const at::Tensor& qb, const at::Tensor& packed, OUT* o, int M, int N, int K, int cpb, int nt, cudaStream_t stream)
+{
+ int64_t pstride = (int64_t)(K / 32) * GDQ_Q8_0_BYTES, qstride = (int64_t)(K / 32) * GDQ_Q8_1_BYTES;
+ dim3 grid((N + cpb - 1) / cpb, (M + MR - 1) / MR);
+ size_t shmem = (size_t)2 * MR * (nt + 4) * sizeof(float);
+ gdq_kernel<OUT, MR, NCH><<<grid, nt, shmem, stream>>>(qb.data_ptr<uint8_t>(), packed.data_ptr<uint8_t>(), o, M, N, K, pstride, qstride, cpb);
+}
+
+template <typename OUT, int NCH>
+void gdq_rows(const at::Tensor& qb, const at::Tensor& packed, OUT* o, int M, int N, int K, int cpb, int nt, cudaStream_t stream)
+{
+ if (M <= 1) gdq_launch<OUT, 1, NCH>(qb, packed, o, M, N, K, cpb, nt, stream);
+ else if (M == 2) gdq_launch<OUT, 2, NCH>(qb, packed, o, M, N, K, cpb, nt, stream);
+ else if (M <= 4) gdq_launch<OUT, 4, NCH>(qb, packed, o, M, N, K, cpb, nt, stream);
+ else gdq_launch<OUT, 8, NCH>(qb, packed, o, M, N, K, cpb, nt, stream);
+}
+
+} // namespace
+
+// qb: [M, K/32*36] uint8 (fq_quant_q8_1_rows), packed: [N, K/32, 34] uint8, out: [M, N] float or half. cpb = columns per block.
+// Returns false when the shape is outside the kernel (K > 16384 or K % 32): the caller keeps the stock launch.
+bool gm_dense_q8(const at::Tensor& qb, const at::Tensor& packed, at::Tensor& out, int64_t cpb)
+{
+ TORCH_CHECK(qb.is_cuda() && packed.is_cuda() && out.is_cuda(), "tensors must be CUDA");
+ TORCH_CHECK(qb.is_contiguous() && packed.is_contiguous() && out.is_contiguous(), "tensors must be contiguous");
+ int M = (int)qb.size(0), N = (int)packed.size(0), K = (int)packed.size(1) * 32;
+ TORCH_CHECK(packed.dim() == 3 && packed.size(2) == GDQ_Q8_0_BYTES && (int)out.size(0) == M && (int)out.size(1) == N, "shape mismatch");
+ TORCH_CHECK((int)qb.size(1) == (K / 32) * GDQ_Q8_1_BYTES, "qb width must match K");
+ int nchunks = K / 32;
+ int nt = nchunks >= 256 ? 256 : ((nchunks + 31) / 32) * 32;
+ int nch = (nchunks + nt - 1) / nt;
+ if (nch > 2 || M < 1 || cpb < 1)
+ return false;
+ at::cuda::CUDAGuard guard(qb.device());
+ auto stream = at::cuda::getCurrentCUDAStream().stream();
+ auto go = [&](auto* op)
+ {
+ using O = std::decay_t<decltype(*op)>;
+ if (nch == 1) gdq_rows<O, 1>(qb, packed, op, M, N, K, (int)cpb, nt, stream);
+ else gdq_rows<O, 2>(qb, packed, op, M, N, K, (int)cpb, nt, stream);
+ };
+ if (out.dtype() == torch::kHalf)
+ go(reinterpret_cast<__half*>(out.data_ptr<at::Half>()));
+ else if (out.dtype() == torch::kFloat)
+ go(out.data_ptr<float>());
+ else
+ return false;
+ return true;
+}
+
+#endif
diff --git a/exllamav3/gm_ext/gm_dense_q8.cuh b/exllamav3/gm_ext/gm_dense_q8.cuh
new file mode 100644
index 0000000..13a40ad
--- /dev/null
+++ b/exllamav3/gm_ext/gm_dense_q8.cuh
@@ -0,0 +1,5 @@
+#pragma once
+#if defined(USE_ROCM)
+#include <ATen/Tensor.h>
+bool gm_dense_q8(const at::Tensor& qb, const at::Tensor& packed, at::Tensor& out, int64_t cpb);
+#endif
diff --git a/exllamav3/loader/attn_grouped.py b/exllamav3/loader/attn_grouped.py
index b0a9f62..1e32718 100644
--- a/exllamav3/loader/attn_grouped.py
+++ b/exllamav3/loader/attn_grouped.py
@@ -9,7 +9,7 @@ and one launch replace n. Results are cached per input tensor (identity + versio
from __future__ import annotations
import torch
-from .hy4_forward import QLinear, DENSE_MAXR
+from .hy4_forward import QLinear, DENSE_MAXR, dense_gemv
from . import dense_req as _DR
# attribute names of the MLA object that read the layer input `cur` (wq_a, wkv_a, wgate); keyed by role, not by model
@@ -35,7 +35,7 @@ class _Group:
x2 = x.reshape(-1, self.K)
xf = x2.float().contiguous()
out = torch.empty(xf.shape[0], sum(self.sizes), dtype=torch.float32, device=x.device)
- self.gemv(xf, self.packed, out)
+ dense_gemv(self.gemv, xf, self.packed, out)
if self.stats is not None:
self.stats["dense_gemv"] = self.stats.get("dense_gemv", 0) + 1
self.stats["attn_grouped_calls"] = self.stats.get("attn_grouped_calls", 0) + 1
diff --git a/exllamav3/loader/hy4_forward.py b/exllamav3/loader/hy4_forward.py
index e75ef99..a69b23d 100644
--- a/exllamav3/loader/hy4_forward.py
+++ b/exllamav3/loader/hy4_forward.py
@@ -268,6 +268,23 @@ def dense_fn(ty, K):
_TM_HOLD = [None] # the live _Tm (stage timers inside prefill dense calls)
+DENSE_V2 = [os.environ.get("HY4_DENSE_V2", "0") == "1"] # 1 = 2..16 decode rows with K <= 8192 through gm_ext gm_dense_q8 (column-tiled Q8_0 GEMV, activations in registers; bit-identical to fq_gemv_q8_0); read at call time (graph re-capture flips it)
+DENSE_V2_KMAX = 8192 # above this (wo K=16384, layer-0 FFN down) the stock launch is as fast (opbench / dend_test 20/11)
+
+
+def dense_gemv(gemv, xf, packed, out):
+ """out = Q8_0 GEMV of the [R, K] float rows xf: the stock launch, or (HY4_DENSE_V2, R >= 2) quantise once + the column-tiled kernel (1 / 2 / 3 columns per block at R <= 4 / <= 8 / more: measured best)"""
+ if DENSE_V2[0] and xf.shape[0] >= 2 and xf.shape[1] <= DENSE_V2_KMAX and getattr(gemv, "__name__", "") == "fq_gemv_q8_0":
+ g, e = _gm(), _ext()
+ if g is not None and e is not None and hasattr(g, "gm_dense_q8"):
+ R, K = xf.shape
+ qb = e.fq_q8_scratch(xf.device.index, R, K)
+ e.fq_quant_q8_1_rows(xf, qb)
+ if g.gm_dense_q8(qb, packed, out, 1 if R <= 4 else (2 if R <= 8 else 3)):
+ return
+ gemv(xf, packed, out)
+
+
class QLinear:
"""a dense [N, K] matrix kept as STORED bytes on the device; `x @ q.T` / q(x) = x [.., K] -> [.., N]"""
@@ -291,7 +308,7 @@ class QLinear:
if x2.shape[0] <= DENSE_MAXR and self.gemv is not None:
xf = x2.float().contiguous()
out = torch.empty(xf.shape[0], N, dtype=torch.float32, device=x.device)
- self.gemv(xf, self.packed, out)
+ dense_gemv(self.gemv, xf, self.packed, out)
if self.stats is not None:
self.stats["dense_gemv"] = self.stats.get("dense_gemv", 0) + 1
elif PF_DENSE and self.ty in (13, 14) and x2.is_cuda: # requantised dense (HY4_DENSE_REQ_ARMS): fp16 dequant + fp16 GEMM, like the Q8_0 prefill path
diff --git a/tools/hy4/step/ab_dend.py b/tools/hy4/step/ab_dend.py
new file mode 100644
index 0000000..bdf56aa
--- /dev/null
+++ b/tools/hy4/step/ab_dend.py
@@ -0,0 +1,51 @@
+"""ab_dend.py: ONE load; paired ABBA graph-replay verify-round wall, T = 1..6, ctx 1000 / 4000, arm A = stock dense Q8_0 GEMV, arm B = HY4_DENSE_V2 (gm_ext gm_dense_q8 for 2..16 rows, K <= 8192).
+cwd = tree. Env: EXL3_GM_BUILD_DIR (the gm_ext build holding gm_dense_q8), PCTXS, PTS. Arm flip = fwm.DENSE_V2[0] + GR.clear() (graphs re-captured). Prints per-T ms for both arms, the logit equality (bit-identical expected) and the dense launch count."""
+import json, os, statistics, sys, time
+tree = os.getcwd()
+sys.path.insert(0, os.path.join(tree, "tools", "hy4"))
+import serve
+serve.apply_env(16384)
+import torch
+from engine import Hy4Engine
+GGUF = os.environ.get("GGUF", "/home/kamel/models/hy4-flash-gguf/Hy4-flash-Q3_K-00001-of-00002.gguf")
+e = Hy4Engine(tree, GGUF, ctx=16384, k=3)
+e.load(print)
+GR, M = e.GR, e.M
+fwm = sys.modules[type(M).__module__]
+g = fwm._gm()
+print("gm_ext", None if g is None else (g.__file__, hasattr(g, "gm_dense_q8")), flush=True)
+assert g is not None and hasattr(g, "gm_dense_q8"), "gm_dense_q8 missing: set EXL3_GM_BUILD_DIR to the build holding it"
+wiki = json.load(open(os.environ.get("WIKI", "/home/kamel/scratch_w5/wiki_ids.json")))
+pc, sync = time.perf_counter, torch.cuda.synchronize
+
+
+def arm(b):
+ fwm.DENSE_V2[0] = b
+ GR.clear()
+
+
+ctxs = [int(x) for x in os.environ.get("PCTXS", "1000,4000").split(",")]
+Ts = [int(x) for x in os.environ.get("PTS", "1,2,3,4,5,6").split(",")]
+res, logit = {}, {}
+for ctxn in ctxs:
+ e._t0 = pc(); e.reset(); e.prefill(wiki[:ctxn]); e.phase("decode")
+ for a_ in ("A", "B", "B", "A"):
+ arm(a_ == "B")
+ for T in Ts:
+ toks = wiki[ctxn:ctxn + T]
+ for _ in range(3):
+ GR.step_rows(toks); sync(); GR.rewind(ctxn)
+ ts = []
+ for _ in range(20):
+ t = pc(); out = GR.step_rows(toks); sync(); ts.append((pc() - t) * 1000); GR.rewind(ctxn)
+ res.setdefault((ctxn, T, a_), []).append(statistics.median(ts))
+ if (ctxn, T, a_) not in logit:
+ logit[(ctxn, T, a_)] = out[0].float().reshape(T, -1).clone()
+ print(f"ARM {a_} ctx {ctxn} done (DENSE_V2 {fwm.DENSE_V2[0]})", flush=True)
+arm(False)
+for ctxn in ctxs:
+ for T in Ts:
+ a, b = res[(ctxn, T, "A")], res[(ctxn, T, "B")]
+ eq = bool(torch.equal(logit[(ctxn, T, "A")], logit[(ctxn, T, "B")]))
+ print(f"AB ctx {ctxn} T {T}: A {[round(x, 2) for x in a]} B {[round(x, 2) for x in b]} ms delta {statistics.mean(b) - statistics.mean(a):+.2f} ms logits_bit_equal {eq}", flush=True)
+print("ABDEND_DONE", flush=True)
diff --git a/tools/hy4/step/dend_test.py b/tools/hy4/step/dend_test.py
new file mode 100644
index 0000000..85bcdb3
--- /dev/null
+++ b/tools/hy4/step/dend_test.py
@@ -0,0 +1,76 @@
+"""dend_test.py: gm_dense_q8 vs fq_gemv_q8_0 (stock): bit equality at M 1..16 and ms per call at the real shapes (graph replay over distinct weights)."""
+import os, sys, time, json, types
+tree = os.environ["LC_T"]
+sys.path.insert(0, os.path.join(tree, "tools", "hy4"))
+import torch
+import engine as _eng
+_eng._stub_package(tree)
+from exllamav3.loader import hy4_forward as HF
+from exllamav3 import gm_ext
+e, g = HF._ext(), gm_ext.get()
+print("ext", e.__file__ if hasattr(e, "__file__") else e, "gm", g.__file__, flush=True)
+dev = "cuda"
+shapes = [(1024, 3072), (576, 3072), (1536, 3072), (3072, 1536), (8192, 1024), (16384, 1024), (3072, 8192), (3072, 16384), (13824, 3072), (3072, 13824), (16384, 3072), (1001, 1056), (77, 96), (2050, 5120)]
+only = os.environ.get("SHAPES")
+if only:
+ shapes = [shapes[int(i)] for i in only.split(",")]
+cpbs = [int(c) for c in os.environ.get("CPBS", "4").split(",")]
+Ts = [int(t) for t in os.environ.get("TS", "1,2,3,4,6,8,16").split(",")]
+bad = 0
+def mk(N, K, cp):
+ w = torch.randint(-127, 128, (N, K // 32, 34), dtype=torch.int16, device=dev).to(torch.int8).view(torch.uint8)
+ d = (torch.rand(N, K // 32, device=dev) * 0.02 + 0.001).half().view(torch.uint8).reshape(N, K // 32, 2)
+ w[:, :, :2] = d
+ return w
+def run_stock(x, w, out):
+ e.fq_gemv_q8_0(x, w, out)
+def run_v2(x, w, out, cpb):
+ R, K = x.shape
+ qb = e.fq_q8_scratch(0, R, K); e.fq_quant_q8_1_rows(x, qb)
+ assert g.gm_dense_q8(qb, w, out, cpb)
+def run_f(x, w, out, cpb):
+ assert g.gm_dense_q8_x(x, w, out, cpb)
+def timeit(fns):
+ s = torch.cuda.Stream()
+ with torch.cuda.stream(s):
+ for f in fns: f()
+ torch.cuda.synchronize()
+ gr = torch.cuda.CUDAGraph()
+ with torch.cuda.graph(gr):
+ for f in fns: f()
+ for _ in range(3): gr.replay()
+ torch.cuda.synchronize()
+ ts = []
+ for _ in range(40):
+ a = torch.cuda.Event(enable_timing=True); b = torch.cuda.Event(enable_timing=True)
+ a.record(); gr.replay(); b.record(); torch.cuda.synchronize(); ts.append(a.elapsed_time(b))
+ ts.sort()
+ return ts[len(ts) // 2] / len(fns) * 1000 # us per call
+res = []
+for (N, K) in shapes:
+ nb = N * (K // 32) * 34
+ copies = max(4, (96 << 20) // nb + 1)
+ ws = [mk(N, K, i) for i in range(copies)]
+ for T in Ts:
+ x = torch.randn(T, K, device=dev)
+ o1 = torch.empty(T, N, device=dev); o2 = torch.empty(T, N, device=dev)
+ run_stock(x, ws[0], o1)
+ row = dict(N=N, K=K, T=T)
+ outs = {i: torch.empty(T, N, device=dev) for i in range(copies)}
+ t0 = timeit([(lambda w=w, o=outs[i]: run_stock(x, w, o)) for i, w in enumerate(ws)])
+ qbs = [e.fq_q8_scratch(0, T, K)] * copies
+ tq = timeit([(lambda w=w: e.fq_quant_q8_1_rows(x, qbs[0])) for i, w in enumerate(ws)])
+ row["quant_us"] = round(tq, 2)
+ row["stock_us"] = round(t0, 2); row["stock_gbs"] = round(nb / (t0 * 1e-6) / 1e9, 1)
+ for cpb in cpbs:
+ for tag, fn in ((("v", run_v2),) if os.environ.get("NOF") else (("v", run_v2), ("f", run_f))):
+ fn(x, ws[0], o2, cpb); torch.cuda.synchronize()
+ eq = bool(torch.equal(o1, o2))
+ if not eq: bad += 1; row[f"NE_{tag}{cpb}"] = 1
+ t1 = timeit([(lambda w=w, o=outs[i]: fn(x, w, o, cpb)) for i, w in enumerate(ws)])
+ row[f"{tag}{cpb}"] = round(t1, 1)
+ print(json.dumps(row), flush=True)
+ res.append(row)
+ del ws
+ torch.cuda.empty_cache()
+print("BAD", bad, flush=True)
diff --git a/tools/hy4/step/opbench.py b/tools/hy4/step/opbench.py
index 0b91c6e..19c1c76 100644
--- a/tools/hy4/step/opbench.py
+++ b/tools/hy4/step/opbench.py
@@ -26,7 +26,8 @@ def shipped_env():
ENV = shipped_env()
for _k, _v in ENV.items():
os.environ.setdefault(_k, _v)
-FLAGHASH = hashlib.sha1(json.dumps({k: os.environ.get(k) for k in sorted(ENV)}, sort_keys=True).encode()).hexdigest()[:8]
+EXTRA_FLAGS = ("HY4_DENSE_V2", "HY4_DENSE_V2_CPB", "HY4_FFN_GROUPED", "BOLT_FQ_Q8_MROWS") # op-agent flags outside SHIPPED_ENV: hashed only when set, so the existing point keys stay valid
+FLAGHASH = hashlib.sha1(json.dumps({**{k: os.environ.get(k) for k in sorted(ENV)}, **{k: os.environ[k] for k in EXTRA_FLAGS if k in os.environ}}, sort_keys=True).encode()).hexdigest()[:8]
sys.path.insert(0, os.path.join(TREE, "tools", "hy4"))
import numpy as np