Repository navigation
feat(cloudtpu): 1-graph decode, native S4 + BF16 + pad8, and c=16 continuous batching - #27
Open
saariuslystoned wants to merge 9 commits into
Open
saariuslystoned wants to merge 9 commits into
saariuslystoned wants to merge 9 commits into
Conversation
…lti-layer KV donation
…pad8 MXU alignment
…ason diagnostics, and 1..512 default buckets
…ing KV caches invariant
…, and live v6e-8 notes
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.
Stacked on #25 (
feat/ggml-cloudtpu-decode-lift@161e8841) — do not merge until #18 -> #19 -> #25 land (left OPEN for review).Summary
Closes the pure-StableHLO acceleration and continuous-batching serving gaps in
ggml-cloudtpuwhile keepingLDD_LIBPYTHON=0,MAPS_LIBPYTHON=0, and zero external dependencies acrossv5e/v6e/tpu7x:Whole-Model 1-Graph Single-Token Decode (
5e214ed)SET_ROWS->FLASH_ATTN_EXTviews) eliminates per-layeralias_conflictgraph splits.Llama-3.1-8B& 28-layerQwen2.5-1.5Bdecode from65+PJRT calls/token down to1subgraph/eval (CLOUDTPU_FUSE_ATTN=1,CLOUDTPU_MAX_FUSE_OPS=4096) with full2 * n_layersKV buffer donation (kv_donation_skipped=0).Native StableHLO
S4Single-Read Matmul + TrueBF16Scales +pad8MXU Alignment (63a9c99,ea016d6,HEAD)CLOUDTPU_Q4_MODE=i4(default): PacksQ4_0(q - 8) andQ4_K(q - 8,m_s4 = m + 8*d) directly into 0.5 B/weightPJRT_Buffer_Type_S4(0.5 B/won HBM; host staging uses 1 B/elem low-nibble layout as required by XLABufferFromHostBufferbyte_strides=nullptr).(dot_b * d) + (xsum * m)lowering forB3*B2*M <= 32and in-loop dequant forM > 32, withGET_ROWS+MUL_MATcoexistence (S4/U4andU8->S4bitcast) andSHARD_N/SHARD_KSPMD support.BF16Q4_K/Q6_Kscales (CLOUDTPU_Q4K_BF16_SCALES=1default) eliminateF16->F32->BF16roundtrips and125 MiBf32lm_headtemporaries.CLOUDTPU_MM_PAD_M=8(default): Zero-padsM < 8 -> 8beforeQ4_*_I4&Q6_Kdot_generalsoM=1decode lowers to TPU(8,128)MXU instead of VPU.v6efixes: normalizedPJRT_Buffer_ToHostBufferS41-B/elem zero-extended nibbles (sign_extend_nibble) inpjrt_runtime.cpp, and defaultedCLOUDTPU_ASYNC_COLLECTIVES=0(opt-in1) inggml-cloudtpu.cppto avoid legacyAug 15 2025libtpu.soMegaChipbase=0compile errors onP=8.Continuous Batching Static Padded Buckets (
51ff7eb,6dad6e9,09fda45)CLOUDTPU_BATCH_BUCKETS=1,2,4,8,16,32,64,128,256,512: Dataflow token-axis analysis maps dynamicn_tokensonto static buckets (failing closed on ambiguity), pads non-KV token tables (mixed_embd) safely, uses-1sentinel scatter indices so padded tokens never corrupt live KV cache slots, handles partialGET_ROWS(N_out < T), and slices logical outputs[0..T)cleanly on readback.Verified Evidence
Local Host Mock (
test_cloudtpu_host, post-final-edit)./llama-cpp-cloudtpu/build.sh standalone: 1/1 Passed,CLOUDTPU_MOCK=1(1-chip & 8-chip SPMD)ALL PASSED (0 failures),MAPS_LIBPYTHON=0.100tracked files: PASSED.Live Colab
TPU v5e-1(libtpu.so,LDD_LIBPYTHON=0,MAPS_LIBPYTHON=0)test-backend-ops -b CLOUDTPU(09fda45/ea016d6/8da23c2):MUL_MAT(1,361/1,361),MUL_MATq4_K|q6_K|q4_0|q8_0n=1|16(57/57),ROPE(287/287),CPY(157/157),ADD(153/153),MUL(140/140),SOFT_MAX(107/107),CONT(89/89),SET_ROWS(65/65),RMS_NORM(61/61),GET_ROWS(56/56),SCALE(12/12),UNARY/GLUPASS, targetedFLASH_ATTN_EXT(hsk=128,kv=512,nb=1,type_K=f16,type_V=f16)1/1 OK.llama-bench -p 3,5,6,7,9,10,11 -n 0onQwen2.5-1.5B):cache_entries=3total across all7odd token lengths (bucketed=2each,kv_donation_skipped=0).llama-bench -ngl 99 -fa 1 -p 512 -n 64(single stream,subgraphs/eval = 1.0,kv_donation_skipped = 0):Qwen2.5-1.5B Q4_K_M:pp512 = 30,176.38(+38%vs M4C21,836.23),tg64 = 244.97 tok/s(+16.4% vs M4C210.47).Llama-3.1-8B Q4_K_M:pp512 = 7,021.04(vs M4C6,555.99),tg64 = 83.25 tok/s(84.15@MAX_FUSE_OPS=256, +17.2% vs M4C71.03;+20.6%over unpadded 1-graph69.03).llama-server -np 16 -cb -kvuw/LLAMA_KV_ROWS_DISABLE=1, coherent across all streams,kv_donation_skipped = 0):Llama-3.1-8B Q4_K_M:c=170.54wall /72.35decode ->c=4242.75wall /256.31decode (3.54x) ->c=8473.52decode (6.54x) ->c=16756.55wall /787.79decode tok/s (10.9xscaling overc=1) (evals=418, subgraphs=418, bucketed=83).Qwen2.5-1.5B Q4_K_M:c=1196.32wall /203.76decode ->c=161,331.86decode tok/s (evals=342, subgraphs=342, bucketed=14).Live GCP
v6e-8Silicon (TPU v6 liteAug 15 2025libtpu.so,LDD_LIBPYTHON=0,MAPS_LIBPYTHON=0)test_cloudtpu_host(CLOUDTPU_MOCK=0):ALL PASSED (0 failures)on livev6e-8(includingS4H2D/D2H, 1/4/8-chip collectives,BF16scales,pad8, 1-graph KV donation, and continuous-batching buckets).test-backend-ops -b CLOUDTPU(CLOUDTPU_SPMD_CHIPS=8):SET_ROWS&RMS_NORMpassed; quantizedMUL_MAT(q4_K|q6_K|q4_0|q8_0) passed381/381;GET_ROWS(CLOUDTPU_SPMD_CHIPS=1 CLOUDTPU_Q4K_BF16_SCALES=0,q4_K|q6_K|q4_0) passed15/15.v6e-1(CLOUDTPU_SPMD_CHIPS=1 -sm none -mg 0):Qwen2.5-1.5B Q4_K_Mpp512 = 16,262.01/tg64 = 73.92(+35.6%tg64vs M4A54.52);Llama-3.1-8B Q4_K_Mpp512 = 7,557.94/tg64 = 52.98, coherent16/16viallama-server -np 16 -cb -kvu(50.00decode atc=1,20.30decode atc=16,MAPS_LIBPYTHON=0).v6e-8(CLOUDTPU_ASYNC_COLLECTIVES=0): ConfirmedCLOUDTPU_ASYNC_COLLECTIVES=0avoids the legacylibtpu.soMegaChip base=0compile failure (Qwen2.5-1.5B-p 4 -n 4:pp4 = 61.25/tg4 = 28.79,2.54xtg4vsFUSE_ATTN=0). Note: Ubuntu 22.04 TPU images ship Python 3.10, causingpip install libtputo pull legacy 2025libtpu.soinstead oflibtpu >= 0.0.53(cp312); fullQwen3-32B&Llama-3.3-70BP=8re-benchmarking againstlibtpu >= 0.0.53(withbuild.sh overlayand-sm nonenotes documented inREADME.md) remains ready to run on demand.