Repository navigation
feat(cloud-tpu): branchless VREG 4-bit IQ4_XS select-tree LUT kernel + parity tests (#43) - #46
Merged
Merged
Conversation
…nel and parity tests (#43)
…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
Collaborator
Author
Adversarial Hardening & Public-Roads Audit Receipt (
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #43 — Phase-1 branchless 4-bit VREG select-tree LUT host math/decoders, standalone StableHLO emitters, TileIR
STABLEHLO_SELECT_TREElowering + Mosaic guard, and bit-exact/sanitizer parity tests.Summary
freetile/include/freetile/select_tree_lut.hpp,freetile/src/select_tree_lut.cpp,tools/select_tree_lut.py): implements a 4-level branchlessselect(bit, hi, lo)tree (15selects,0gather) over 16-entry codebooks (IQ4_XS/IQ4_NLviakValuesIq4Nl, sequentialNF4, sequentialFP4_E2M1; 2/3-bit truncation viaselect_tree_f32). Walked via byte-level little-endian loads (zero strict-aliasing UB), overflow-guardediq4xs_dequant_matmul(includingk=0zero-fill), and zero out-of-bounds tail pointer formation.tools/select_tree_lut.pyis a clean-room NumPy reference mirror (produces no MLIR IR).llama-cpp-cloudtpu/stablehlo_emitter.*,llama-cpp-cloudtpu/tests/test_cloudtpu_host.cpp):emit_select_tree_lut4_program()emits a standalone@mainmodule with15stablehlo.selectops and0stablehlo.gatherops acrossU32/U8/U4index inputs, verified via Mock PJRT execution at{4, 8}.freetile/include/freetile/tile_ir.hpp,freetile/src/tile_ir.cpp,freetile/src/mosaic_emitter.cpp): addsQuantFormat::{IQ4_XS,IQ4_NL,NF4,FP4}andLoweringTarget::STABLEHLO_SELECT_TREE(U4planning onv5e/v6eM <= 64), and fails closed inemit_mosaic_kernelby throwing before numericuitofpdequantization.proof/cloud-tpu-iq4xs-select-tree/PROOF.md,.github/workflows/ci.yml): host bit-exact (max_abs_diff = 0.0, IEEE float bit pattern + finiteness +-0.0fsign-bit parity) and Mock PJRT proof; no live-silicon timing is claimed.Proof Block (Head
a394014cedc544f21c07d8f2f6095e0c2cabba84)cmake -S freetile -B build-freetile -DCMAKE_BUILD_TYPE=Release && ctest(5/5 PASS, incl.freetile_select_tree_lut_testsover2304²/3072²/4096²/6144²full weight dequant, matmul full-K,NwithM_tile=min(M,8),k=0..300tails +scalar_iq4_xs_ref,k=0,1,31,257tail matmul,-0.0fFP4 sign bit, andnext_ssachaining) +make -C freetile test(PASS).clang++ -std=c++17 -O2 -g -fsanitize=address,undefined -fno-sanitize-recover=all -Wall -Wextra -Wpedantic -Werror ... test_select_tree_lut.cpp(PASS, 0 warnings/errors).make -C libopenbuenos verify-header-host host test(PASS) &make -C libopentpu verify-header-host host test(PASS).cmake -S llama-cpp-cloudtpu -B build-cloudtpu && ctest(PASS,test_select_tree_lut4_programverifies15selects /0gathers at2304..6144and executesU32/U8/U4bit-exactly on Mock PJRT).python3 tools/select_tree_lut.py --self-test&python3 tools/test_select_tree_lut.py -v(7/7 OK, incl.uint8/uint16NumPy wrap regression & unfusedk-ascending accumulation); clean-room audit across198tracked files (PASS).gpt-6.2-astra, multi-round pre-push loop):IQ4_XS/IQ4_NLdecoders with explicit byte-offset little-endian reads,k=0zero-fill matmul semantics,uint64_tdim-bound overflow checks beforesize_tnarrowing in both StableHLO emitters, andconstexprcodebook tables.uint8/uint16wrap intools/select_tree_lut.py, rejected fractional widths viaoperator.index, matched unfusedk-ascending float32 accumulation, and addedU32/U8/U4Mock PJRT execution + strict float bit-pattern assertions.LoweringTarget::STABLEHLO_SELECT_TREE,PROOF.md, and PR scope (Refs #43) with actual Phase-1 code behavior and remaining#43silicon/wiring gates.