BitState / Bitstate /BitState_PoC_experiment_matrix_EN_v0.5.md
mktnhr's picture
NEW
2698a31 verified
|
Raw History Blame Contribute Delete
7.92 kB
# BitState / HSDR PoC Experiment Matrix — v0.5
Purpose: make the experiment falsifiable, separate state-count correctness from numerical representation error, and test the new dependency-breaking pure-LNS path against the dyadic reference path.
## A. Correctness layers
| ID | Test | Input | Reference | Candidate output | Required result |
|---|---|---|---|---|---|
| C0 | LNS8 decode | all codes 0..127, both signs | FP64 formula | decoded value | exact within FP rounding |
| C1 | phase/band decomposition | all non-zero codes | direct formula | `phase=k&7`, `band=k>>3` | exact |
| C2 | direct 8-phase accumulation | K=128 vectors | direct LNS8->FP64 sum | `A[L3] += ±(1<<E4)` | exact within FP rounding |
| C2b | ternary signed population | K=128 vectors | direct state tally | POPCOUNT histogram | bit-exact state counts |
| C2c | direct-vs-histogram phase state | same vectors | direct `A[0..7]` | histogram `sum_o H[p][o]<<o` | bit-exact `A[0..7]` |
| C3 | dyadic reconstruction | signed histogram | exact LNS8->FP64 sum | shift/add reference | equivalent within FP rounding |
| C4 | population folding | `n=1..128` identical states | FP64 `n*x` | `k + 8*log2(n)` | exact in real math; quantify LUT rounding |
| C5 | fractional LNS same-sign add | exhaustive/sampled state pairs | FP64 add then log | `kappa+` path | quantify internal-code error |
| C6 | fractional LNS subtract | opposite signs incl. equality | FP64 subtraction | `kappa-` + zero handling | exact zero for equal magnitude; quantify others |
| C7 | balanced pure-LNS tree | random/adversarial K=128 | direct FP64 ternary dot | tree result | error vs internal fractional precision |
| C8 | shared scale in log domain | random positive scales | direct `d*sum` | log-offset scale | quantify scale-offset error |
| C9 | Q9.6 boundary | relevant output range | FP64 / wide fixed | Q9.6 | quantify rounding/saturation; not assumed lossless |
## B. State-distribution sweep
| Distribution | Why |
|---|---|
| one repeated state | best case for population folding |
| 8 phases, one band | isolates phase reduction |
| one phase, 16 bands | tests intra-phase balanced LNS reduction |
| octave/band sweep | tests exact +8-code relative positioning |
| uniform random codes | high-cardinality stress case |
| Gaussian-like encoded values | generic realistic distribution |
| captured post-Hadamard Bonsai 2 activations | primary real workload |
For each 64/128-element tile record unique-state count `U`, non-zero signed bucket count `B`, and active phase count `P`.
## C. Weight-distribution sweep
| Pattern | Purpose |
|---|---|
| all +1 | sign-free reference |
| alternating +/- | exact cancellation stress |
| {-1,0,+1} uniform | generic ternary |
| measured Bonsai 2 trit distribution | real workload |
| high zero fraction | tests skip / nonzero mask benefit |
## D. Reuse / amortization sweep
Build activation state representation once and reuse it for `N` output rows.
```text
N = 1, 8, 32, 128, 512, 2048
```
Report separately:
```text
T_encode = activation LNS8 encoding
T_stateset = reusable state-set construction
T_intersect = one row's weight-mask intersection + POPCOUNT
T_reduce_dyad = dyadic reference reduction
T_reduce_lns = pure fractional-LNS reduction
T_scale = scale application / log-offset handling
T_total_ref(N) = T_encode + T_stateset + N*(T_intersect + T_reduce_dyad + T_scale)
T_total_lns(N) = T_encode + T_stateset + N*(T_intersect + T_reduce_lns + T_scale)
```
## E. Kernel variants
| ID | Variant | Purpose |
|---|---|---|
| B0 | current fork ternary dot | baseline |
| B1 | scalar direct decode | simple reference |
| D0 | scalar direct 8-phase accumulator | correctness baseline for `A[L3] += ±(1<<E4)` |
| D1 | Tile64 direct phase-mask routing | primary ordinary-CPU K→8 reduction candidate |
| D2 | Tile32 word-width equivalent | CPU/GPU width-invariance correctness check |
| P0 | scalar signed histogram | validates state-count math |
| P1 | full-state masks rebuilt per row | intentionally unamortized comparison |
| P2 | reusable sparse state masks | primary dependency-breaking hypothesis |
| P3 | phase-local signed histogram | compares explicit population path with direct A[8] |
| P4 | AVX2/SWAR state construction + POPCNT | optimized CPU state front-end |
| R0 | dyadic shift/add materializer | reference post-POPCOUNT path |
| L0 | scalar fractional-LNS add/sub | correctness reference |
| L1 | balanced sparse-bucket pure-LNS tree | primary pure-LNS CPU hypothesis |
| L2 | 8-phase normalized `120..127` anchor path | tests relative-state normalization |
| P5 | PTQ1_0 integrated decode | dense-packing follow-up |
| G0 | CUDA ballot state-per-lane | GPU front-end candidate |
| G1 | CUDA match-any grouping + balanced state reduction | GPU candidate |
## F. K sweep
```text
K = 32, 64, 128, 256, 4096, 5120, 8192
```
K=128 is especially important because it aligns with Bonsai 2 scale groups.
## G. Fractional-LNS precision sweep
Test internal fractional code bits independently of storage LNS8:
```text
F = 4, 6, 8, 10, 12, 14
```
For each `F`, generate `count_log[n]`, `kappa_plus[d]`, and `kappa_minus[d]` from a high-precision reference. Measure pairwise error, full-tree error, and LUT footprint.
## H. Reduction-order / dependency sweep
Compare:
```text
serial left fold
balanced tree
phase-local balanced tree -> 8-phase 8->4->2->1 tree
sparse global balanced tree
```
Report both operation count and **dependent critical-path stages**. This is a first-class metric, not a secondary implementation detail.
## I. CPU metrics
- ns / 128-weight group
- cycles / output row
- cycles / weight
- instructions / weight
- uops / IPC
- product-state ADD cost
- phase-mask / selector build cost
- direct K→8 weighted reduction cost
- state-set build cost for histogram variants
- unique states / non-zero signed buckets
- POPCNT count and throughput
- fractional-LNS LUT loads
- dependent LNS-add/sub stages
- L1/L2 misses
- actual memory bandwidth
- crossover reuse count vs baseline
## J. End-to-end metrics
- TG128
- PP512 as secondary context
- model load / memory footprint unchanged unless explicitly testing metadata
- quality/perplexity or task check vs existing fork
- LNS8 saturation / underflow rate
- pure-LNS vs dyadic end-to-end delta
## K. Reporting rule
Always report at least these components separately:
```text
1. activation / product-state encoding
2. phase-mask / selector construction
3. direct K→8 weighted reduction
4. state-set construction + POPCOUNT (histogram variants)
5. eight-phase dyadic finalization
6. pure-LNS reduction cost
7. dependent critical-path depth
8. end-to-end integrated result
```
This prevents a fast microkernel from hiding conversion costs and prevents a slow first implementation from hiding the benefit of reusable state sets or a shallower reduction dependency graph.
## L. Reference artifact for direct 8-phase correctness
Use `LNS8_base74_8step_zone8_popcount_demo_JA_v0.8_bitslice128_validation.xlsx` as the visual reference for the direct path:
- `Inputs_128` -> two Tile64 blocks;
- `S1|E4|L3` decomposition;
- phase masks as intermediate routing selectors;
- `±(1<<E4)` routed into eight integer accumulators;
- equality against direct decoded sum.
This workbook proves correctness of the reduction identity, not performance.
## M. Stop / continue decision
Continue optimization if at least one realistic region shows either:
- lower per-output-row cost after amortization;
- materially lower dependent reduction depth with competitive total work;
- lower memory traffic with competitive latency;
- pure-LNS finalization beats or simplifies the dyadic materializer without unacceptable quality loss.
Stop or redesign if real post-Hadamard state cardinality, mask/POPCOUNT cost, or fractional-LNS LUT/reduction cost leaves no crossover against the existing ternary kernel.