use memra_engine::Engine;
use memra_engine::MOE_GROUPED_PREFILL_DISPATCHES;
use memra_engine::forward::argmax;
use memra_engine::hybrid::HybridModel;
use memra_engine::hybrid_forward::{
HYPER_PRIME_NATURAL_SCHEDULES, HYPER_PRIME_PIPELINED_CHUNKS, hyper_prime_ranges,
};
use memra_gguf::GgmlType;
use memra_gguf::config::{HfConfig, ModelConfig};
use memra_gguf::model_plan::{ModelPlan, StatePlan};
use memra_gguf::source::{TensorSource, TensorView};
use memra_gguf::tensor_contract::{
CheckpointDialect, ContractOptions, LayerTensor, OutputHead, TensorContract, TensorId,
TensorMatch,
};
use memra_reference::{ReferenceTensor, deterministic_fixture};
use std::borrow::Cow;
use std::collections::BTreeMap;
use std::sync::atomic::Ordering;
const HIDDEN: usize = 128;
const VOCAB: u32 = 32;
const LAYERS: usize = 4;
const TOL: f32 = 2e-5;
const TOL_BGEMM: f32 = 1e-2;
fn mini_config_json() -> String {
r#"{
"model_type": "glm5_next_text",
"num_hidden_layers": 4,
"num_nextn_predict_layers": 0,
"hidden_size": 128,
"intermediate_size": 64,
"vocab_size": 32,
"max_position_embeddings": 40960,
"rms_norm_eps": 1e-05,
"hidden_act": "silu",
"swiglu_limit": 10.0,
"tie_word_embeddings": true,
"hc_mult": 4,
"hc_eps": 1e-06,
"hc_sinkhorn_iters": 20,
"mhc": true,
"layer_types": ["linear_attention", "deepseek_sparse_attention",
"linear_attention", "deepseek_sparse_attention"],
"mlp_layer_types": ["dense", "sparse", "sparse", "sparse"],
"first_k_dense_replace": 1,
"indexer_types": ["full", "full", "full", "full"],
"linear_attn_config": {
"num_heads": 1,
"head_dim": 128,
"short_conv_kernel_size": 4,
"gate_lower_bound": -5.0,
"kda_layers": [0, 2],
"full_attn_layers": [1, 3]
},
"num_attention_heads": 2,
"num_key_value_heads": 2,
"q_lora_rank": 16,
"kv_lora_rank": 16,
"qk_head_dim": 16,
"qk_nope_head_dim": 16,
"qk_rope_head_dim": 0,
"v_head_dim": 16,
"mla_use_nope": true,
"index_n_heads": 1,
"index_head_dim": 8,
"index_topk": 8,
"index_kpool": 4,
"index_kpool_always_select_tail": true,
"index_kpool_compress": true,
"indexer_rope_interleave": true,
"index_share_for_mtp_iteration": true,
"n_routed_experts": 288,
"num_experts_per_tok": 8,
"moe_intermediate_size": 64,
"n_shared_experts": 1,
"scoring_func": "sigmoid",
"topk_method": "noaux_tc",
"routed_scaling_factor": 2.5,
"norm_topk_prob": true,
"n_group": 1,
"topk_group": 1,
"head_dim": 0,
"attention_bias": false,
"moe_router_dtype": "float32",
"dtype": "bfloat16"
}"#
.to_string()
}
struct OwnedTensor {
bytes: Vec<u8>,
ne: Vec<u64>,
ggml_type: GgmlType,
}
fn is_expert_bank(id: &TensorId) -> bool {
matches!(
id,
TensorId::Layer {
tensor: LayerTensor::MoeExpertGateBank
| LayerTensor::MoeExpertUpBank
| LayerTensor::MoeExpertDownBank,
..
}
)
}
fn is_shared_expert(id: &TensorId) -> bool {
matches!(
id,
TensorId::Layer {
tensor: LayerTensor::SharedMlpGate
| LayerTensor::SharedMlpUp
| LayerTensor::SharedMlpDown,
..
}
)
}
struct FixtureSource {
config: ModelConfig,
tensors: BTreeMap<String, OwnedTensor>,
}
impl TensorSource for FixtureSource {
fn config(&self) -> ModelConfig {
self.config.clone()
}
fn find(&self, name: &str) -> Option<TensorView<'_>> {
let t = self.tensors.get(name)?;
Some(TensorView {
bytes: Cow::Borrowed(&t.bytes),
ggml_type: t.ggml_type,
ne: t.ne.clone(),
})
}
}
fn fixture_source(
config: &ModelConfig,
plan: &ModelPlan,
weights: &BTreeMap<TensorId, ReferenceTensor>,
) -> FixtureSource {
let contract = TensorContract::for_plan(
plan,
CheckpointDialect::Gguf,
ContractOptions {
output_head: OutputHead::TiedToEmbedding,
},
)
.expect("contract for the mini glm5_next hc plan");
let mut tensors = BTreeMap::new();
for req in contract
.requirements
.iter()
.filter(|r| r.required || weights.contains_key(&r.id))
{
let tensor = weights
.get(&req.id)
.unwrap_or_else(|| panic!("reference fixture is missing {:?}", req.id));
let elements: usize = req.shape.iter().map(|&d| d as usize).product();
assert_eq!(
elements,
tensor.data.len(),
"fixture {:?} has {} elements, contract requires {elements}",
req.id,
tensor.data.len()
);
if matches!(
req.id,
TensorId::Layer {
tensor: LayerTensor::MoeRouterBias,
..
}
) {
let n = tensor.data.len();
let bias: Vec<f32> = (0..n).map(|i| -0.00018f32 * i as f32).collect();
let bytes: Vec<u8> = bias.iter().flat_map(|v| v.to_le_bytes()).collect();
for name in match req.match_mode {
TensorMatch::OneOf => &req.names[..1],
TensorMatch::All => req.names.as_slice(),
} {
tensors.insert(
name.clone(),
OwnedTensor {
bytes: bytes.clone(),
ne: req.shape.clone(),
ggml_type: GgmlType::F32,
},
);
}
continue;
}
let (bytes, ggml_type) = if is_expert_bank(&req.id) {
(
memra_gguf::nvfp4_repack::f32_to_nvfp4(&tensor.data),
GgmlType::NVFP4,
)
} else if is_shared_expert(&req.id) {
(
memra_gguf::nvfp4_repack::f32_to_q8_0(&tensor.data),
GgmlType::Q8_0,
)
} else {
(
tensor.data.iter().flat_map(|v| v.to_le_bytes()).collect(),
GgmlType::F32,
)
};
let names = match req.match_mode {
TensorMatch::OneOf => &req.names[..1],
TensorMatch::All => req.names.as_slice(),
};
for name in names {
tensors.insert(
name.clone(),
OwnedTensor {
bytes: bytes.clone(),
ne: req.shape.clone(),
ggml_type,
},
);
}
}
FixtureSource {
config: config.clone(),
tensors,
}
}
fn tokens(n: usize, seed: u64) -> Vec<u32> {
let mut s = seed | 1;
(0..n)
.map(|_| {
s = s
.wrapping_mul(6_364_136_223_846_793_005)
.wrapping_add(1_442_695_040_888_963_407);
((s >> 33) as u32) % VOCAB
})
.collect()
}
fn relative(got: &[f32], want: &[f32]) -> f32 {
assert_eq!(got.len(), want.len(), "compared slices differ in length");
let worst = got
.iter()
.zip(want)
.map(|(x, y)| (x - y).abs())
.fold(0.0f32, f32::max);
let scale = want.iter().fold(0.0f32, |m, x| m.max(x.abs())).max(1e-6);
worst / scale
}
fn row_profile(got: &[f32], want: &[f32], n_embd: usize) -> String {
let rows = want.len() / n_embd;
let mut worst = (0usize, 0.0f32, 0.0f32);
let mut buckets = [0.0f32; 8];
for r in 0..rows {
let a = &got[r * n_embd..(r + 1) * n_embd];
let b = &want[r * n_embd..(r + 1) * n_embd];
let d = a
.iter()
.zip(b)
.map(|(x, y)| (x - y).abs())
.fold(0.0f32, f32::max);
let scale = b.iter().fold(0.0f32, |m, x| m.max(x.abs())).max(1e-6);
let rel = d / scale;
if rel > worst.1 {
worst = (r, rel, scale);
}
let bucket = (r * 8 / rows.max(1)).min(7);
buckets[bucket] = buckets[bucket].max(rel);
}
format!(
"rows={rows} worst row {} rel {:.3e} (row scale {:.3e}); per-eighth worst \
[{}]",
worst.0,
worst.1,
worst.2,
buckets
.iter()
.map(|v| format!("{v:.1e}"))
.collect::<Vec<_>>()
.join(" ")
)
}
fn bit_mismatches(got: &[f32], want: &[f32]) -> usize {
assert_eq!(got.len(), want.len(), "compared slices differ in length");
got.iter()
.zip(want)
.filter(|(a, b)| a.to_bits() != b.to_bits())
.count()
}
fn prime_once_tapped(
e: &Engine,
m: &HybridModel,
plan: &ModelPlan,
ids: &[u32],
max_ctx: usize,
layer_ids: &[usize],
) -> Result<(Vec<f32>, Vec<f32>), Box<dyn std::error::Error>> {
let mut cache = memra_engine::pp::new_cache_planned(e, &m.cfg, plan, max_ctx)?;
cache.hc_taps = Some(memra_engine::cache::HcTapSink::new(
layer_ids.to_vec(),
HIDDEN,
ids.len(),
));
let (logits, _seed, _hiddens) = m.prime_cache(e, ids, &mut cache, 0)?;
let sink = cache
.hc_taps
.take()
.ok_or("the prime must leave its tap sink in place")?;
Ok((logits, sink.rows))
}
fn prime_once(
e: &Engine,
m: &HybridModel,
plan: &ModelPlan,
ids: &[u32],
max_ctx: usize,
) -> Result<(Vec<f32>, Vec<f32>), Box<dyn std::error::Error>> {
let mut cache = memra_engine::pp::new_cache_planned(e, &m.cfg, plan, max_ctx)?;
let started = std::time::Instant::now();
let (logits, _seed, hiddens) = m.prime_cache(e, ids, &mut cache, 0)?;
let stack = e.dtoh(&hiddens)?;
if std::env::var("MEMRA_PRIME_PROF").as_deref() == Ok("1") {
eprintln!(
"[prime-v2-gate] attribution-only wall {:.1} ms for t={} (128-wide FIXTURE; \
not a performance claim)",
started.elapsed().as_secs_f64() * 1e3,
ids.len()
);
}
assert_eq!(
cache.pos,
ids.len(),
"the prime must leave the cache at the prompt length"
);
Ok((logits, stack))
}
fn set_env(key: &str, value: &str) {
unsafe { std::env::set_var(key, value) };
}
fn clear_env(key: &str) {
unsafe { std::env::remove_var(key) };
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
let t1: usize = std::env::args()
.nth(1)
.and_then(|s| s.parse().ok())
.unwrap_or(4096);
let t2: usize = std::env::args()
.nth(2)
.and_then(|s| s.parse().ok())
.unwrap_or(8192);
let chunk2: usize = std::env::args()
.nth(3)
.and_then(|s| s.parse().ok())
.unwrap_or(4096);
let red = std::env::var("MEMRA_PRIME_V2_GATE_RED").unwrap_or_default();
if std::env::var("NVIDIA_TF32_OVERRIDE").as_deref() != Ok("0") {
set_env("NVIDIA_TF32_OVERRIDE", "0");
}
set_env("MEMRA_PP_STAGES", "2");
clear_env("MEMRA_PP_SPLITS");
clear_env("MEMRA_PP_SPLIT");
clear_env("MEMRA_B200_PRIME_V2");
clear_env("MEMRA_PRIME_CHUNK");
clear_env("MEMRA_PRIME_PIPE");
let config = ModelConfig::from_hf(&HfConfig::parse(&mini_config_json()));
let plan = memra_gguf::model_packs::for_config(&config)
.expect("glm5_next model pack matches the mini config")
.compile_plan(&config)
.expect("mini glm5_next plan compiles");
assert_eq!(plan.layers.len(), LAYERS);
assert_eq!(plan.hidden_size as usize, HIDDEN);
let fixture = deterministic_fixture(&plan).expect("deterministic glm5_next hc fixture");
let source = fixture_source(&config, &plan, &fixture.weights);
let cut = (1..plan.layers.len())
.find(|&c| {
let has = |lo: usize, hi: usize, want_recur: bool| {
plan.layers[lo..hi].iter().any(|l| match l.state {
StatePlan::Recurrent { .. } => want_recur,
StatePlan::LatentKvCache { .. } => !want_recur,
_ => false,
})
};
let n = plan.layers.len();
has(0, c, true) && has(0, c, false) && has(c, n, true) && has(c, n, false)
})
.expect(
"no two-stage cut of this fixture gives both stages a Recurrent AND a \
LatentKvCache layer — the fixture's layer_types must alternate both classes on \
both sides of some boundary",
);
set_env("MEMRA_PP_SPLITS", &cut.to_string());
let e = Engine::new(0)?;
let m = HybridModel::load_from_source_without_mtp(&e, &source)?;
let topology = m.hyper.as_ref().expect(
"the fixture must load as a HyperConnections trunk — otherwise this gate measures a \
schedule the door does not steer",
);
let fence = memra_engine::pp::pp_cuts(LAYERS)
.expect("MEMRA_PP_STAGES=2 must open a two-stage fence over the fixture trunk");
assert_eq!(
fence.len(),
3,
"this gate's arms are PP-2 arms: fence {fence:?}"
);
let mut recur_on = vec![false; fence.len() - 1];
let mut latent_on = vec![false; fence.len() - 1];
for layer in &plan.layers {
let il = layer.index as usize;
let stage = usize::from(il >= fence[1]);
match layer.state {
StatePlan::Recurrent { .. } => recur_on[stage] = true,
StatePlan::LatentKvCache { .. } => latent_on[stage] = true,
_ => {}
}
}
assert!(
recur_on.iter().all(|&b| b) && latent_on.iter().all(|&b| b),
"every PP stage must own BOTH a Recurrent (KDA) and a LatentKvCache (MLA+kpool) layer \
so the per-stage cache split is exercised on both halves; got recur={recur_on:?} \
latent={latent_on:?} over fence {fence:?}"
);
println!(
"glm5-prime-v2-gate config: cut={cut} T1={t1} T2={t2} CHUNK2={chunk2} fence={fence:?} \
streams={} collapse={:?} sinkhorn={} red={}",
topology.streams,
topology.collapse,
topology.sinkhorn_iterations,
if red.is_empty() { "none" } else { red.as_str() },
);
let mut failures: Vec<String> = Vec::new();
{
let ids = tokens(t1, 0x5EED_0001);
let max_ctx = t1 + 16;
clear_env("MEMRA_B200_PRIME_V2");
let gpf_before = MOE_GROUPED_PREFILL_DISPATCHES.load(Ordering::Relaxed);
let shipped_ranges = hyper_prime_ranges(t1, LAYERS, m.gdn_prime_grid_on());
let (ref_logits, ref_stack) = prime_once(&e, &m, &plan, &ids, max_ctx)?;
if red != "schedule" {
set_env("MEMRA_B200_PRIME_V2", "1");
}
let nat_before = HYPER_PRIME_NATURAL_SCHEDULES.load(Ordering::Relaxed);
let door_ranges = hyper_prime_ranges(t1, LAYERS, m.gdn_prime_grid_on());
let (got_logits, got_stack) = prime_once(&e, &m, &plan, &ids, max_ctx)?;
let nat = HYPER_PRIME_NATURAL_SCHEDULES.load(Ordering::Relaxed) - nat_before;
clear_env("MEMRA_B200_PRIME_V2");
println!(
"arm 1 SCHEDULE t={t1}: shipped {} chunks {:?} -> door {} chunks {:?} \
(natural-schedule counter +{nat})",
shipped_ranges.len(),
shipped_ranges
.iter()
.map(|&(s, x)| x - s)
.collect::<Vec<_>>(),
door_ranges.len(),
door_ranges.iter().map(|&(s, x)| x - s).collect::<Vec<_>>(),
);
if nat < 2 {
failures.push(format!(
"arm 1 VACUOUS: HYPER_PRIME_NATURAL_SCHEDULES advanced by {nat}, want >= 2 — \
the natural-chunk schedule never ran with the door open"
));
}
if shipped_ranges.len() == door_ranges.len() {
failures.push(format!(
"arm 1 VACUOUS: the door left the chunk count at {} — comparing two identical \
schedules proves nothing (this is the exact shape the lane's roofline caught: \
an armed geometry that changed nothing and was invisible from outside)",
door_ranges.len()
));
}
let rel_logits = relative(&got_logits, &ref_logits);
let rel_stack = relative(&got_stack, &ref_stack);
let arg_ref = argmax(&ref_logits);
let arg_got = argmax(&got_logits);
let grouped_on = MOE_GROUPED_PREFILL_DISPATCHES.load(Ordering::Relaxed) > gpf_before;
let (band, band_name) = if grouped_on {
(TOL_BGEMM, "f16-mirror grouped class")
} else {
(TOL, "cuBLASLt m-dependence near-tie")
};
println!(
"arm 1 SCHEDULE logits rel {rel_logits:.3e} stack rel {rel_stack:.3e} \
(band {band:.1e}, {band_name}) argmax {arg_ref} vs {arg_got}"
);
if !got_logits.iter().all(|v| v.is_finite()) || !got_stack.iter().all(|v| v.is_finite()) {
failures.push("arm 1: the door walk produced non-finite values".to_string());
}
println!(
"arm 1 ROWS {}",
row_profile(&got_stack, &ref_stack, HIDDEN)
);
clear_env("MEMRA_B200_PRIME_V2");
set_env("MEMRA_PRIME_CHUNK", &(t1 / 2).to_string());
let ctrl_ranges = hyper_prime_ranges(t1, LAYERS, m.gdn_prime_grid_on());
let (ctrl_logits, ctrl_stack) = prime_once(&e, &m, &plan, &ids, max_ctx)?;
clear_env("MEMRA_PRIME_CHUNK");
let ctrl_rel_logits = relative(&ctrl_logits, &ref_logits);
let ctrl_rel_stack = relative(&ctrl_stack, &ref_stack);
println!(
"arm 1 CONTROL shipped reschedule to {} chunks: logits rel {ctrl_rel_logits:.3e} \
stack rel {ctrl_rel_stack:.3e}",
ctrl_ranges.len()
);
if rel_logits > band {
failures.push(format!(
"arm 1: LOGITS outside the {band_name} band — {rel_logits:.3e} > {band:.1e}"
));
}
let stack_bar = (ctrl_rel_stack * 4.0).max(band);
if rel_stack > stack_bar {
failures.push(format!(
"arm 1: the door's schedule moves the hidden stack {rel_stack:.3e}, MORE than \
4x what an already-shipped reschedule moves it ({ctrl_rel_stack:.3e}, bar \
{stack_bar:.3e}). That is a schedule DEFECT, not this trunk's known discrete \
k-pool sensitivity"
));
}
if ctrl_rel_stack == 0.0 && rel_stack == 0.0 {
failures.push(
"arm 1 CONTROL VACUOUS: neither the door nor a shipped reschedule moved the \
stack at all, so this comparison cannot distinguish them"
.to_string(),
);
}
if arg_ref != arg_got {
failures.push(format!("arm 1: argmax moved {arg_ref} -> {arg_got}"));
}
}
{
let ids = tokens(t2, 0x5EED_0002);
let max_ctx = t2 + 16;
set_env("MEMRA_B200_PRIME_V2", "1");
set_env("MEMRA_PRIME_CHUNK", &chunk2.to_string());
let ranges = hyper_prime_ranges(t2, LAYERS, m.gdn_prime_grid_on());
assert!(
ranges.len() >= 2,
"arm 2 needs at least two chunks to overlap: T2={t2} CHUNK2={chunk2} gave \
{} range(s). Raise T2 or lower CHUNK2.",
ranges.len()
);
set_env("MEMRA_PRIME_PIPE", "0");
let serial_before = HYPER_PRIME_PIPELINED_CHUNKS.load(Ordering::Relaxed);
let (ref_logits, ref_stack) = prime_once(&e, &m, &plan, &ids, max_ctx)?;
let serial_chunks = HYPER_PRIME_PIPELINED_CHUNKS.load(Ordering::Relaxed) - serial_before;
if red != "pipe" {
clear_env("MEMRA_PRIME_PIPE");
}
let pipe_before = HYPER_PRIME_PIPELINED_CHUNKS.load(Ordering::Relaxed);
let (got_logits, got_stack) = prime_once(&e, &m, &plan, &ids, max_ctx)?;
let pipe_chunks = HYPER_PRIME_PIPELINED_CHUNKS.load(Ordering::Relaxed) - pipe_before;
clear_env("MEMRA_PRIME_PIPE");
clear_env("MEMRA_PRIME_CHUNK");
clear_env("MEMRA_B200_PRIME_V2");
let bad_logits = bit_mismatches(&got_logits, &ref_logits);
let bad_stack = bit_mismatches(&got_stack, &ref_stack);
println!(
"arm 2 PIPELINE t={t2} chunks={} ({:?}): serial pipelined-count {serial_chunks}, \
door pipelined-count {pipe_chunks}; bit mismatches logits {bad_logits}/{} stack \
{bad_stack}/{}",
ranges.len(),
ranges.iter().map(|&(s, x)| x - s).collect::<Vec<_>>(),
got_logits.len(),
got_stack.len(),
);
if serial_chunks != 0 {
failures.push(format!(
"arm 2 CONTROL BROKEN: MEMRA_PRIME_PIPE=0 still pipelined {serial_chunks} \
chunk(s) — the reference arm is not the serial walk it claims to be"
));
}
if pipe_chunks != ranges.len() as u64 {
failures.push(format!(
"arm 2 VACUOUS: the pipelined body ran {pipe_chunks} chunk(s), schedule says \
{} — bit identity between two SERIAL walks proves nothing, and the body \
declines by name on several shapes (overlay, armed hc tap, MEMRA_PRIME_PIPE=0); \
check stderr for a [hyper-prime-pipe] DECLINED line",
ranges.len()
));
}
if bad_logits != 0 || bad_stack != 0 {
let rel_l = relative(&got_logits, &ref_logits);
let rel_s = relative(&got_stack, &ref_stack);
failures.push(format!(
"arm 2: the pipelined walk is NOT bit-identical — {bad_logits} logit bits and \
{bad_stack} stack bits differ (relative {rel_l:.3e} / {rel_s:.3e}). The \
schedule is unchanged between these two walks, so this is a seam bug, not a \
numeric class"
));
}
}
{
let ids = tokens(t2, 0x5EED_0004);
let max_ctx = t2 + 16;
let taps: Vec<usize> = vec![fence[1] - 1, fence[2] - 1];
set_env("MEMRA_B200_PRIME_V2", "1");
set_env("MEMRA_PRIME_CHUNK", &chunk2.to_string());
set_env("MEMRA_PRIME_PIPE", "0");
let (ref_logits, ref_taps) = prime_once_tapped(&e, &m, &plan, &ids, max_ctx, &taps)?;
let serial_pipelined = HYPER_PRIME_PIPELINED_CHUNKS.load(Ordering::Relaxed);
if red != "taps" {
clear_env("MEMRA_PRIME_PIPE");
}
let before = HYPER_PRIME_PIPELINED_CHUNKS.load(Ordering::Relaxed);
let (got_logits, got_taps) = prime_once_tapped(&e, &m, &plan, &ids, max_ctx, &taps)?;
let pipelined = HYPER_PRIME_PIPELINED_CHUNKS.load(Ordering::Relaxed) - before;
clear_env("MEMRA_PRIME_CHUNK");
clear_env("MEMRA_B200_PRIME_V2");
let ranges = {
set_env("MEMRA_B200_PRIME_V2", "1");
set_env("MEMRA_PRIME_CHUNK", &chunk2.to_string());
let r = hyper_prime_ranges(t2, LAYERS, m.gdn_prime_grid_on());
clear_env("MEMRA_PRIME_CHUNK");
clear_env("MEMRA_B200_PRIME_V2");
r
};
let bad_logits = bit_mismatches(&got_logits, &ref_logits);
let bad_taps = bit_mismatches(&got_taps, &ref_taps);
let nonzero = ref_taps.iter().filter(|v| **v != 0.0).count();
println!(
"arm 4 TAPPED t={t2} chunks={} taps={taps:?} rows={} ({nonzero} nonzero): \
pipelined-count {pipelined}; bit mismatches logits {bad_logits}/{} taps \
{bad_taps}/{}",
ranges.len(),
ref_taps.len(),
got_logits.len(),
got_taps.len(),
);
if serial_pipelined != before {
failures.push(
"arm 4 CONTROL BROKEN: MEMRA_PRIME_PIPE=0 still pipelined chunks".to_string(),
);
}
if pipelined != ranges.len() as u64 {
failures.push(format!(
"arm 4 VACUOUS: the pipelined body ran {pipelined} chunk(s), schedule says {} — \
with a sink armed this is the decline arm 2 used to take, and it is exactly \
what cost the product route its win at depth. Check stderr for a \
[hyper-prime-pipe] DECLINED line, and for taps=armed on the arm2 engagement line",
ranges.len()
));
}
if nonzero == 0 {
failures.push(
"arm 4 VACUOUS: the reference sink is all zeros, so comparing sinks compares \
nothing — the tap never fired"
.to_string(),
);
}
if bad_logits != 0 || bad_taps != 0 {
failures.push(format!(
"arm 4: the pipelined walk with taps armed is NOT bit-identical — {bad_logits} \
logit bits and {bad_taps} tap bits differ. The tap rows are the drafter's whole \
context; a moved bit there is a different draft"
));
}
}
if failures.is_empty() {
println!(
"glm5-prime-v2-gate: PASS (arm 1 near-tie band + argmax, arm 2 bit-identical, \
arm 4 tapped pipeline bit-identical)"
);
Ok(())
} else {
for f in &failures {
eprintln!("glm5-prime-v2-gate FAIL: {f}");
}
Err(format!("glm5-prime-v2-gate: {} failure(s)", failures.len()).into())
}
}