nx_flash_byte_exact_gate.nx
buildroot/runtime/nx_flash_byte_exact_gate.nx
about
nx_flash_byte_exact_gate.nx -- TWO-PASS BYTE-EXACT flash attention: the determinism+memory exceed.
The team's one-pass online-softmax flash (nx_flash_attention) is memory-efficient but only EPS-matches naive
(eps_q10=100) because the online rescale `acc*exp(m_old-m_new)/SCALE` ROUNDS in fixed-point. This rung proves a
TWO-PASS flash -- pass-1 finds the GLOBAL row-max, pass-2 recomputes exp(s-gmax) and accumulates EXACTLY (no
rescale) -- is BYTE-EXACT == naive AND block-size-INVARIANT (any tile size -> identical output), while keeping
O(block) score memory (not O(n^2)). = byte-exact AND memory-efficient attention -- the combination float
FlashAttention CANNOT do (its parallel float reductions are non-deterministic).
criteria:
1 two-pass(block=2) == naive BYTE-EXACT (0 mismatches)
2 two-pass(block=1) == naive BYTE-EXACT
3 two-pass(block=4=full) == naive BYTE-EXACT (=> block-size-INVARIANT = the determinism exceed)
4 output is the known non-trivial answer [[17,1],[21,2]] (real attention, not all-zeros)
5 memory win: two-pass score scratch (block) < naive score scratch (n_kv) at byte-exactness
expect_exit: 0 license_tier: ORIGINAL
dependencies 2 imports · 0 importers
imports: nx_syscalls.nxnx_gate_verdict.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 18 | const SCALE: i64 = 1000 |
functions
| 20 | func dp(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } |
| 21 | func dn(v: i64) -> i64 |
| 31 | func chk(name: *u8, ok: i64) -> i64 |
| 35 | func printw(label: *u8, w: *i64, n: i64) -> i64 |
| 42 | func eq(x: i64) -> i64 |
| 56 | func dot(a: *i64, b: *i64, d: i64) -> i64 |
| 64 | func naive_attn(Q: *i64, K: *i64, V: *i64, nq: i64, nkv: i64, d: i64, out: *i64) -> i64 |
| 99 | func twopass_attn(Q: *i64, K: *i64, V: *i64, nq: i64, nkv: i64, d: i64, bs: i64, out: *i64) -> i64 |
| 145 | func weq(a: *i64, b: *i64, n: i64) -> i64 called by 1: main |
| 152 | func main() -> i64 |