Skip to content

Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.

C++

F7: the final mixer in one fused read (fork 2ec7a80)

Niko1221edc592b1ef32
diff --git a/src/core/mtp.cpp b/src/core/mtp.cpp
index 2784c0a3e..9941e55ce 100644
--- a/src/core/mtp.cpp
+++ b/src/core/mtp.cpp
@@ -796,6 +796,14 @@ bool MtpDrafter::record_rest(int step_row, cudaStream_t cs, std::string& err) {
const char* v = std::getenv("STRATA_FUSE_HEAD_GR");
return v != nullptr && std::atoi(v) != 0;
}();
+ static const bool head_mix_multi_on = [] {
+#if defined(STRATA_USE_HIP)
+ return false;
+#else
+ const char* v = std::getenv("STRATA_HEAD_MIX_MULTI");
+ return v == nullptr || std::atoi(v) != 0;
+#endif
+ }();
// the shared expert only reads mixed_ / xq_ and writes shared_: a branch beside the router and the routed
// experts, joined before the combine (CUDA; HIP keeps one stream: STRATA_MTP_SHARED_BRANCH=0 does too)
static const bool branch_on = [] {
@@ -863,6 +871,17 @@ bool MtpDrafter::record_rest(int step_row, cudaStream_t cs, std::string& err) {
fa[t].inject_out = dummy_inj_; fa[t].mixed = sample_ + t * N;
}
fused_gr_read_multi(fa, T, xn_, cs);
+ } else if (head_mix_multi_on) {
+ // the window's rows in one read (CUDA; HIP keeps gr_read per row): bitwise the same sums
+ FusedGrArgs fa[kFusedGrMaxT];
+ for (int t = 0; t < T; ++t) {
+ fa[t].R = R_ + (size_t) t * HC * N; fa[t].R_out = R_ + (size_t) t * HC * N; fa[t].apply = false;
+ fa[t].w_norm = f32("hyper_connection_mixer.hc_norm.weight");
+ fa[t].w_down = bf16("hyper_connection_mixer.input_mix_weight_down.weight");
+ fa[t].w_up = bf16("hyper_connection_mixer.input_mix_weight_up.weight");
+ fa[t].eps = EPS; fa[t].lo = lo_ + t * g.hc_lr; fa[t].rs = rs_ + t * HC; fa[t].mixed = sample_ + t * N;
+ }
+ fused_gr_read_multi(fa, T, xn_, cs);
} else {
for (int t = 0; t < T; ++t)
gr_read(R_ + (size_t) t * HC * N, f32("hyper_connection_mixer.hc_norm.weight"),
diff --git a/src/core/verify.cpp b/src/core/verify.cpp
index 9ca5781d6..5439d2a7c 100644
--- a/src/core/verify.cpp
+++ b/src/core/verify.cpp
@@ -107,6 +107,20 @@ const bool g_sh_stream = [] {
// A one-token window always keeps its token, so its graph advances the sequence state itself (the GDN conv history
// and recurrence state) and Verifier::commit launches no commit graph after it (eddoursul's fork, F7). CUDA only:
// HIP keeps the commit graph after every window (STRATA_ONE_TOKEN_COMMIT=0 does too).
+// The head's hyper-connection read for the window's tokens in one launch set (CUDA; HIP keeps gr_read per token;
+// STRATA_HEAD_MIX_MULTI=0 does too): bitwise the same sums.
+bool head_mix_multi_enabled() {
+#if defined(STRATA_USE_HIP)
+ return false;
+#else
+ static const bool on = [] {
+ const char* v = std::getenv("STRATA_HEAD_MIX_MULTI");
+ return v == nullptr || std::atoi(v) != 0;
+ }();
+ return on;
+#endif
+}
+
bool one_token_self_commit() {
#if defined(STRATA_USE_HIP)
return false;
@@ -1300,6 +1314,21 @@ bool Verifier::record_window(int T, cudaStream_t cs, std::string& err) {
a.mixed = head_mixed_ + t * N;
}
fused_gr_read_multi(fa, T, xn_, cs);
+ } else if (head_mix_multi_enabled() && head_ != nullptr && head_->loaded()) {
+ // the final mixer, the window's tokens in one read (fused_gr_read_multi without the pending write: the
+ // last layer's write was done above; its sums are gr_read's)
+ if (hn->kind != WeightKind::F32 || hd->kind != WeightKind::Bf16InF32 || hu->kind != WeightKind::Bf16InF32) {
+ err = "verify: the output_hc_* weights have the wrong engine forms";
+ return false;
+ }
+ FusedGrArgs fa[kFusedGrMaxT];
+ for (int t = 0; t < T; ++t) {
+ fa[t].R = Rt(t); fa[t].R_out = Rt(t); fa[t].apply = false;
+ fa[t].w_norm = (const float*) hn->data; fa[t].w_down = (const uint16_t*) hd->data;
+ fa[t].w_up = (const uint16_t*) hu->data; fa[t].eps = EPS;
+ fa[t].lo = lo_ + t * g.hc_lr; fa[t].rs = rs_ + t * HC; fa[t].mixed = head_mixed_ + t * N;
+ }
+ fused_gr_read_multi(fa, T, xn_, cs);
} else {
for (int t = 0; t < T; ++t) {
BlockBuffers bb = ss.block;