Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 73 additions & 7 deletions bench/baselines/gemma4-e2b-f32-attention-semantics-2026-07-12.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{
"slice_id": "LARQL-INFERENCE-TRUST-001A-ST4",
"closeout_slice": "LARQL-INFERENCE-TRUST-001A-ST4A",
"work_start_sha": "15864226bd3ffb70a2cdc35ca3e52dafe76692c7",
"pr_base_sha": "15864226bd3ffb70a2cdc35ca3e52dafe76692c7",
"head_sha": "pending PR head",
"head_sha": "2889157f29ea85d690db5d08290bad41154a346f",
"merge_commit": "b2584c0acf7691d9963dff6a557ec7bac58755d9",
"ci": "all 11 triggered workflows completed successfully",
"intrinsic_window": 512,
"layer_pattern": "SSSSG x7, final layer global (34)",
"shared_kv_map": {
Expand All @@ -27,16 +29,70 @@
"observed_attention_ranges": "match expected (t1-t9 PASS)",
"range_mismatch_count": 0,
"prefill_decode_comparison_count": 4,
"maximum_absolute_error": 1e-5,
"prefill_decode_method": "canonical kv_prefill_run vs kv_prefill_run+kv_decode_step_run (window-512 E2B-like fixture)",
"prefill_decode_abs_tolerance": 1e-5,
"prefill_decode_per_position": {
"511": {
"hidden_max_abs": 1.073e-6,
"hidden_max_rel": 1.023e-6,
"local_kv_tail_max_abs": 0.0,
"local_cache_len_route_a": 512,
"local_cache_len_route_b": 512,
"global_cache_len_route_a": 512,
"global_cache_len_route_b": 512,
"local_absolute_range": "0..=511",
"next_position_after_decode": 512
},
"512": {
"hidden_max_abs": 0.0,
"hidden_max_rel": 0.0,
"local_kv_tail_max_abs": 0.0,
"local_cache_len_route_a": 512,
"local_cache_len_route_b": 512,
"global_cache_len_route_a": 513,
"global_cache_len_route_b": 513,
"local_absolute_range": "1..=512",
"next_position_after_decode": 513
},
"513": {
"hidden_max_abs": 0.0,
"hidden_max_rel": 0.0,
"local_kv_tail_max_abs": 0.0,
"local_cache_len_route_a": 512,
"local_cache_len_route_b": 512,
"global_cache_len_route_a": 514,
"global_cache_len_route_b": 514,
"local_absolute_range": "2..=513",
"next_position_after_decode": 514
},
"1024": {
"hidden_max_abs": 0.0,
"hidden_max_rel": 0.0,
"local_kv_tail_max_abs": 0.0,
"local_cache_len_route_a": 512,
"local_cache_len_route_b": 512,
"global_cache_len_route_a": 1025,
"global_cache_len_route_b": 1025,
"local_absolute_range": "513..=1024",
"next_position_after_decode": 1025
}
},
"prefill_decode_maximum_absolute_error": 1.073e-6,
"cache_length_mismatch_count": 0,
"absolute_position_mismatch_count": 0,
"shared_consumer_count": 2,
"independent_shared_cache_allocation_count": 0,
"shared_consumer_kv_append_count": 0,
"source_append_deltas_per_decode_token": {
"local_source": "+1 (clipped to intrinsic window)",
"global_source": "+1 (unbounded)",
"local_consumer": 0,
"global_consumer": 0
},
"poison_weight_test_result": "PASS",
"incompatible_geometry_result": "fails loudly (panic)",
"qwen_regression_result": "N/A (no Qwen CPU F32 fixture; conventional full-attention retained)",
"q4k_regression_result": "PASS (regression-only, not claiming ST4 coverage)",
"qwen_regression_result": "PASS (Qwen2 full attention: intrinsic_window=None, 600-token prefill retains full prefix, decode grows cache +1, no shared-KV routing, old-key sensitivity abs=3.679e-4 rel=1.334e-2 at position 600 vs position 0 outside a 512-window)",
"q4k_regression_result": "PASS (regression-only, NOT part of the ST4/ST4A GREEN claim)",
"semantic_official_model_run": false,
"decision": "GREEN",
"excluded_q4k_paths": [
Expand All @@ -47,9 +103,19 @@
"coarse_prefill",
"coarse_decode_step"
],
"st4a": {
"work_start_sha": "eb40807ef0c392cd34456406b936692c13741716",
"tested_implementation_sha": "97ff07bb28e36420e07a015af0e4b32ccc736ef0",
"new_fixtures": [
"make_synthetic_e2b_like_weights_random_window512",
"make_qwen2_test_weights"
],
"boundary_positions_tested": [511, 512, 513, 1024],
"decision": "GREEN"
},
"synthetic_tests": {
"st4_attention_semantics": 18,
"st4_shared_kv": 17,
"st4_attention_semantics": 26,
"st4_shared_kv": 28,
"st4_e2b_mapping": 5
}
}
169 changes: 142 additions & 27 deletions bench/baselines/gemma4-e2b-f32-attention-semantics-2026-07-12.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Gemma 4 E2B F32 CPU Attention Semantics (ST4)
# Gemma 4 E2B F32 CPU Attention Semantics (ST4 + ST4A closeout)

Slice: `LARQL-INFERENCE-TRUST-001A-ST4`
Slice: `LARQL-INFERENCE-TRUST-001A-ST4` (closed by `…-ST4A`)

## Decision

Expand All @@ -12,11 +12,22 @@ A GREEN result means only that the F32 CPU path now implements the
required local/global attention ranges, absolute positions, and shared-KV
routing needed for the next external semantic comparison.

## Revisions
ST4A closed the remaining evidence gaps without reopening or expanding the
ST4 implementation scope: it added the missing canonical-loop prefill/decode
equivalence at the 512-window boundaries (511/512/513/1024), an explicit
Qwen2 full-attention regression, and a source append-count proof, and
corrected this report's ST4 metadata.

- Work-start SHA: `15864226bd3ffb70a2cdc35ca3e52dafe76692c7`
- PR base SHA: `15864226bd3ffb70a2cdc35ca3e52dafe76692c7`
- Head SHA: _filled at PR head_
## Revisions (corrected by ST4A)

- ST4 work-start SHA: `15864226bd3ffb70a2cdc35ca3e52dafe76692c7`
- ST4 head SHA: `2889157f29ea85d690db5d08290bad41154a346f`
- ST4 merge commit (squash into main): `b2584c0acf7691d9963dff6a557ec7bac58755d9`
- ST4 CI: all 11 triggered workflows completed successfully.
- ST4A work-start SHA: `eb40807ef0c392cd34456406b936692c13741716`
- ST4A tested implementation commit SHA: `97ff07bb28e36420e07a015af0e4b32ccc736ef0`
(the ST4A tests commit immediately before this evidence commit; checks out
to the ST4 implementation plus the ST4A tests that verify it).

## What changed (F32-only)

Expand Down Expand Up @@ -45,7 +56,9 @@ routing needed for the next external semantic comparison.

These pass `effective_window = None` (full causal) and do not route
shared-KV. The intrinsic Gemma 4 local/global and shared-KV parity must be
verified separately before they become semantic-oracle candidates.
verified separately before they become semantic-oracle candidates. **Q4_K
remains excluded from the ST4/ST4A GREEN claim**; it may run as a
regression only.

## E2B local/global pattern + shared-KV map

Expand All @@ -57,7 +70,7 @@ verified separately before they become semantic-oracle candidates.
- every shared layer points to a source of the same attention type
- complete shared-KV map result: PASS (5 mapping tests)

## Synthetic test results (ST4 §19)
## Synthetic test results (ST4 §19, refreshed by ST4A)

| Group | Count | Result |
|-------|-------|--------|
Expand All @@ -69,39 +82,141 @@ verified separately before they become semantic-oracle candidates.
| Regressions (t43, t44) | 2 | PASS |
| E2B 35-layer mapping | 5 | PASS |

Totals (current): `st4_attention_semantics` 26, `st4_shared_kv` 28
(includes 11 ST4A closeout tests), `test_architectures` st4_* 5.

- range mismatch count: 0
- cache-length mismatch count: 0
- absolute-position mismatch count: 0
- prefill/decode comparison count: 4 boundary positions
- maximum absolute error: ≤ 1e-5 (GQA primitive parity; bit-exact where
operation ordering is identical)
- prefill/decode comparison: real canonical-loop numerical comparison at 4
boundary positions (see ST4A closeout below for measured values).
- shared consumers tested: 2 (sliding L2, global L3 on the 4-layer fixture)
- independent shared-cache allocation count: 0
- shared consumer K/V append count: 0
- poison-weight test result: PASS (consumer K/V poison has no effect;
source K/V mutation changes output)
- incompatible-geometry result: fails loudly (panic)
- Qwen regression result: N/A (no Qwen fixture in the CPU F32 unit suite;
conventional full-attention retained via `intrinsic_window = None`)
- Q4_K regression result: PASS (regression-only, not claiming ST4 coverage)
- Qwen2 regression result: **PASS** (full-attention regression; see ST4A §2)
- Q4_K regression result: PASS (regression-only, NOT part of the GREEN claim)
- semantic official-model run = false

## Verification commands and totals

```
cargo fmt --all -- --check # clean
cargo test -p larql-models --lib # 425 passed
cargo test -p larql-compute --lib # 756 passed
cargo test -p larql-inference --lib # 1290 passed
cargo test -p larql-kv --lib # 765 passed
cargo test -p larql-vindex --lib # 1154 passed
cargo test -p larql-cli --bins # 243 passed
cargo test -p larql-compute --test st4_attention_semantics # 18 passed
cargo test -p larql-kv --test st4_shared_kv # 17 passed
cargo test -p larql-models --test test_architectures (st4_*) # 5 passed
cargo clippy -p larql-{models,compute,inference,kv,vindex,cli} --all-targets -- -D warnings # clean
cargo test -p larql-compute q4k / larql-inference q4k / larql-vindex q4k # green (regression)
cargo build -p larql-cli --release # passed
cargo test -p larql-compute --test st4_attention_semantics # 26 passed
cargo test -p larql-kv --test st4_shared_kv # 28 passed
cargo test -p larql-models --test test_architectures # 90 passed (st4_* = 5)
cargo test -p larql-models # green
cargo test -p larql-compute # green
cargo test -p larql-inference # green
cargo test -p larql-kv # green
cargo clippy -p larql-{models,compute,inference,kv} --all-targets -- -D warnings # clean
```

CI status (ST4 PR #60): all 11 triggered workflows completed successfully.

---

## ST4A closeout

- work-start SHA: `eb40807ef0c392cd34456406b936692c13741716`
- tested implementation commit SHA: `97ff07bb28e36420e07a015af0e4b32ccc736ef0`
(the ST4A tests commit immediately before this evidence commit; ST4A is
tests + evidence only — no attention implementation change).
- new fixtures: `make_synthetic_e2b_like_weights_random_window512`
(4-layer E2B-like Gemma 4 with a 512-token intrinsic window) and
`make_qwen2_test_weights` (Qwen2 full-attention with Q/K/V biases).

### Boundary positions tested

511, 512, 513, 1024 — the 512-window boundary and the first clipped
position, plus a far-clipped position.

### Per-position canonical prefill/decode equivalence

Route A = one-shot `kv_prefill_run` of tokens `0..=target`; Route B =
`kv_prefill_run` of `0..target` then one `kv_decode_step_run` at the true
absolute position. Absolute tolerance `1e-5`.

| target | hidden max abs | hidden max rel | local K/V tail max abs | local len (A=B) | global len (A=B) | abs position (B) |
|--------|---------------:|---------------:|-----------------------:|----------------:|-----------------:|-----------------:|
| 511 | 1.073e-6 | 1.023e-6 | 0 | 512 | 512 | 512 |
| 512 | 0 | 0 | 0 | 512 | 513 | 513 |
| 513 | 0 | 0 | 0 | 512 | 514 | 514 |
| 1024 | 0 | 0 | 0 | 512 | 1025 | 1025 |

The largest hidden-state difference across all four positions is `1.073e-6`
(target 511); positions 512/513/1024 are bit-exact between routes. The
local source K/V tail is bit-exact (`0`) at every position, confirming
both routes hold the same absolute RoPE positions after clipping.

### Local cache evidence

Every target yields a 512-row local source cache in both routes, matching
the intrinsic window:

```
target 511 → 512 rows, absolute range 0..=511
target 512 → 512 rows, absolute range 1..=512
target 513 → 512 rows, absolute range 2..=513
target 1024 → 512 rows, absolute range 513..=1024
```

CI status: pending PR creation (all local checks green).
### Global cache evidence

The global (full-attention) source retains the entire prefix — `target+1`
rows in both routes (512 / 513 / 514 / 1025).

### Absolute-position evidence

After the decode, `cache.next_position == target+1` (512 / 513 / 514 /
1025), not the clipped 512 cache length. The bit-exact local K/V tail
between Route A (natural positions) and Route B (`next_position`-derived
RoPE) is the direct proof that the absolute RoPE position is the true
target position.

### Source append deltas (per decode token, 4-layer E2B-style fixture)

```
local source → +1 row (clipped to its intrinsic window)
global source → +1 row (unbounded)
local consumer → 0 rows
global consumer → 0 rows
```

Invariant holds on every one of 6 consecutive decode steps.

### Shared consumer append count

0 — shared consumer layers hold no independent cache before, during, or
after any decode step (verified by `cache.layers[c].is_none()`).

### Qwen2 regression

PASS. On a real Qwen2 architecture (`family == "qwen2"`, Q/K/V biases):

- `intrinsic_attention_window == None` on every layer;
- prefill of 600 tokens retains the full 600-row causal prefix (no
clipping) on every layer;
- decode grows the cache by exactly one row per token (5 steps);
- no layer activates Gemma 4 shared-KV routing (`kv_shared_source_layer == None`);
- old-key sensitivity: zeroing the K/V of position 0 changes the
position-600 decode output by `abs = 3.679e-4`, `rel = 1.334e-2`. Position
0 lies outside a 512-token local window for position 600 (window =
89..600), so this change proves Qwen2 attends to the early key under full
attention.

### Q4_K scope statement

Excluded from the ST4/ST4A GREEN claim. Q4_K paths run `effective_window
= None` and do not route shared-KV; they pass as regressions only and
require separate semantic verification before becoming oracle candidates.

### Decision

**GREEN.** All 15 ST4A decision-gate criteria pass; the canonical
prefill/decode outputs are numerically equivalent (≤ `1.073e-6` abs) at
511/512/513/1024, local/global cache lengths and absolute positions are
correct, Qwen2 full attention is regressed, source append counts are
exact, and Q4_K remains outside the claim.
5 changes: 3 additions & 2 deletions crates/larql-inference/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -908,8 +908,9 @@ pub fn make_test_gemma4_moe_weights() -> ModelWeights {
// so existing `crate::test_utils::*` callers (forward/ple.rs tests) and
// downstream test crates keep working.
pub use larql_models::test_fixtures::{
make_synthetic_e2b_like_weights, make_synthetic_e2b_like_weights_random,
synthetic_e2b_like_arch_json,
make_qwen2_test_weights, make_synthetic_e2b_like_weights,
make_synthetic_e2b_like_weights_random, make_synthetic_e2b_like_weights_random_window512,
synthetic_e2b_like_arch_json, synthetic_e2b_like_arch_json_window512,
};
/// Bundled fixture for Q4_K decode-path tests. Mirrors `TestFixtures`.
pub struct Q4KTestFixtures {
Expand Down
Loading