Numerical Formats and Transformer Workloads
Turn a transformer diagram into concrete numeric formats, tensor shapes, operations, and allocation lifetimes
Build a resource model for floating-point arithmetic, transformer layers, training state, and the distinct prefill and decode phases of autoregressive inference.
A transformer diagram can show a box labeled Attention and another box labeled Feed Forward. A running program must turn each box into concrete arrays and operations. For a batch of two prompts with 1,024 tokens each and a hidden width of 4,096 values, one activation array contains 2 × 1,024 × 4,096 numbers. At two bytes per number, that single array occupies about 16.8 megabytes. Graphics processing unit (GPU) programs read the array, use general matrix multiplication (GEMM) to multiply the array by learned weight matrices, create temporary arrays, and keep selected results for later work.
Chapter 3 names such a multidimensional numeric array a tensor only after specifying its axes, element format, physical storage order, producer, consumer, and lifetime. The chapter also shows where floating-point formats enter the real execution path: model weights can be stored in BF16, matrix hardware can multiply BF16 operands while accumulating partial sums in FP32, and the final tensor can be converted back to BF16. Every format choice changes both the representable numbers and the bytes that the machine moves.
The chapter then follows two complete workloads. A training step performs a forward calculation, preserves selected intermediate tensors, computes gradients in reverse order, and updates learned weights. An inference request first processes all prompt tokens, then repeatedly generates one new token while retaining attention history in a key-value (KV) cache. Explicit tensor shapes, counts expressed in floating-point operations (FLOP), and allocation lifetimes explain why the two workloads consume memory and arithmetic resources differently. Later examples name high-bandwidth memory (HBM) as the large off-chip memory attached to the GPU.
Prerequisites
- Chapter 1: work and units
- Linear algebra: vectors, matrices, matrix multiplication
- Basic neural-network forward and backward passes
Learning objectives
- Follow one value through storage, multiplication, accumulation, reduction, and output conversion
- Annotate a decoder layer with tensor shapes, producers, consumers, work, and bytes
- Estimate memory for the recurring inference request and eight-GPU training step from allocation lifetimes
Study this chapter
- 3.1Floating-point formats and numerical errorBegin lesson →
Predict and observe overflow, underflow, and rounding along a declared training or inference format path
- 3.2Transformer operations and tensor shapesBegin lesson →
Map one declared decoder layer from mathematical operations to profiler-visible GPU work and tensor allocations
- 3.3Training memory and communicationBegin lesson →
Build and validate a time-ordered ledger for parameters, gradients, optimizer state, saved activations, workspaces, and communication buffers
- 3.4Prefill and decode workloadsBegin lesson →
Explain with shapes, timelines, and cache bytes why prompt processing and one-token generation require separate performance models
Extended exercises
Complete these projects after the lesson-level practice tasks. Each project combines several mechanisms from the chapter.
Record one numerical format path
Trace stored operands, loaded operands, multiplication, accumulation, reduction, and output conversion through one general matrix multiplication and one row reduction.
Evidence: A dataflow diagram that names every format conversion, representable-range risk, and error-sensitive accumulation point.
Annotate one decoder layer
For the recurring 7-billion-parameter model at a declared prompt or decode shape, annotate tensor axes, floating-point-operation counts, minimum HBM bytes, producers, consumers, and lifetimes.
Evidence: A notebook or table whose shape products, byte calculations, and profiler-visible operation names can be independently checked.
Validate an allocation timeline
Estimate either one 1-billion-parameter training step on eight GPUs or the recurring inference request on one 80 GiB GPU. Compare the lifetime-based prediction with a framework memory snapshot.
Evidence: Separate parameter, optimizer, activation, workspace, communication, allocator-reservation, and key-value-cache terms plus the saved snapshot and explanation of the largest discrepancy.
Sources and further reading
The lesson explanations synthesize primary papers and official references. Follow the originals for proofs, exact APIs, architecture details, and version-sensitive behavior.