Nandai AI
Sign In

Prefill ALU vs. Decode Bandwidth on Qwen 4 35B-A3B: Why Q4_K_M Outpaces IQ4_XS on Large Prompts

Understanding Time-To-First-Token (TTFT) vs. tokens-per-second bottlenecks when ingesting 64K–256K codebases on Metal and CUDA.

Decode speed is bandwidth-bound (favoring UD-IQ4_XS at 2.95 GB/tok), whereas 128K prompt prefill is ALU-bound (favoring linear Q4_K_M bit-shifts).

~847 wordsTechArticle + HowTo + Speakable JSON-LDZero-Upload Client RAM
Execution Pipeline ArchitectureLocal Browser RAM & Apple Silicon
01Batch PrefillProcesses N prompt tokens ->ALU compute bound02Dequant SuperblockBitwise Q4_K_M nibbles vsIQ4_XS LUT gather03FlashAttention TileFuses QSA softmax inside GPUshared SRAM04Switch to DecodeDrops to batch=1 -> DRAMbandwidth bound
  1. Step 01 · Batch Prefill

    Processes N prompt tokens -> ALU compute bound. Prompt prefill (Time-To-First-Token) processes hundreds or thousands of tokens in parallel matrix multiplications, shifting the bottleneck from DRAM bandwidth to shader/Tensor ALU throughput.

  2. Step 02 · Dequant Superblock

    Bitwise Q4_K_M nibbles vs IQ4_XS LUT gather. Codebook quants like UD-IQ4_XS unpack weights through non-linear lookup tables stored in shared memory or constant caches, incurring bank-conflict and instruction overhead during prefill.

  3. Step 03 · FlashAttention Tile

    Fuses QSA softmax inside GPU shared SRAM. Linear K-quants like Q4_K_M unpack weights via pure bitwise shifts, masks, and affine FP16 scale/min FMA instructions—mapping cleanly onto Apple Metal SIMD lanes and NVIDIA DP4A/Tensor pipelines.

  4. Step 04 · Switch to Decode

    Drops to batch=1 -> DRAM bandwidth bound. On workloads constantly ingesting fresh 64K–256K files (RAG, PR diff reviews, document extraction), Q4_K_M shaves noticeable seconds off TTFT at just +1.00 GiB memory cost.

1. Two Distinct Physics Regimes: Prompt Ingestion vs. Token Emission

Benchmark charts often report only decode tokens per second while ignoring Time-To-First-Token (TTFT). Yet for local developer assistants reading 50,000 lines of source code or 80-page legal filings, TTFT dominates perceived responsiveness. The crucial systems insight is that prompt ingestion (prefill) and token emission (decode) live on opposite sides of the hardware roofline curve.

During prefill of P = 512 or P = 2,048 tokens per chunk, each loaded weight byte participates in 2 * P floating-point operations—pushing arithmetic intensity cleanly past the hardware ridge point into the compute-bound regime. Under compute saturation, memory controllers stay fed easily while GPU shader ALUs, register files, and shared memory bandwidth determine speed.

Once prefill finishes and token 1 emits, arithmetic intensity collapses back to ~2 FLOPs/byte (batch=1 decode), shifting the bottleneck immediately back to DRAM bandwidth. Optimizing end-to-end latency therefore requires examining both how tightly a quant packs weights in DRAM AND how cheaply the ALU unpacks those bits into FP16 registers during dense matmuls.

TTFT_total ≈ (Prefill_Tokens * Active_FLOPs_per_Token) / Sustained_Matmul_TFLOPS + QSA_Attention_Scan(N_ctx)
Decode_Time_per_Token ≈ Active_Weight_GB / Sustained_Memory_Bandwidth_GBps

2. Bitwise Nibble Masking (Q4_K_M) vs. Codebook Lookup Tables (UD-IQ4_XS)

Understanding why Q4_K_M feels noticeably snappier during massive prefill on Apple Metal and NVIDIA CUDA requires peeking inside the inner dequantization micro-kernel. UD-IQ4_XS compresses weights into 4-bit indices pointing into a non-linear 16-value (or paired 8-bit) codebook grid optimized for normal weight distributions. Every inner loop step must decode indices, read lookup entries (creating potential shared-memory bank conflicts across parallel threads), and scale results.

