Skip to content

feat(cloudtpu): M4 multi-chip v6e-8/tpu7x SPMD sharding, collectives & SubgraphPlanCache (4.9x v5e-1 decode) - #19

Merged
saariuslystoned merged 18 commits into
mainfrom
feat/ggml-cloudtpu-m4
Nov 23, 2026
Merged

saariuslystoned merged 18 commits into
mainfrom
feat/ggml-cloudtpu-m4

Conversation

@saariuslystoned

Copy link
Copy Markdown
Owner

Summary

Completes M4 of Track 1 (#16), stacked on PR #18 (feat/ggml-cloudtpu):

M4A — Multi-Chip v6e-8 & tpu7x SPMD Sharding + Collectives

  • PJRT Multi-Chip Runtime (pjrt_runtime.{hpp,cpp}):
    • Encodes xla::DeviceAssignmentProto (field 9 of ExecutableBuildOptionsProto) for explicit replica-SPMD (num_replicas=P, num_partitions=1).
    • Adds execute_spmd(...), buffer_from_host_replicated(...), atomic execute stats, and eviction_epoch().
    • Upgrades Host Mock PJRT (CLOUDTPU_MOCK_DEVICES=1..16) with per-chip HBM accounting (v6e-8 32 GiB/chip = 256 GiB, tpu7x-4t 192 GiB/chip = 768 GiB) and lockstep cross-chip all_reduce, all_gather, reduce_scatter, replica_id, and dynamic_slice.
  • StableHLO v1.0 Collectives (stablehlo_emitter.{hpp,cpp}):
    • Emits stablehlo.all_reduce, stablehlo.all_gather, stablehlo.reduce_scatter, stablehlo.replica_id, and stablehlo.dynamic_slice.
    • Supports SHARD_N and SHARD_K across F32/F16/BF16/Q8_0/Q4_0/Q4_K/Q6_K weights and automatic Megatron-LM single-all_reduce FFN fusion (Gate/Up SHARD_N -> local SwiGLU -> Down SHARD_K -> 1 all_reduce, 0 all_gather).
  • Unified SPMD GGML Device (ggml-cloudtpu.cpp):
    • CLOUDTPU_SPMD_CHIPS=auto exposes a single CLOUDTPU device with aggregated mesh HBM (256 GiB on v6e-8, 768 GiB on tpu7x-4t) and automatic 1/P per-chip weight sharding with lossless get_tensor reconstruction.

M4B — Fast-Path SubgraphPlanCache & Decode Optimization

  • Zero-MLIR-re-emission structural SubgraphPlanCache (keyed by compact binary FNV-1a + exact signature words, invalidated via eviction_epoch()).
  • Single-pass (N)$ ggml_gallocr cgraph liveness + O(1) store_tensor_hbm slot reuse + extended fusion (CLOUDTPU_MAX_FUSE_OPS=64, safe SET_ROWS fusion) + async pipelining (ggml_backend_cloudtpu_synchronize).

Proof

  • Live TPU v5e-1 (libtpu.so, zsh Colab, MAPS_LIBPYTHON=0, ldd libpython = 0 on all 5 binaries):
    • Standalone test_cloudtpu_host (CLOUDTPU_MOCK=0): ALL PASSED (0 failures) including live P=1 StableHLO all_reduce / all_gather / reduce_scatter compile & exec + 4-chip tpu7x & 8-chip v6e-8 SPMD Megatron FFN tests.
    • test-backend-ops -b CLOUDTPU (mock=0): MUL_MAT 44/44, FLASH_ATTN_EXT 1697/1697, SET_ROWS 65/65, RMS_NORM 61/61.
    • llama-bench -ngl 99 -fa 1 (M3 -> M4B):
      • Qwen2.5-1.5B-Instruct Q4_K_M: pp128 4,945 -> 15,541, pp512 16,113 -> 28,132, tg64 39.17 -> 192.06 tok/s (4.90x)
      • Qwen2.5-1.5B-Instruct Q8_0: pp128 5,445 -> 16,512, pp512 19,820 -> 28,371, tg64 42.24 -> 202.96 tok/s (4.80x)
      • Meta-Llama-3.1-8B-Instruct Q4_K_M: tg64 33.25 -> 38.74 tok/s (1.17x); coherent llama-cli -c 4096 (17 * 23 = 391)
      • Meta-Llama-3.1-8B-Instruct Q8_0: tg64 35.20 -> 53.06 tok/s (1.51x, 422 GB/s effective HBM BW)
  • Multi-Chip Host Mock Parity (4-chip tpu7x & 8-chip v6e-8):
    • test-backend-ops passed across 1, 4, and 8 chips (MUL_MAT 44/44, RMS_NORM 61/61, SOFT_MAX 107/107, ADD 153/153, MUL 140/140, SCALE 12/12, CPY 157/157, CONT 89/89).
    • End-to-end 2-layer Llama-3 GGUF llama-server confirmed bit-exact identical token output across CPU == 1-chip == 4-chip == 8-chip.
  • Clean-room audit: PASSED across 100 tracked files.
  • Note: Stacked on PR feat(cloudtpu): native C++17 ggml-cloudtpu PJRT backend for llama.cpp (M1–M3, #16) #18; ready for owner review/merge (not self-merged). Paid GCP v6e-8 / tpu7x live runs remain owner-gated.

@saariuslystoned

Copy link
Copy Markdown
Owner Author

Live Cloud TPU v6e-8 (Trillium, 8 chips / 256 GiB HBM) Silicon Proof (MAPS_LIBPYTHON=0)

  • Zero-Python link & runtime: ldd libpython = 0, MAPS_LIBPYTHON=0 across all binaries.
  • test_cloudtpu_host (CLOUDTPU_MOCK=0): ALL PASSED (0 failures) including live 4-chip & 8-chip SPMD collective (all_reduce/all_gather/reduce_scatter) + Megatron FFN tests.
  • test-backend-ops -b CLOUDTPU (CLOUDTPU_SPMD_CHIPS=8): 3,820 / 3,820 PASSED (MUL_MAT 1361/1361, FLASH_ATTN_EXT 1697/1697, ROPE 287/287, ADD 153/153, MUL 140/140, SET_ROWS 65/65, RMS_NORM 61/61, GET_ROWS 56/56).
  • End-to-End 8-Chip GGUF Inference (llama-bench -ngl 99 -fa 1 & llama-cli -c 4096):
    • Qwen2.5-1.5B Q4_K_M: 1-chip pp512 10,479.21 / tg64 54.52; 8-chip pp512 5,212.55 / tg64 12.13
    • Qwen3-32B Q4_K_M (18.40 GiB): 8-chip pp512 2,747.30 / tg64 7.20 (coherent reasoning)
    • Llama-3.3-70B-Instruct Q4_K_M (39.59 GiB, exceeds single-chip 31.25 GiB HBM): 8-chip pp512 502.72 / tg64 2.23 (17 * 23 = 391)
  • Silicon fixes landed on this commit:
    1. GCC < 13 (Ubuntu 22.04 GCC 11) -fpermissive fallback in CMakeLists.txt for pjrt_c_api.h.
    2. Explicit DeviceAssignmentProto + per-device cache key for CLOUDTPU_SPMD_CHIPS=1 on multi-chip hosts (ExecuteShard device-1 fix).
  • VM Teardown: v6e-8 VM deleted and verified 0 active TPU VMs / queued resources.

# Conflicts:
#	.github/workflows/ci.yml
#	llama-cpp-cloudtpu/CMakeLists.txt
#	llama-cpp-cloudtpu/README.md
#	llama-cpp-cloudtpu/build.sh
#	llama-cpp-cloudtpu/ggml-cloudtpu.cpp
#	llama-cpp-cloudtpu/patches/llama-cpp-b12608-cloudtpu.patch
#	llama-cpp-cloudtpu/pjrt_runtime.cpp
#	llama-cpp-cloudtpu/pjrt_runtime.hpp
#	llama-cpp-cloudtpu/stablehlo_emitter.cpp
#	llama-cpp-cloudtpu/stablehlo_emitter.hpp
#	llama-cpp-cloudtpu/tests/test_cloudtpu_host.cpp
…ion, SHARD_K broadcast, scratch HBM release, README)
… all_reduce, REDUCE_SCATTER replica-local, S32 mock collectives)
… LRU recency, selective plan pruning, registered spmd_chips)
…harding, non-owning plan exec_key, liveness in try)
@saariuslystoned
saariuslystoned merged commit b5065f5 into main Nov 23, 2026
2 checks passed
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