1. The 16-Byte Rule of Mixed-Precision Full Fine-Tuning
Engineers transitioning from inference to post-training often assume a 70B BF16 model (~140 GB inference weights) can be fine-tuned on two 80GB GPUs. Under standard mixed-precision training with AdamW, each trainable parameter requires 16 bytes of static state before counting activations:
- Forward/Backward Weights (BF16):
2 bytes / parameter - Parameter Gradients (BF16):
2 bytes / parameter - FP32 Master Weights + AdamW 1st & 2nd Moments (`m_t`, `v_t`):
4 + 4 + 4 = 12 bytes / parameter
For a 70.6B model, static training state alone totals 70.6 × 16 ≈ 1,130 GB. DeepSpeed ZeRO-3 (and PyTorch FSDP `FULL_SHARD`) partitions all three pools across N data-parallel GPUs, reducing per-GPU static memory to 16·P / N while gathering layer parameters on-the-fly over NVLink during forward and backward passes.
2. How QLoRA Compresses 70B SFT onto a Single 48GB GPU
QLoRA decouples frozen base representations from low-rank task updates:
- 4-Bit NormalFloat (`NF4`) + Double Quantization: Compresses frozen base weights to
~0.55 bytes / parameter(~39 GB for 70B). - Low-Rank Adapter Budget: Attaching rank-
radapters across all 7 linear projections (`q, k, v, o, gate, up, down`) introducesP_lora = L × 7 × 2 × d_model × rtrainable parameters—under1%of base parameters atr = 32. - Gradient Checkpointing + FlashAttention-2: Recomputes intra-layer activations during backpropagation instead of storing full attention matrices, cutting activation memory by ~70% at a modest ~25%–28% FLOPs overhead.
3. Multi-Turn Agent Loops & Quadratic Token Snowballing
Stateless LLM APIs require an autonomous agent to re-transmit its accumulated message history on every tool-execution turn. Given static system + MCP schema tokens S and per-step growth Δ = T_obs + T_out across K steps, cumulative input tokens equal:
Cumulative_Input(K) = K * S + Δ * K * (K - 1) / 2
At K = 20 turns with S = 3,000 and Δ = 1,500, a single agent run bills 345,000 input tokens—nearly 10× the raw text generated during the session. Three architectural practices tame this curve:
- Strict Prefix Determinism: Keep system instructions and tool definitions byte-identical at index 0 (never inject dynamic `Date.now()` timestamps into the system prompt) so automatic prompt caching discounts
75%–90%of repeated turns. - Sub-Agent Context Isolation: Delegate noisy file searches, log parsing, or web scraping to ephemeral sub-agents that return compact structured summaries rather than polluting the parent trajectory.
- Bounded Rolling Compaction: Summarize older tool outputs once history crosses 8–10 turns. Benchmark your exact savings in the Multi-Turn Agent Token Snowball Simulator →.