Q4_K_M avoids indirection completely. Superblocks of 256 weights store uniform 4-bit unsigned nibbles alongside packed 6-bit scale and min values. A Metal SIMD lane or CUDA warp extracts eight 4-bit values from one 32-bit word using fast bitwise AND/shift masks, converts them via integer-to-float or lookup-free bit manipulation tricks, and multiplies directly against the superblock scale inside hardware FMA units.

During decode, those extra ALU cycles inside UD-IQ4_XS remain hidden behind DRAM stalls, so UD-IQ4_XS wins thanks to reading 2.95 GB/tok instead of 3.15 GB/tok. During 128K prefill—where ALUs run at 100% duty cycle—Q4_K_M’s linear arithmetic saves billions of unpacking operations.

Micro-Kernel Instruction Behavior: Linear K-Quant vs. Codebook IQ
Kernel StageQ4_K_M (Linear Affine)UD-IQ4_XS (Non-Linear Codebook)
Weight Unpacking OpBitwise mask + shift + FMA scaleCodebook LUT read + sign decode
Shared Memory Bank RiskNone (pure register arithmetic)Possible LUT gather bank serialization
Mixed 6-bit Attention LayersQ6_K linear scales on v/down projectionsDynamic mixed precision per tensor
Decode vs Prefill WinnerWins Compute-Bound Prefill (TTFT)Wins Bandwidth-Bound Decode (tok/s)

3. FlashAttention-2 Tiling on Qwen 4’s 10 QSA Layers

Even though Qwen 4 restricts explicit quadratic attention to just 10 of its 40 layers, ingesting 128K–262K prompts still requires computing attention scores across 10 QSA layers. Without FlashAttention (-fa on), naive attention materializes massive intermediate N x N score matrices into DRAM—burning gigabytes of scratch memory and saturating memory controllers mid-prefill.

FlashAttention keeps Q, K, and V tiles resident inside high-speed on-chip SRAM (Apple Silicon threadgroup memory / NVIDIA shared memory), computing online softmax normalization incrementally without ever writing the full N x N matrix back to unified RAM or GDDR7. Paired with Qwen 4’s 30 linear O(N)-prefill Gated-DeltaNet blocks, FlashAttention keeps prefill memory flat and prefill latency predictable across 256K codebases.

4. Eliminating Repeated Prefill via KV Prefix Caching

The fastest prefill is the prefill you never recompute. In multi-turn coding agents, 85–95% of prompt tokens across consecutive tool invocations stay identical (system prompt, tool JSON schemas, core project files). Enabling server slot prefix caching keeps the computed GDN states and QSA KV blocks pinned in RAM.

Wait: watch one nuance specific to hybrid GDN + QSA models! Unlike pure attention transformers where truncating or restoring any arbitrary token prefix only requires slicing KV array indices, Gated-DeltaNet maintains an accumulated recurrent state S_t. Modern inference engines store periodic GDN state checkpoints alongside QSA slot prefixes so prompt reuse works cleanly whenever the shared prefix aligns to cached block boundaries.

Actionable Checklist
  • Always pass -fa on so QSA prefill tiles stay in SRAM rather than allocating N x N DRAM buffers.
  • Keep system instructions and large static file context at the TOP of the prompt to maximize KV cache hits.
  • Choose Q4_K_M on 32 GB RTX 5090 and 48–64 GB Macs when frequent fresh prefill dominates.
  • Choose UD-IQ4_XS when tight 36 GB capacity or maximum single-stream decode speed wins.

5. Why Qwen 4 35B-A3B Beats 27B–32B Dense Peers on Both TTFT and Decode

Compared against traditional dense 27B–32B checkpoints (which push every token through all 27B–32B parameters during both prefill and decode), Qwen 4 35B-A3B exercises only ~3B active computational weights per token across its MoE + GDN topology. That means prefill FLOPs drop by roughly 6x–9x per prompt token while active decode DRAM bytes drop from ~16–20 GB/tok down to 2.95–3.15 GB/tok.

As a result, even if UD-IQ4_XS trades slightly slower unpacking ALU cycles against Q4_K_M on huge prompts, BOTH variants process 128K repositories several times faster than dense 32B models on identical MacBook Pro or GeForce RTX hardware. Check /gguf/qwen4-35b-a3b-vs-qwen35-llama4-deepseek-local-sizing or run your exact prompt profile in /tools/gguf-vram-calculator.

