Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/om/gpu/dsv41/decoder/check-swa-replay.om # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / om / gpu / dsv41 / decoder / check-swa-replay.om` 114 lines ยท 2777 bytes Raw Blame History 1 note SPDX-License-Identifier: AGPL-3.0-only 2 note Pure Seeded OM-2 Host Verification & Negative-Control Gate for SWA Bounded Replay (dsv41). 3 note Compose after: om/gpu/dsv41/decoder/swa_replay.om 4 5 text swaMsgOk "PASS: dsv41 swa_replay gate (5 checks, skipped_pct=" 6 text swaMsgEnd "%, 0 failures)\n" 7 text swaMsgBad "FAIL: swa_replay check=" 8 text swaMsgNl "\n" 9 10 fn swaPrint s view uchar * to void 11 r = write 1 s 0 len s 12 end 13 14 fn swaPrintU x ulong to void 15 b = new uchar 24 0 16 pos = ulong 24 17 v = x 18 while true 19 pos = sub pos 1 20 put b pos uchar add 48 rem v 10 21 v = div v 10 22 if eq v 0 23 break 24 end 25 end 26 r = write 1 b pos sub 24 pos 27 end 28 29 fn swaFail code ulong to int 30 swaPrint swaMsgBad 31 swaPrintU code 32 swaPrint swaMsgNl 33 ret int code 34 end 35 36 fn main to int 37 swaInitDefault 38 39 note Check 1: Short prompt <= 134 always yields 0 prefix hit. 40 if ne swaComputeHitLen 134 128 true 0 41 ret swaFail 1 42 end 43 if ne swaComputeHitLen 100 100 true 0 44 ret swaFail 2 45 end 46 47 note Check 2: Long prompt L=4096 with full block hit (4096) caps at floor((4096-134)/128)*128 = 3840. 48 hHit = swaComputeHitLen 4096 4096 true 49 if ne hHit 3840 50 ret swaFail 3 51 end 52 note On SWA KV cache miss, backs off by exactly one 128-token block: 3840 - 128 = 3712. 53 hMiss = swaComputeHitLen 4096 4096 false 54 if ne hMiss 3712 55 ret swaFail 4 56 end 57 note Partial block hit L1=1024 with SWA miss -> 896; with SWA hit -> 1024. 58 if ne swaComputeHitLen 4096 1024 true 1024 59 ret swaFail 5 60 end 61 if ne swaComputeHitLen 4096 1024 false 896 62 ret swaFail 6 63 end 64 65 note Check 3: Compact prefill (L=2560, 40 layers) runs all 20 encoder layers for all 2560 tokens, 66 note and runs 20 decoder layers ONLY for the last 140 tokens (2420..2559). 67 put swaSkippedLayers 0 0 68 put swaExecutedLayers 0 0 69 for p ulong 2560 70 for L ulong 40 71 run = swaShouldRunPrefillLayer L p 2560 72 end 73 end 74 note Expected executed = 20*2560 + 20*140 = 51200 + 2800 = 54000; skipped = 20*2420 = 48400 (47% saved!). 75 if or ne get swaExecutedLayers 0 54000 ne get swaSkippedLayers 0 48400 76 ret swaFail 7 77 end 78 79 note Check 4: Truncated SWA key range during bounded replay starting at s = 2420. 80 rng = new ulong 2 0 81 if not swaTruncatedKeyRange 2420 2420 rng 82 ret swaFail 8 83 end 84 if or ne get rng 0 2420 ne get rng 1 2420 85 ret swaFail 9 86 end 87 if not swaTruncatedKeyRange 2500 2420 rng 88 ret swaFail 10 89 end 90 if or ne get rng 0 2420 ne get rng 1 2500 91 ret swaFail 11 92 end 93 if not swaTruncatedKeyRange 2559 2420 rng 94 ret swaFail 12 95 end 96 if or ne get rng 0 2432 ne get rng 1 2559 97 ret swaFail 13 98 end 99 100 note Check 5: Negative controls (keep_tokens < 134 refused; pos < replayStart refused). 101 if swaInit true 100 102 ret swaFail 14 103 end 104 if swaTruncatedKeyRange 2400 2420 rng 105 ret swaFail 15 106 end 107 108 tot = add get swaExecutedLayers 0 get swaSkippedLayers 0 109 pct = div mul get swaSkippedLayers 0 100 tot 110 swaPrint swaMsgOk 111 swaPrintU pct 112 swaPrint swaMsgEnd 113 ret 0 114 end