Unit 6 of 11 · about 5 hours · explain, measure

Quantized dispatch, speculative verification and structured-decoding gaps

These three paths change what the engine executes every step. Each wins only inside its acceptance, error and schema regime.

You'll be able to

  • Explain quantized dispatch, speculative acceptance and structured-mask costs with their batch-shape effects.
  • Measure one quantized, one speculative and one guided path against exact-match and quality gates.
  • Name the batch shape or schema where each path stops paying.

Covers

Weight, activation and key-value quantized kernel dispatchSpeculative decoding verification cost and batch shapeStructured decoding masks, CPU interaction and kernel gaps
1

Read

In this order, only the parts listed

0 of 3 done

  1. Quantization, dequant fusion and constrained decodingAI Systems Performance Engineering - Chapters 13, 15 and 16

    Chapter 16, Quantization Approaches for Real-Time Inference: Reducing Precision from FP16 to FP8 and FP4; Weight-Only Quantization (GPTQ, AWQ); Fusing Quantization-Dequantization Steps into the Execution Graph; Chapter 15, Constrained Decoding Performance Implications

  2. Verification cost modelFast Inference from Transformers via Speculative Decoding

    Sections 2 to 3, draft-verify-accept loop, acceptance rule, resampling distribution and walltime-versus-operations analysis. The paper names the target and the draft distribution; this unit and LeetGPU 87 swap the letters, so its rule reads with the draft

  3. Mask reuse and weight-only quantization labsAI Systems Performance Engineering companion code - Chapters 12 to 16

    GuidedDecodingBenchmark (defined in guided_decoding_common.py) with reuse_gpu_mask=False in baseline_guided_decoding.py versus reuse_gpu_mask=True in optimized_guided_decoding.py; ch16/baseline_awq_gptq_smoothquant.py versus ch16/optimized_awq_gptq_smoothquant_awq.py

2

Focus on

  • Quantized dispatch changes scales, granularity and accumulation, not just storage. Per-token scales dequantize as ; verify error against task tolerance, not just kernel error.
  • Speculative verification accepts draft token with probability , where is the draft probability and the target probability. Rejection resamples from the normalized positive part of and ends that sequence's accepted run.
  • Structured decoding pays for masks and host interaction every step. A GPU-resident reused mask removes the per-step rebuild; measure its cost per schema, not as a constant.
Common mistakes · 3
  • Reading a high acceptance rate as a speedup. Verification adds a full batched forward; low acceptance wastes it.
  • Comparing quantized and dense paths by kernel time alone. Scale, granularity and accumulation change error; gate by task quality.
  • Treating structured decoding as free once correct. Mask builds and host round trips scale with schema complexity and batch width.
3

Try it yourself

Closed-book, before checking anything

Closed-book, verify the LeetGPU 87 worked example: draft [1, 2, 0] with the given draft and target probabilities and uniform samples [0.50, 0.70, 0.30, 0.90]. Accept position 0 (, ), reject position 1 (, ), resample token 3 from normalized [0.667, 0, 0, 0.333], and emit [1, 3, 0, 0].
4

Quiz yourself

Answer first, then mark it. Missed ones go to Review.

0 got · 0 missed

  1. 1.What does lossless speculative decoding guarantee?Answer

    It preserves the target distribution up to floating-point limits: accepted drafts follow it and resamples come from the adjusted difference. Greedy equality tests check the implementation, not the proof.

  2. 2.Why does speculative decoding depend on batch shape?Answer

    Batch width changes arithmetic intensity and memory traffic per step. Verification adds a batched target forward that pays only when acceptance is high enough at that width.

  3. 3.Where does guided-decoding overhead come from?Answer

    A per-step CPU mask rebuild plus host interaction. Reusing a GPU-resident mask removes the rebuild; the book reports that complex grammars or small batches can still cost double-digit percent.

5

