Skip to content

feat(cloudtpu): M4C decode lift — K-major tile-aligned quants, split-X Q4 dot, KV donation, BF16 MXU - #25

Open
saariuslystoned wants to merge 8 commits into
mainfrom
feat/ggml-cloudtpu-decode-lift
Open

saariuslystoned wants to merge 8 commits into
mainfrom
feat/ggml-cloudtpu-decode-lift

Conversation

@saariuslystoned

Copy link
Copy Markdown
Owner

Stacked on #19 (feat/ggml-cloudtpu-m4) for Issue #16 (Track 1: ggml-cloudtpu).

Summary

Six TPU-native decode & kernel upgrades with zero Python at runtime (MAPS_LIBPYTHON=0, LDD_LIBPYTHON=0):

  1. TPU-native K-major N-minor quantized HBM layout ([B3, B2, NB, 16/32, N] + [B3, B2, NB, N]): Aligns quantized weights and scales directly with TPU (8, 128) HBM tiles (0% minor-dim padding vs 4x/8x bloat on [N, NB, 32/16]), eliminates runtime weight reshapes/transposes, broadcasts scales along axis 3 without HBM materialization, and gathers selected rows directly on the last axis in GET_ROWS.
  2. Zero-concatenate split-activation Q4 matmul (CLOUDTPU_Q4_SPLIT_DOT=1): Replaces weight stablehlo.concatenate with dot(x_lo, w_lo) + dot(x_hi, w_hi) on [NB, 16, N] nibble halves (+78% on Llama-3.1-8B Q4_K_M decode vs single concatenated dot: 69.56 vs 39.34 tok/s).
  3. Single-token SET_ROWS dynamic_update_slice + in-place KV buffer donation (CLOUDTPU_DONATE_KV=1): Emits {tf.aliasing_output = idx : i32} + ExecutableBuildOptionsProto.alias_passthrough_params with runtime exclusive-ownership donation checks (non_donatable_input_indices fallback when aliased).
  4. Llama-3 ROPE n_dims == 0 probe fix: Keeps rope_freqs.weight resident in TPU HBM during llama-model-loader buffer placement, eliminating the 65 CPU/TPU graph splits per token on Llama-3.1-8B.
  5. BF16 MXU contraction (CLOUDTPU_MATMUL_BF16=1): Keeps affine q * d + m dequantization in F32 VPU precision and casts once to BF16 for native MXU contraction (dense F32 weights stay F32).
  6. Multi-chip SPMD async collective overlap (CLOUDTPU_ASYNC_COLLECTIVES=1): Encodes all 7 XLA TPU async collective flags into DebugOptions.xla_backend_extra_options + monotonic launch_id on P > 1, plus axis-aware SPMD sharding for K-major quantized weights and CLOUDTPU_MAX_FUSE_OPS=512 (CLOUDTPU_FUSE_ATTN=0/1).

Live $0 Colab v5e-1 Verification (libtpu.so, MAPS_LIBPYTHON=0)

Op & Host Parity

  • Clean-room audit: PASSED across all 100 tracked files (0 forbidden paths/binaries).
  • Standalone test_cloudtpu_host: PASSED (0 failures) on Host Mock AND live v5e-1 (CLOUDTPU_MOCK=0), including dynamic_update_slice + {tf.aliasing_output}, alias_passthrough_params, DebugOptions.xla_backend_extra_options, and both Q4 split-dot / single-dot modes.
  • Live v5e-1 test-backend-ops -b CLOUDTPU (CLOUDTPU_MOCK=0):
    • SET_ROWS: 65/65 | ROPE: 287/287 | GET_ROWS: 56/56
    • MUL_MAT q4_K: 114/114 (split=1 & split=0) | q6_K: 63/63 | q8_0: 102/102 | q4_0: 102/102
  • 4-chip SPMD Host Mock (CLOUDTPU_MOCK_DEVICES=4): MUL_MAT q4_K & q8_0 passed.

End-to-End GGUF Throughput (llama-bench -ngl 99 -fa 1 -p 512 -n 64 -r 3)

Model (GGUF) Quant M4B pp512 M4C pp512 M4B tg64 M4C tg64 (FUSE_ATTN=0 / 1) tg64 Lift
Qwen2.5-1.5B-Instruct Q4_K_M 28,132.27 22,220.93 192.06 190.19 / 209.88 +9.3%
Qwen2.5-1.5B-Instruct Q8_0 28,371.30 29,662.17 202.96 206.00 / 210.63 +3.8%
Meta-Llama-3.1-8B-Instruct Q4_K_M 4,726.56 6,524.26 38.74 69.56 / 70.24 +81.3% (1.81x)
Meta-Llama-3.1-8B-Instruct Q8_0 4,237.41 6,963.31 53.06 60.33 / 57.66 +13.7% (>62% peak HBM BW)
  • Coherence (llama-cli): 17 * 23 = 391 verified on live v5e-1.
  • Zero Python: MAPS_CHECKED=1 MAPS_LIBPYTHON=0, LDD_LIBPYTHON=0.
  • Teardown: Verified 0 active Colab sessions ($0 GCP spend).

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