Kimi K3 studies / 02

Memory: Kimi K3
on 512 GB200s

FP32 where training keeps its history. BF16 where the model computes. The hard part is understanding what is live at the same time.

2.780Tlogical parameters
512GB200 GPUs
184.31 GiBreported HBM per GPU
60.70 GiBaverage FP32 update-state tally

Default case: full Kimi K3, PP8 / CP1 / TP1 / DP-shard64 / EP64, DistMuon plus AdamW, one 4K row per microbatch, and 64 microbatches in one 1F1B schedule. This is a training memory study, not an inference KV-cache calculator.

First, name the copies

FP32 training does not mean FP32 GEMMs

In this recipe, the sharded resident parameter is the master weight. FSDP makes a BF16 compute view for forward and backward; the optimizer updates the FP32 resident shard. Do not count a separate, full-model BF16 master copy on every GPU.

Resident masterFP32Sharded parameter, updated by the optimizer
FSDP compute viewBF16Cast / gather the weights needed by compute
Gradient historyFP32Reduction and optimizer-visible gradient shards
Muon momentumFP32One persistent tensor, in the gradient's dtype
Object Dtype Lifetime / ownership
Resident / master parameter FP32 Storage shard; persists across updates
Forward/backward parameter view BF16 Unsharded over FSDP, but still local to PP and EP
Gradient reduction / accumulation policy FP32 Unreduced PP gradients can outlive one microbatch
Optimizer-visible param.grad FP32 Matches the FP32 resident parameter in this recipe
Muon momentum FP32 One tensor with the storage gradient's layout
AdamW first and second moments FP32 Two tensors for the small AdamW remainder
Model GEMMs / main activations BF16 Exceptions for selected pointwise arithmetic and statistics
The unavoidable bill

Muon needs one momentum, not two Adam moments

The first study counted 2,779,931,738,208 parameters. In this optimizer assignment, 2,777,072,664,576 use DistMuon and 2,859,073,632 use AdamW: about 99.897% versus 0.103%. Routed expert matrices alone are 97.94% of the model. Selecting 16 of 896 experts reduces compute per token, not the number of trainable weights or optimizer states we must store.

DistMuon parameter4 + 4 + 4 = 12 bytes

FP32 master + FP32 gradient + FP32 momentum

AdamW parameter4 + 4 + 4 + 4 = 16 bytes

FP32 master + gradient + two FP32 moments

Update-state tally = 12 P_muon + 16 P_adam
                   = 33,370,617,153,024 bytes
                   = 30.35 TiB across the logical model

Ideal 512-way average = 60.70 GiB / GPU

This tally assumes all trainable parameters have gradients and optimizer state. It is not a measured peak or an assertion that every gradient exists throughout forward. It excludes BF16 compute views, unsharded accumulation, activations, padding, communication, and optimizer workspaces. The familiar “16 or 17 bytes per parameter” shortcut is not a universal memory law.

256 GPUs121.40 GiB average update-state tally
512 GPUs60.70 GiB average update-state tally

Twice the GPUs halves evenly distributed resident state. It does not automatically halve a gathered compute unit, microbatch activations, or NCCL workspace.

Explore the ownership

A memory lab, with its assumptions exposed

Pick a pipeline rank. The state ledger uses the actual 93-layer structure, including the first dense FFN, last MLA layer, embeddings, vision pathway, and output head. You can inspect every projection and activation below, change what is saved, and follow its lifetime through a pipeline schedule. Structural state counts, selected tensor candidates, and chosen workspace allowances are kept distinct.

After reduction / optimizer-state tally63.23 GiB

Planning subtotal + chosen reserve

Backward planning budget

Full deferred gradients replace reduced shards in this phase; they are not added on top of an entire second gradient copy. Actual reduction can briefly overlap both and needs additional buffers. Lifecycle scenarios assume initialized optimizer state; forward assumes zero_grad(set_to_none=True). The first-ever forward, before momentum is initialized, has a different state bill.

Allocation category Modeled size What the number means
Follow the bytes through one layer

A tensor anatomy, not just bytes per parameter

Select a KDA, MLA, or first dense layer. Click a computation to inspect its outputs and the weight copies it owns. The diagram follows the forward dependencies; the saved-tensor checkboxes define a candidate accounting policy shared by matching operations in other layers. They do not claim to rewrite TorchTitan's checkpoint policy.

Selected saved storage Recomputed / transient View: no new storage. Dashed wires carry gates, routing metadata, or shared outputs past intervening compute.

Box values sum unique allocations assigned to that operation, not a cumulative memory peak. Use the inspector for alias and lifetime details.

Every named activation and view in this layer

A checked row is charged once to its backing allocation. Changing a checkbox enters custom mode. Backend save/recompute decisions, padding, and uncatalogued workspaces can differ from these candidates.

Save? Tensor / operation Logical shape → local dimensions Dtype New storage Ownership / lifetime note
Every trainable parameter group and its copies

Logical parameter counts are global. Sizes are per GPU: PP selects layers, EP selects routed experts, FSDP shards resident history. BF16 views are unsharded over FSDP but still EP-local. AdamW has two moments; Muon has one.