Prefill Compute vs. Decode Bandwidth Physics: UD-IQ4_XS vs. Q4_K_M on Qwen 4 35B-A3B

Prefill Compute vs. Decode Bandwidth Physics: UD-IQ4_XS vs. Q4_K_M on Qwen 4 35B-A3B
Engineering DimensionUD-IQ4_XS (~4.35 bpw Codebook)Q4_K_M (~4.85 bpw Linear K-Quant)
35B MoE Static Residency20.40 GiB (saves 1.00 GiB)21.40 GiB (fits 32–64 GB cleanly)
Batch-1 Decode Active Traffic2.95 GB/tok (6.3% faster roofline)3.15 GB/tok (still >568 tok/s on 5090)
Unpacking Kernel OperationNon-linear 256-entry LUT table gatherPure bitwise shift/mask + affine FMA
64K–256K Prompt Prefill ALUHigher LUT register/bank pressureFaster Metal SIMD & CUDA tensor unpack
Sweet-Spot WorkloadLong single-session generation & tight 36 GB RAMFrequent fresh 64K–256K repo/doc ingestion

Connected Workflows & Technical References

Launch pre-configured interactive sandboxes or read paired Academy, Guide, and GGUF specifications.

Model Prefill & Decode TTFT →
FOUNDER_999_LOCK · 67% OFF ALL-IN-ONE PRO

Run Every Studio Unlimited at $9.99/mo (Web Cloud + 5 Apple Silicon Macs)

Consolidate $130+/mo of separate writing, PDF, citation, cutout, video, and 1-second charting subscriptions into one local-first workspace — backed by a 14-day refund window and 1-click cancel.

Publisher & Creator Partner Network
Embed Zero-Upload Tools & Earn 40% Recurring

Add our 1-line Shadow DOM widget to your blog or share your partner link for 40% monthly / 30% annual recurring revenue.

More in Local Apple Silicon AI, Zero-Upload Privacy & Post-Quantum Web Security (8 Sibling Playbooks)

All 84 Articles →
FAQ · DIRECT ANSWERS

Local Apple Silicon AI, Zero-Upload Privacy & Post-Quantum Web Security — FAQ

05 Questions
Why does Q4_K_M prefill faster than UD-IQ4_XS on large prompts?
Q4_K_M uses linear bitwise nibble shifts and affine scale FMAs that execute directly in Metal SIMD and CUDA pipelines, whereas UD-IQ4_XS performs non-linear lookup table gathers under compute-bound prefill.
Which variant wins batch-1 token generation speed (decode)?
UD-IQ4_XS reads 2.95 GB/tok compared to Q4_K_M’s 3.15 GB/tok, giving UD-IQ4_XS a ~6.3% theoretical bandwidth roofline edge during single-stream decode.
Why is -fa on (FlashAttention) critical during 128K prefill?
FlashAttention fuses QSA softmax tiling inside on-chip SRAM instead of writing quadratic N x N attention score matrices to DRAM, preventing scratch OOM spikes.
How does Qwen 4 35B-A3B compare to dense 27B–32B models on TTFT?
Because Qwen 4 activates only ~3B computational weights per token and uses 30 linear-scan GDN blocks, both prefill FLOPs and decode bytes drop ~6x versus dense 27B–32B peers.
Can prefix caching skip repeated system prompt prefill?
Yes. Placing static tool definitions and repository headers at the start of prompts lets inference slots reuse cached QSA KV and GDN state checkpoints cleanly.
Founder Pro $9.99/mo · 67% Off1-tap Stripe Checkout · Instant ?ref= Free Months · 40% Recurring Partner Payouts
1. Subscribe in 1 TapFOUNDER_999_LOCK

Unlock All 19 Pro Studios + Mac App

Lock $9.99/mo Founder Pro (reg. $29.99 — 67% off), $119/yr Web Annual (-34%), or $299/yr 5-Mac + Web Pro.

Redeem Code
2. Get 6 Months FreeZERO OTP

Mint Your ?ref= Link Instantly

Give friends 67% off ($9.99/mo). Every paid friend adds 30 days of Pro free to your account (up to 6 months).

Dashboard: /refer · Rules

3. Creator & Publisher Cash90-DAY COOKIE

Earn 40% Monthly · 30% Annual

Earn 40% recurring monthly until cancel + 30% annual & every renewal, or embed our free tools with data-ref.