Skip to content

feat(cloud-tpu): wire branchless VREG IQ4_XS/IQ4_NL select-tree LUT into StableHLO, ggml-cloudtpu & FreeTile (#43) - #57

Open
saariuslystoned wants to merge 1 commit into
mainfrom
feat/43-cloud-tpu-vreg-iq4xs-select-tree
Open

saariuslystoned wants to merge 1 commit into
mainfrom
feat/43-cloud-tpu-vreg-iq4xs-select-tree

Conversation

@saariuslystoned

Copy link
Copy Markdown
Collaborator

Addresses #43 (Refs #43 — does not close #43; live Cloud TPU v5e/v6e silicon timing and bare-metal /dev/vfio/0 proof remain human-gated and open on #43).

Context

Phase 1 (#46) landed the standalone host select-tree LUT math, standalone @main StableHLO snippet emitter, and TileIR codebook planning guard. This PR delivers Phase 2, wiring the branchless 4-bit VREG select-tree LUT (15 stablehlo.select ops, 0 stablehlo.gather) into the full Cloud TPU MUL_MAT + GET_ROWS StableHLO pipeline, ggml-cloudtpu.cpp GGUF IQ4_XS/IQ4_NL ingestion/readback, portable FreeTile codebook_dequant semantic op, and a reproducible Cloud TPU Gates 1–4 benchmark script.

Summary

  • End-to-end Cloud TPU StableHLO IQ4_XS_LUT & IQ4_NL_LUT lowering (llama-cpp-cloudtpu/stablehlo_emitter.{hpp,cpp}):
    • Wires TensorStorageKind::IQ4_XS_LUT and TensorStorageKind::IQ4_NL_LUT into emit_stablehlo_program() for MUL_MAT, GET_ROWS, and CPY, supporting native U4 and packed U8 bitcast-to-U4 K-major N-minor HBM storage, BF16 MXU + mm_pad_m decode padding, FP8 MXU (tpu7x), and SPMD SHARD_N/SHARD_K.
    • Requests precision = [HIGHEST, HIGHEST] on F32 IQ4_XS_LUT/IQ4_NL_LUT dot_general so TPU hardware does not silently round F32 operands to BF16.
  • GGUF GGML_TYPE_IQ4_XS & GGML_TYPE_IQ4_NL runtime ingestion (llama-cpp-cloudtpu/ggml-cloudtpu.cpp):
    • Alignment-safe byte-offset unpacking of canonical 136-byte/256-weight block_iq4_xs (split nibbles + 6-bit signed sub-scales ls - 32 + kvalues_iq4nl) and 18-byte/32-weight block_iq4_nl, lossless readback via 8-byte header metadata, HBM allocation sizing, and consistent slot type/shape tracking across partial/view-staged and reused slots.
  • Portable FreeTile codebook_dequant semantic op & codebook extensibility (freetile/):
    • Adds CodebookDequantOp / plan_codebook_dequant_op() across IQ4_XS, IQ4_NL, NF4, FP4 targeting Cloud TPU (stablehlo.select_tree with v5e 16 MiB VMEM cliff characterization <= 5.31M vs >= 9.44M elements), ARM SME2 (sme2.luti4), Qualcomm HVX (hvx.vlut), and PowerVR Volcanic (volcanic.select_tree).
    • Adds generic 1..4-bit emit_stablehlo_select_tree_lut() (3/7/15 selects, 0 gather — composable scalar primitive for future grid-codebook sub-lookups) and packed 18-byte/32-weight BlockCodebook4 (NF4/FP4_E2M1/IQ4_NL) dequantizers.
  • Gates 1–4 Reproducible Cloud TPU Benchmark Script & Proof (tools/select_tree_lut.py, tools/test_select_tree_lut.py, proof/cloud-tpu-iq4xs-select-tree/PROOF.md):
    • --emit-jax-bench generates a clean-room Cloud TPU script covering canonical 136-byte IQ4_XS parity (including an independent scalar row-0 decoder), 512^2..6144^2 VMEM-cliff sweep, XLA gather footguns (mode="promise_in_bounds", int32, flat 1D), and lax.fori_loop BF16 parity with jax.lax.optimization_barrier + lowered/compiled IR checks.

Verification (Head dc9ec44755283a5b42dee675f38cf5e87d76438c)

  • make -C freetile test + ASan/UBSan (-fsanitize=address,undefined -fno-sanitize-recover=all -Wall -Wextra -Wpedantic -Werror): PASS (0.0 bit-exact diff across 2304^2 / 3072^2 / 4096^2 / 6144^2, packed NF4/FP4/IQ4_NL, 2/3-bit 3/7-select IR, 4 portable codebook_dequant backends, Mosaic refusal guard)
  • llama-cpp-cloudtpu Host Mock PJRT (test_cloudtpu_host, pjrt_runtime_guards_test) + ASan/UBSan: PASS (IQ4_XS_LUT 15 selects / 0 gather across 2304..6144 x M=1,64,128, HIGHEST F32 dot precision, IEEE bit-exact MUL_MAT & GET_ROWS on M=4, K=256, N=16 for IQ4_XS_LUT U4/U8-bitcast and IQ4_NL_LUT U4, BF16 M=1 pad8 NMSE < 5e-4)
  • Clean-room OSS boundary & Public Roads Firewall audit across 229 files: PASS (0 violations)
  • Adversarial pre-push review (codex exec -m gpt-6.2-astra, 3 rounds): caught and fixed HIGHEST dot precision on F32 IQ4 matmuls, partial/view/reused-slot SPMD & scale_dtype mismatches, alignment-safe byte-offset IQ4 codecs, TileIR IQ2_XXS/IQ3_XXS over-claiming, and JAX bench canonical 136 B parity + optimization_barrier IR checks.
  • Proof receipt: proof/cloud-tpu-iq4xs-select-tree/PROOF.md

Remaining Human-Gated Silicon Follow-Up

  • Live Cloud TPU v5e/v6e verification (CLOUDTPU_MOCK=0 ./build-cloudtpu/test_cloudtpu_host, python3 tools/select_tree_lut.py --emit-jax-bench, GGML test-backend-ops -b CLOUDTPU -o MUL_MAT) and bare-metal /dev/vfio/0 (MAPS_LIBTPU=0) proof were not run in this PR and remain human-gated on #43.

…nto StableHLO MUL_MAT, ggml-cloudtpu & FreeTile codebook_dequant (#43)
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.

1 participant