Parameter group Weight shape Logical parameters FP32 master FP32 optimizer FP32 gradient BF16 compute view
The allocations a state formula misses

Four temporary-memory stories

These worked sizes follow the current local token shape. They are separate examples, not four extra bars added to the budget: exact concurrency, buffer reuse, fusion, and kernel versions must be measured.

KDA: training is not inference

Token chunks carry matrix state

One FP32 state-equivalent per 64-token chunk scales as ceil(T / 64) × H × K × K × 4. Kernels can save or regenerate multiple intermediates; this is a worked layout, not an assertion about every KDA backend.

Attention residuals

References versus materialized stacks

Keeping a list does not erase the underlying residual vectors. It can avoid a second [T, N, D] stacked copy. A fused reduction can also avoid full FP32 expansion. Local boundary aliases are deduplicated in the saved-bank tally; cross-chunk transport/cache copies are not modeled.

SiTU-GLU recomputation

FP32 casts cover routed rows

Gate and up each span [R, F], where balanced R = 16T. In eager mode, casts and pointwise results occupy HBM. Compiling/fusing this region can keep some values in registers or eliminate buffers; it does not reduce master weights or optimizer states.

Muon Newton–Schulz

Small matrices, batched working sets

A routed logical matrix is [F, Z] = [3072, 3584]; the Gram side is 3072, not the fused gate/up storage's 6144. FP32 momentum is already in the state tally. BF16 iteration copies, old/new iterates, Gram polynomials, redistribution, and NCCL buffers are optimizer-phase costs.

PP, EP, and FSDP divide different things

PP8

Own a model slice

Ranks 0–6 own 12 layers each; rank 7 owns the remaining nine. Embeddings and vision sit at the front, the output head at the back. Pipeline stages are not perfectly balanced, so a model-wide average hides the worst rank.

EP64

Own 14 experts per MoE layer

896 / 64 = 14. The 64 ranks exchange tokens, rather than all 512 ranks participating in one EP group. Dense attention and shared-expert weights are not divided by EP.

FSDP64 / expert FSDP1

Shard the resident history

512 / PP8 = 64 ranks per pipeline stage. Dense master/gradient/state shards span those 64 ranks. EP already divides the expert bank by 64, leaving expert FSDP = 64 / 64 = 1: no further expert-storage division.

On one pipeline stage, let D = non-routed parameters and E = routed parameters.

Resident parameters / GPU = D / dense_FSDP + E / (EP * expert_FSDP)
BF16 gathered stage view  = 2 * (D + E / EP) bytes

At PP8 / EP64 / FSDP64: expert_FSDP = 1

Increasing EP at fixed PP and GPU count can shrink the expert compute slice while reducing the expert FSDP degree. It does not create additional aggregate HBM. And the 512 GPUs do not form one pooled allocation space: every rank must stay within its own device capacity.

Context parallelism changes the local token axis, not the global context. With CP16, one 64K row gives 4K local tokens; dense FSDP still spans DP × CP = 64 ranks in the default 512-GPU / PP8 layout. MLA's head-sharded Ulysses exchange turns [4096, 96, channels] into [65536, 6, channels], preserving this tensor's element count while attending across the full 64K sequence. Attention work and communication still change. A KV-all-gather CP backend has a different working set and is not modeled here; an unchanged local tensor subtotal alone does not prove a long-context configuration will fit.

Memory follows lifetime, not global batch

64 microbatches do not mean 64 saved forwards

In ordinary 1F1B, a rank fills its local pipeline, then alternates forward and backward. Backward releases that microbatch's saved activations. With eight physical stages and enough microbatches, rank 0 can hold eight unfinished forwards; rank 7 needs only one. This is a logical schedule bound, excluding implementation-specific send/receive buffers and keepalives.

Peak saved-tensor candidates by PP rank

Ordinary 1F1B: peak unfinished forwards on rank r = min(microbatches, PP - r)

Selected rank: forward-to-backward lifetimes

The horizontal axis is local logical action order, not elapsed time. F adds a saved activation set; B releases it at completion. Spans show the first few microbatches of each chunk. The live-storage curve covers the entire schedule. Click a span or use the slider to inspect it. No communication overlap or speedup is inferred from this diagram.

Compare ordinary and interleaved lifetimes

Same hardware, PP/CP/EP, row shape, microbatch count, and saved-tensor policy. These comparisons show backward scenarios with one gathered chunk. Virtual splitting changes the layer mix on a physical rank; aggregate resident state is conserved. They are memory-accounting alternatives, not speed predictions.

Schedule / VP Local chunks / layers Max unfinished chunk forwards One BF16 gathered chunk Scheduled saved candidates FP32 update-state tally

At the default shape, local packed tokens T = rows × context = 4096. One BF16 [T, 7168] stream is 56 MiB. Twelve checkpointed layer inputs across five unfinished forwards on rank 3 give a boundary-input floor of 3.28 GiB. The expanded lab counts incoming residual-bank candidates separately, then allows for an active layer's recomputation and a chosen workspace budget.

