From 3dd2cb36eaac27c74964b4a47c9bb4a990353311 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Sun, 4 Oct 2026 22:38:56 -0500 Subject: [PATCH 1/2] inference-abi: strict-mode GPU-backend tests assert real behaviour; CI runs them strict Three tests only passed with AIEN_DEV_FALLBACK=1 and one passed without testing anything. Observed on a strict stub build (CAND-0 0c1d249, no AIEN_DEV_FALLBACK): test_blackwell_inference_backend, attention_wiring f_omega_backend_refuses_pool_mismatch_before_native_code and transformer_parity test_blackwell_vs_reference_cpu_autoregressive_parity FAILED with STRICT_REAL_MODEL_VIOLATION. Diagnosis: test bugs, not production bugs. The strict build correctly refuses a GPU backend with no engine linked (and omega attention supports head_dim 64 only, so head_dim 16 configs can never be fully native). - omega_backend: replace chip_error_trips_strict_in_production, whose skip branch panicked with the expected text (should_panic passed in dev and native runs without testing anything), with a stub/native negative control: an engine-refused swiglu is fatal in a strict process and a counted fallback with the reference result in a dev process. - lib.rs test_blackwell_inference_backend: head_dim 64; strict stub must refuse with the strict violation; native must run with zero fallbacks; dev stub must count fallbacks. - transformer_parity: the GPU leg in a stub build is the reference math, so the "CPU vs Blackwell bitwise" claim was CPU vs CPU. Strict must refuse; dev must show counted fallbacks; token equality asserted only where both legs are the same math. - attention_wiring: accept the strict violation for the op in a strict process, the geometry message in a dev process. - CI: new step runs these targets plus strict_real_model without AIEN_DEV_FALLBACK, so strict branches are exercised on every PR. Validation: cargo test -p aien-inference-abi --lib --test attention_wiring --test transformer_parity, strict and AIEN_DEV_FALLBACK=1, stub build: all ok (88/12/5). Mutation (strict::fallback_taken made non-fatal): the four rewritten tests go red in strict mode. clippy -D warnings, fmt clean. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci.yml | 8 +++ crates/aien-inference-abi/src/lib.rs | 44 +++++++++++-- .../aien-inference-abi/src/omega_backend.rs | 42 +++++++++++-- .../tests/attention_wiring.rs | 29 +++++++-- .../tests/transformer_parity.rs | 61 +++++++++++++++---- 5 files changed, 157 insertions(+), 27 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 76022efa..187dcbe1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,6 +46,14 @@ jobs: AIEN_DEV_FALLBACK: "1" run: cargo test --workspace --verbose -- --test-threads=1 + - name: Strict-Mode Controls (no AIEN_DEV_FALLBACK) + # The workspace test step above opts in to the dev fallback, which skips every + # strict branch of the GPU-backend tests. These targets must also pass in a strict + # process: a stub build must refuse the GPU backend instead of computing on the CPU. + run: | + cargo test -p aien-inference-abi --lib --test attention_wiring --test transformer_parity -- --test-threads=1 + cargo test -p aien-inference-runtime --test strict_real_model -- --test-threads=1 + - name: Zero-CUDA Gate (aien-cli links no NVIDIA CUDA library or symbol) run: | bash scripts/zero-cuda-gate.sh --self-test diff --git a/crates/aien-inference-abi/src/lib.rs b/crates/aien-inference-abi/src/lib.rs index 678faf7a..0f7ce6e4 100644 --- a/crates/aien-inference-abi/src/lib.rs +++ b/crates/aien-inference-abi/src/lib.rs @@ -885,15 +885,21 @@ mod tests { assert!(metrics.step_latency_us > 0); } + /// The GB10 backend on reference weights, judged per build. head_dim 64 is the + /// geometry omega attention supports, so a native strict build can run every op on + /// the chip. Before this test was split, it used head_dim 16 and asserted success + /// unconditionally, so it only passed with AIEN_DEV_FALLBACK=1: a strict stub build + /// correctly refuses at the first op (no engine linked), and a strict native build + /// would refuse at attention (omega attention needs head_dim 64, see omega_backend.rs). #[tokio::test] async fn test_blackwell_inference_backend() { let config = ModelConfig { num_layers: 2, num_heads: 4, num_kv_heads: 2, - head_dim: 16, - hidden_dim: 64, - intermediate_dim: 128, + head_dim: 64, + hidden_dim: 256, + intermediate_dim: 512, vocab_size: 256, block_size: 16, ..Default::default() @@ -925,9 +931,39 @@ mod tests { step_id: 1, }; - let (outputs, metrics) = backend.execute_step(&batch).await.unwrap(); + let run = tokio::spawn(async move { + let res = backend.execute_step(&batch).await; + (res, backend.inner.backend.tensor_backend.fallback_count()) + }) + .await; + + let native = aien_omega_gpu::is_native(); + if crate::strict::production_strict() && !native { + // Negative control: a strict build with no engine linked must refuse, not + // compute on the CPU behind the GPU backend's name. + let err = run.expect_err("a strict stub build must refuse the GPU backend"); + assert!(err.is_panic(), "{err}"); + let payload = err.into_panic(); + let msg = payload + .downcast_ref::() + .cloned() + .or_else(|| payload.downcast_ref::<&str>().map(|s| s.to_string())) + .unwrap_or_default(); + assert!( + msg.contains(crate::strict::STRICT_VIOLATION_PREFIX), + "{msg}" + ); + return; + } + let (res, fallbacks) = run.expect("execute_step must not panic here"); + let (outputs, metrics) = res.unwrap(); assert_eq!(outputs.len(), 1); assert_eq!(metrics.prefill_tokens_processed, 3); + if native { + assert_eq!(fallbacks, 0, "native build: every op must run on the chip"); + } else { + assert!(fallbacks > 0, "dev stub build: fallbacks must be counted"); + } } #[tokio::test] diff --git a/crates/aien-inference-abi/src/omega_backend.rs b/crates/aien-inference-abi/src/omega_backend.rs index a71d5035..0a04fc01 100644 --- a/crates/aien-inference-abi/src/omega_backend.rs +++ b/crates/aien-inference-abi/src/omega_backend.rs @@ -847,15 +847,45 @@ mod tests { .contains("native_fallbacks=[matmul_batch:1]")); } + /// Negative control for stub and native builds alike. The engine refuses a + /// claimed-native op before any launch (swiglu with unequal gate/up lengths; the + /// reference path accepts it and uses the shorter length). In a strict process that + /// refusal must be fatal; in a dev process it must be a counted fallback with the + /// reference result. This replaces a `should_panic` test whose skip branch panicked + /// with the expected text, so it passed without testing anything in dev and native runs. #[test] - #[should_panic(expected = "STRICT_REAL_MODEL_VIOLATION")] - fn chip_error_trips_strict_in_production() { - if aien_omega_gpu::is_native() || crate::strict::dev_fallback_active() { - panic!("STRICT_REAL_MODEL_VIOLATION (skipped: native or dev build)"); - } + fn chip_refusal_is_fatal_in_strict_and_counted_in_dev() { let b = OmegaGb10Backend::new(); + let gate = [0.5f32, 2.0, -1.0]; + let up = [3.0f32, -0.25]; let mut out = [0.0f32; 2]; - b.matmul_vec(&mut out, &[1.0; 2], &[1.0; 4], 2, 2); + let r = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| { + b.swiglu(&mut out, &gate, &up) + })); + assert_eq!(b.chip_errors(), 1, "{}", b.last_error()); + assert_eq!(b.fallback_count(), 1); + assert!( + b.op_report().line().contains("native_fallbacks=[swiglu:1]"), + "{}", + b.op_report().line() + ); + if crate::strict::production_strict() { + let err = r.expect_err("a strict process must refuse a claimed-native fallback"); + let msg = err + .downcast_ref::() + .cloned() + .or_else(|| err.downcast_ref::<&str>().map(|s| s.to_string())) + .unwrap_or_default(); + assert!( + msg.contains(crate::strict::STRICT_VIOLATION_PREFIX) && msg.contains("swiglu"), + "{msg}" + ); + } else { + r.expect("a dev process continues on the reference path"); + let mut want = [0.0f32; 2]; + ReferenceCpuBackend::new().swiglu(&mut want, &gate, &up); + assert_eq!(out, want); + } } /// The cached cos/sin table, applied on the host with the same f32 formulas as the diff --git a/crates/aien-inference-abi/tests/attention_wiring.rs b/crates/aien-inference-abi/tests/attention_wiring.rs index bf076c05..89232d40 100644 --- a/crates/aien-inference-abi/tests/attention_wiring.rs +++ b/crates/aien-inference-abi/tests/attention_wiring.rs @@ -600,9 +600,23 @@ fn f_incompatible_kv_geometry_is_refused_before_reading() { } /// The chip backend refuses the same mismatches before any native call; in the CPU-stub build -/// this is the only path that runs, and the refusal is counted as a chip error. +/// this is the only path that runs, and the refusal is counted as a chip error. In a strict +/// process the refusal surfaces as the strict violation for the op (the fallback itself is +/// fatal); in a dev process the reference path then refuses with the geometry message. #[test] fn f_omega_backend_refuses_pool_mismatch_before_native_code() { + let strict = aien_inference_abi::strict::production_strict(); + let refused = |msg: &str, op: &str, dev_text: &[&str]| { + if strict { + assert!( + msg.contains(aien_inference_abi::strict::STRICT_VIOLATION_PREFIX) + && msg.contains(op), + "{msg}" + ); + } else { + assert!(dev_text.iter().all(|t| msg.contains(t)), "{msg}"); + } + }; let be = OmegaGb10Backend::new(); let (nq, nkv) = (8usize, 2usize); let (k, v) = banded_kv(2, nkv); @@ -613,15 +627,20 @@ fn f_omega_backend_refuses_pool_mismatch_before_native_code() { let mut out = vec![0.0f32; nq * HD]; be.paged_attention(&mut out, &q, &pool, &[0], 2, 0, nq, 4, HD); }))); - assert!(msg.contains("pool is laid out for 2 kv heads"), "{msg}"); + refused( + &msg, + "paged_attention", + &["pool is laid out for 2 kv heads"], + ); assert!(be.chip_errors() > before, "the refusal must be counted"); let msg = panic_message(catch_unwind(AssertUnwindSafe(|| { let mut out = vec![0.0f32; 6 * HD]; be.gqa_attention(&mut out, &q[..6 * HD], &k, &v, 2, 6, 4, HD); }))); - assert!( - msg.contains("6 is not a multiple of num_kv_heads 4"), - "{msg}" + refused( + &msg, + "gqa_attention", + &["6 is not a multiple of num_kv_heads 4"], ); } diff --git a/crates/aien-inference-abi/tests/transformer_parity.rs b/crates/aien-inference-abi/tests/transformer_parity.rs index 7740f921..52dc4291 100644 --- a/crates/aien-inference-abi/tests/transformer_parity.rs +++ b/crates/aien-inference-abi/tests/transformer_parity.rs @@ -257,6 +257,31 @@ async fn test_blackwell_vs_reference_cpu_autoregressive_parity() { step_id: 1, }; + // The micro config uses head_dim 16, which omega attention does not support (see + // omega_backend.rs), and a stub build has no engine at all, so the "GPU" leg is never + // fully native here. A strict process must refuse it. A dev process runs it with + // counted fallbacks; in a stub build both legs are then the same reference math, so + // this is a wiring check, not chip parity. Chip parity lives in + // tests/omega_backend_parity.rs and the strict real-model gate (heavy queue). + let native = aien_omega_gpu::is_native(); + if aien_inference_abi::strict::production_strict() { + let probe = batch_gpu.clone(); + let refused = tokio::spawn(async move { gpu_backend.execute_step(&probe).await }) + .await + .expect_err("a strict process must refuse a GPU leg that cannot run natively"); + assert!(refused.is_panic(), "{refused}"); + let payload = refused.into_panic(); + let msg = payload + .downcast_ref::() + .cloned() + .or_else(|| payload.downcast_ref::<&str>().map(|s| s.to_string())) + .unwrap_or_default(); + assert!( + msg.contains(aien_inference_abi::strict::STRICT_VIOLATION_PREFIX), + "{msg}" + ); + return; + } let mut cpu_tokens = Vec::new(); let mut gpu_tokens = Vec::new(); @@ -272,10 +297,12 @@ async fn test_blackwell_vs_reference_cpu_autoregressive_parity() { }, ) = (&out_cpu[0], &out_gpu[0]) { - assert_eq!( - t_cpu, t_gpu, - "Prefill first token mismatch between CPU and Blackwell GPU" - ); + if !native { + assert_eq!( + t_cpu, t_gpu, + "Prefill first token mismatch between CPU and the GPU leg" + ); + } cpu_tokens.push(*t_cpu); gpu_tokens.push(*t_gpu); } @@ -301,20 +328,30 @@ async fn test_blackwell_vs_reference_cpu_autoregressive_parity() { }, ) = (&step_out_cpu[0], &step_out_gpu[0]) { - assert_eq!( - t_cpu, t_gpu, - "Decode step {} token mismatch: CPU={}, GPU={}", - step, t_cpu, t_gpu - ); + if !native { + assert_eq!( + t_cpu, t_gpu, + "Decode step {} token mismatch: CPU={}, GPU={}", + step, t_cpu, t_gpu + ); + } cpu_tokens.push(*t_cpu); gpu_tokens.push(*t_gpu); } } - assert_eq!( - cpu_tokens, gpu_tokens, - "Autoregressive generation must match bitwise between CPU and Blackwell GPU" + // Dev run: the GPU leg cannot be fully native (see above), so its fallbacks must show. + let fallbacks = gpu_backend.tensor_backend.fallback_count(); + assert!( + fallbacks > 0, + "the GPU leg ran {fallbacks} counted fallbacks; expected some" ); + if !native { + assert_eq!( + cpu_tokens, gpu_tokens, + "stub dev build: both legs are the reference math and must match bitwise" + ); + } println!( "Parity verified over {} tokens: {:?}", cpu_tokens.len(), From a9a1967b2c0ba2cee06c69fb415024c25ab3d2cb Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Sun, 4 Oct 2026 23:05:30 -0500 Subject: [PATCH 2/2] crumb: recompile after rebase onto main Co-Authored-By: Claude Opus 5.5 --- .crumb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.crumb b/.crumb index 0955e282..23909b77 100644 --- a/.crumb +++ b/.crumb @@ -77,14 +77,14 @@ } ], "children_root": "sha256:dfcfd805db0c30c667bc5682364bd3acb3383d494967dcae39f2420739723d7d", - "compiled_at": "2026-10-05T03:29:46Z", + "compiled_at": "2026-10-05T04:05:30Z", "compiler": "crumb-compile/1", - "digest": "sha256:fdf5d407a9877d6809387c3ca7fe1614d7168c893ed649963fef9ed2417e3a41", + "digest": "sha256:5885c8a87b87a313cfaf67fd901db946c28f5ec684cbe3ef3956f33748646da1", "evidence_files": 20, "evidence_root": "sha256:1ef4526f6fe1ba0cee21a89c3313d37bf2e94e1aa2e9bd1a364225e52882d170", - "files": 682, - "generated_at_commit": "0c1d249f2d119c7c2d726a2d252dc913e6185d28", - "source_tree": "sha256:ac8216c1b39db4cb1b51653b10501c13a5b99be770556bb7c3357f398f38cc5b" + "files": 683, + "generated_at_commit": "3dd2cb36eaac27c74964b4a47c9bb4a990353311", + "source_tree": "sha256:a0c99f76c9c4f23b156bcc2320e91aebb77b300943b0db92505e57eecae42693" } }, "history": [],