Practice

  • LeetGPU 87 Speculative Decoding Verification

    Challenge 87 in challenges/medium/87_speculative_decoding_verification/challenge.py: implement solve and pass the accept-all, reject-first and mixed functional tests plus the B = 64, T = 8, V = 32768 performance test

    Run it on LeetGPU or locally against reference_impl from challenge.py as in the CUDA primitives section. Keep correctness tests beyond the hosted score.

  • LeetGPU 96 INT8 KV Cache Attention

    Challenge 96 in challenges/medium/96_int8_kv_cache_attention/challenge.py: implement solve with per-token dequantization and 1 / sqrt(head_dim) scaling; check the num_heads = 1, seq_len = 3, head_dim = 4 example giving [5.00, 6.00, 7.00, 8.00]

    Run it on LeetGPU or locally against reference_impl from challenge.py as in the CUDA primitives section. Test adversarial scales and sequence tails locally.

You're done when

You report measured acceptance length, quantized error and mask overhead on one batch shape plus the regime where each path loses.

Only when you can do this without notes.

Leads to

Notes

Resources · 3 for this unit, 11 more in the section

Also in this section

  • AI Performance Engineering - Inference EnginesWafer · reference

    A curated index. Use Section 4 only to find the introducing paper and implementation for the mechanism your measurement points to.

  • PagedAttention and vLLMvLLM Authors · required

    Study block-based key-value allocation, sharing and scheduling interaction. Trace logical token positions to physical blocks in one engine run and quantify fragmentation and memory-capacity effects.

  • SGLangSGLang Authors · support

    Read the runtime and RadixAttention design, then inspect the repository path for one kernel or prefix-reuse interaction. Use it as an alternative architecture in the integration defense.

  • LeetGPU - Inference Kernel SetAlphaGPU · required

    Choose three bottleneck-matched challenges from 74 GPT-2 Block, 83 Fused Residual Add RMS Norm, 84 SwiGLU MLP Block, 87 Speculative Decoding Verification, 93 Llama Transformer Block and 96 INT8 KV Cache Attention. Integrate one result locally rather than stopping at the hosted submission.

  • FlashInferFlashInfer Project · support

    Use the repository as the serving-kernel baseline and interface reference. Reconstruct workspace planning, layouts, dispatch and stream behavior for one selected operation before comparing your path.

  • GPU Microbenchmark and Kernel Suite - IntegrationRoadmap-Final · support

    Complete the real tensor or model-operation integration, dispatch and fallback requirements. Report compilation and invocation overhead, workload frequency, correctness or quality and the end-to-end no-benefit regime.

  • PyTorch 2.14 ProfilerPyTorch · reference

    Read the Overview example plus the API reference for torch.profiler.profile (activities, schedule, on_trace_ready, record_shapes, with_stack), torch.profiler.record_function and export_chrome_trace. Use it for exact profiler and NVTX-range call contracts missing from the book.

  • Orca (OSDI 2022)USENIX · support

    Read Sections 3 to 4 for iteration-level scheduling and selective batching, and Section 6 for the engine microbenchmark and end-to-end latency-throughput method. Use it as the continuous-batching mechanism behind the book summary.

  • Sarathi-ServearXiv · support

    Read Sections 3 to 4 for chunked-prefill stall-free batching and token-budget selection, and Section 5 for capacity and overhead method. Use it as the chunked-prefill mechanism behind the book summary.

  • vLLM Documentation - Automatic Prefix CachingvLLM Project · reference

    Read Automatic Prefix Caching (vLLM v0.31.0) for hash-based block reuse, full-block caching, reverse-order freeing and the multimodal hashing example. Use it for engine behavior the papers do not version.

  • Transformer Inference ArithmeticKipply · reference

    Read kv cache, capacity, latency calculations, batch sizes and flops counting for per-token KV bytes, weight-capacity arithmetic and memory-bound versus compute-bound latency floors. Use it to derive endpoint bounds before measuring.