Global tokens per update are DP × microbatches × rows × context: 64 × 64 × 1 × 4096 = 16,777,216. Increasing microbatches beyond the 1F1B live-forward bound mostly extends the schedule; increasing rows or context increases each microbatch's activation and routing footprint. Two 2K rows and one 4K row have the same flattened token count, but different document attention boundaries.

KDA's fixed-size inference state does not make its training activations constant-size: token and chunk intermediates still need storage or recomputation. Varlen FlashAttention avoids materializing the full attention-probability matrix for MLA, but still needs Q/K/V, outputs, and backward statistics. Neither attention path has a zero activation-memory bill.

The whole-stage BF16 bar is a residency budget, not a count of all-gather calls. In the reference trace, an interior 12-layer stage made 780 dense parameter all-gathers over one update: 65 per layer. Also, ordinary 1F1B sends the hidden stream and the accumulated AttnRes block stack; a rank's residual cache helps later virtual stages, but cannot shrink that first visit's packet. Study 03 turns these lifetimes and shapes into a communication roofline.

An interactive fitting walkthrough

From a 30-TiB state bill to a local budget

Each step changes one ownership or activation assumption. The same FP32-master / FP32-state / BF16-compute policy is kept throughout. Component lengths below use a logarithmic axis; add the numeric values, not bar lengths.

1 MiB1 GiB64 GiB64 TiB

Model versus implementation

A measured run is the capacity proof

4K / 512-GPU reference146.18 GiBmaximum logged tensor allocation
Device capacity184.31 GiBreported by the training runtime
Arithmetic difference38.13 GiB20.69% — not guaranteed usable slack

The reference completed 12 updates with FP32 resident state, BF16 compute, PP8 / FSDP64 / EP64, full layer checkpointing, varlen attention, compiled pointwise regions, no CUDA graphs, and forced-balanced HybridEP routing. It demonstrates short-run feasibility of this specific configuration; it is not a general capacity guarantee or a convergence result. The fixed reference stays fixed when you change calculator controls.

The calculator deliberately does not label the gap between its subtotal and 146.18 GiB as “activation memory.” That would invent a decomposition. Some important reasons implementations exceed a state-only estimate:

Deferred PP gradients

Gradient accumulation can retain unreduced stage gradients until the schedule finishes. A reduced FP32 shard and an unreduced FP32 dense gradient differ by the FSDP factor. Repeated backward calls do not create 64 independent parameter-gradient histories.

Gather / reduction buffers

A casted input shard, all-gather output, compute view, and reduce-scatter input may briefly overlap. Retaining every in-flight buffer defeats an otherwise good memory budget. Resharding and bounded buffer lifetimes matter as much as dtype.

SiTU-GLU temporaries

Gate/up products cover routed assignments, not just original tokens. Eager FP32 pointwise intermediates occupy HBM. Compiling the pointwise region can fuse intermediates and shorten their lifetimes; it does not compress the FP32 master weights.

Muon working layouts

DistMuon redistributes shards into logical matrices before its update. The storage layout, compute layout, communication buffers, BF16 iteration copy, and Gram matrices have different lifetimes. Transient buffers avoid paying optimizer-only storage during model compute.

Memory outside PyTorch

NCCL can allocate workspace outside PyTorch's caching allocator. Unused cached blocks are not necessarily available to NCCL. Communicator initialization order and runtime connection policy can therefore change whether an otherwise identical run starts.

Graphs and precision shortcuts

CUDA graphs can retain private pools and captured buffers. BF16 reduction alone does not shrink FP32 master, optimizer-visible gradient, or momentum shards. Neither graph capture nor lower reduction precision is a free state-memory reduction.

Tensor allocation, allocator reservation, and total device usage are different measurements. The reported 38.13-GiB difference ignores external allocations and fragmentation. Check every PP rank and the first optimizer update, not only the first forward. Also check later iterations, when momentum and caches are populated.

Sources and accounting notes

  1. Kimi K3 technical report and released configuration: architecture and logical dimensions.
  2. TorchTitan Kimi K3 and DistMuon: parameter shapes, momentum storage, and Newton–Schulz computation. Optimizer assignments and lifecycle settings refer to the recipe analyzed here, not every upstream recipe.
  3. PyTorch FSDP and pipeline parallelism: mixed precision, sharded storage, and schedule concepts.
  4. Presentation inspired by Edward Yang's Hopper memory study. This page uses Kimi K3, GB200, Muon, and the stated FSDP/PP policy; it does not transplant DeepSeek's AdamW or DualPipe assumptions.

GiB = 230 bytes; TiB = 240 bytes. Structural totals match study 01. Shards are modeled by ideal division, ignoring per-tensor padding. VP1 uses the reference contiguous ceil(93 / PP) split; VP2/VP4 use PyTorch's automatic split with embedding/head weights of one and cyclic chunk-to-rank assignment. Non-default settings are accounting scenarios, not validated launch recipes. AttnRes uses the current TorchTitan interval of 12 decoder layers by default; the alternative interval is explicit. The selected-activation model omits kernel-specific state and may include candidates an implementation aliases or recomputes. No internal run links, data paths, or cluster identifiers are included.