Skip to content

feat(cloud-tpu): branchless VREG 4-bit IQ4_XS select-tree LUT kernel + parity tests (#43) - #46

Open
saariuslystoned wants to merge 2 commits into
mainfrom
feat/43-vreg-iq4xs-select-tree-lut
Open

saariuslystoned wants to merge 2 commits into
mainfrom
feat/43-vreg-iq4xs-select-tree-lut

Conversation

@saariuslystoned

Copy link
Copy Markdown
Collaborator

Closes #43 (clean-room branchless 4-bit VREG select-tree LUT kernel in FreeTile + StableHLO/Python emitter, 0.0 bit-exact parity tests across non-power-of-2 MoE shapes, generalization across IQ4_XS/IQ4_NL/NF4/FP4, CI wiring, and reproducible proof doc).

Summary

  • Branchless 4-bit VREG select-tree LUT (freetile/, llama-cpp-cloudtpu/, tools/select_tree_lut.py): replaces dynamic XLA gather with a 4-level branchless select(bit, hi, lo) tree over 16-entry codebooks (IQ4_XS / kvalues_iq4nl, IQ4_NL, NF4, FP4), verified statically to emit zero gather ops.
  • Bit-exact 0.0 parity & shape coverage (freetile/tests/, llama-cpp-cloudtpu/tests/test_cloudtpu_host.cpp, tools/test_select_tree_lut.py): verifies max_abs_diff == 0.0 across non-power-of-2 MoE shapes (1/64/128×2304², 128×3072², 128×4096², 64×6144²) and cross-checks against libopenbuenos scalar IQ4_XS dequantization.
  • Proof & CI (proof/cloud-tpu-iq4xs-select-tree/PROOF.md, .github/workflows/ci.yml): host bit-exact + IR proof verified here; ready-to-run Cloud TPU v5e/v6e live timing commands documented separately.

Verification

  • make -C freetile test + ASan+UBSan: PASS (0 failures, max_abs_diff=0.0).
  • CLOUDTPU_MOCK=1 test_cloudtpu_host: PASS (0 failures).
  • python3 tools/select_tree_lut.py --self-test & tools/test_select_tree_lut.py: 6/6 OK.
  • make -C libopenbuenos verify-header-host host test & make -C libopentpu verify-header-host host test: PASS.
  • Clean-room audit across 198 files: PASS (0 errors).

saariuslystoned and others added 2 commits November 29, 2026 03:49
…r IQ4_XS/NL dequant (freetpu#46)

- Handle non-multiple K tails (k%32/k%256) in dequant_iq4_nl_row and dequant_iq4_xs_row
  instead of silent truncation leaving outputs unwritten; both C++ and Python mirror
  now dequantize the trailing partial block with correct scale decoding
- Add null-pointer and k==0 guards (throw invalid_argument) fail-closed to all dequant entry points
- Fix iq4xs_dequant_matmul row stride to ceil(K/256)*136 for non-multiple K
- Harden select_tree_select_count against shift UB for bits>=32 (saturate UINT32_MAX) and Python count_selects bits range check
- Fuzz-validated bit-exact tree vs direct and scalar reference over 20k cases

Audit: ASan+UBSan -Wall -Wextra -Werror clean, 10k random + boundary + subnormal + unaligned
Clean-room grep: no private terms
@saariuslystoned

Copy link
Copy Markdown
Collaborator Author

Adversarial Hardening & Public-Roads Audit Receipt (6f435ce5)

  • Prior PR head: 27453f96 → Hardened head: 6f435ce5
  • Fixes landed: non-multiple-K tail truncation (C++/Python), ceil row-stride, shift-UB in select_tree_select_count, and null pointer guards.
  • Verification: Bit-exact IQ4_XS parity vs GGML/libopenbuenos, ASan+UBSan -Wall -Wextra -Werror PASS, 20,000-case fuzz + boundary + unaligned tests green, public-roads diff scan clean.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(cloud-tpu): ship branchless VREG 4-bit IQ4_XS select-tree kernel (211x vs XLA gather, faster than BF16)

1 participant