Muhammad Atashi
TRANSFORMER BACKWARD PASS — DEEP LEARNING MECHANICS · REVERSE-MODE AUTOGRAD · MEMORY CONTRACTSCase 08 of 11 · /work/transformer-backward-pass
Index08 / 11
SourcePublic repo
Work / Transformer Backward PassOpen releaseIsolated Evaluation HarnessPublic sourcePinned @ 7a451f1

Transformer Backward Pass

Every analytical gradient equation is only trustworthy once checked against autograd and finite differences.

CORE QUESTION — What exact gradients, cancellation bounds, and SRAM/HBM memory contracts govern modern Transformer backward passes?

OwnsVerifies Transformer VJP gradients and SRAM/HBM tiling contracts across Ch. 01–17StackPython · PyTorch · Autograd VJP · GQA / RoPE · Online Softmax · LoRA / MoEPublic referenceTensorScholar/transformer-backward-pass @ 7a451f1 · verification: python3 code/ch17/ch17_model_verify.py

Built alongside the technical volume The Transformer Backward Pass, code/tgd/ implements MHA/GQA, online softmax tiling, RoPE, RMSNorm, SwiGLU, LoRA, MoE routing, FP8/INT8/INT4 quantization, and AdamW — paired with standalone chapter scripts (ch01–ch17) verifying exact backward-pass identities and SRAM vs HBM memory contracts.

Maturity · Isolated Evaluation Harness — MIT reference code & chapters 1–17 verification harnesses validated against PyTorch autograd and central finite differences.

FIG. 2 — Reverse-mode & tiled memory verificationAutograd + finite-difference checks

CHAPTERS 01–17 VERIFICATION HARNESSES

Inspect mathematical derivations, memory contracts & dual numerical controls

NAIVE ATTENTION BACKWARD

Materializes full O(S²) attention matrix in HBM

Standard reverse-mode stores S×S attention probabilities in high-bandwidth memory between forward and backward passes, dominating activation footprint as context scales.

ch11_kernels_verify.py · HBM activation traffic grows quadratically

TILED ONLINE SOFTMAX (CH. 11)

Recomputes local tiles in SRAM via log-sum-exp statistics

Retains only per-row log-sum-exp accumulators, recomputing P_ij on-chip during backward GQA passes while verifying exact numerical match against full PyTorch autograd.

code/ch11/ch11_kernels_verify.py · Verified vs torch.autograd

Every analytical VJP equation is cross-checked against PyTorch autograd and central finite differences.
FIG. F — Architecture, operating pathStages in record order
  1. 01VJP Bridge

    Frobenius adjoints · Ch. 01–04

  2. 02Attention

    Multi-head masked VJP · Ch. 06

  3. 03Tiling

    Online softmax · SRAM/HBM · Ch. 11

  4. 04GQA & RoPE

    Group-sum backward · 2D rotation

  5. 05Adapters

    Quantization · LoRA · MoE top-k

  6. 06Synthesis

    91M GQA+RoPE+SwiGLU · Ch. 17

FIG. F — The operating path as recorded. Nodes are stages of the system, not claims about deployment.

Engineering decisions — ledger of 3, as recorded. The signal edge marks the rejected alternative in each row.

RefDecision — and whyTrade-off acceptedRejected alternative
ATest every analytical backward formula against dual controls Checking manual VJPs against both PyTorch autograd and central finite differences catches subtle broadcasting and mixed-precision scaling bugs.Verification harnesses run slower in FP64 finite-difference mode than standard FP16 training.Rely on analytical derivations in text without executable numerical checks.
BIsolate architectural variants inside code/tgd/ Comparing MHA, GQA, LoRA, and quantized linear layers against one shared canonical decoder makes byte and gradient deltas concrete.Refrains from external framework abstractions in favor of transparent explicit tensor code.Build chapter demos as disconnected one-off scripts with duplicated blocks.
CCheck vector diagrams cleanly via regenerate_figures.py Computational flow diagrams and Graphviz graphs should regenerate from the verified codebase rather than drifting manually.Requires Graphviz tool availability when regenerating SVGs.Maintain static unlinked illustrations separately from verification code.

Revision table — evidence provenance, verbatim from the record

RevEvidenceResultSemantics
AChapters 01–17 verification scripts
Numerical & memory-contract reference verification; focused on exact backward derivations rather than custom CUDA kernel occupancy.
17 chapter harnesses cross-checked against PyTorch autograd & central finite diffsREPRODUCIBLE Verified
BChapter 11 tiled attention & GQA kernels
Models algorithmic HBM byte contracts in Python/PyTorch; not a substitute for Nsight Compute silicon profiling.
Explicit SRAM vs HBM traffic modeling and online-softmax backward rescaling checkREPRODUCIBLE Verified
CChapter 17 full decoder integration
Reproducible via ch17_model_verify.py at the pinned commit; synthetic training step verification.
End-to-end 91M GQA + RoPE + SwiGLU decoder forward/backward verificationREPRODUCIBLE Verified

Schedule of capabilities — 8 entries, as recorded

  • Four-account memory & FLOP ledger (Ch. 01)
  • Multi-head masked-attention manual VJP (Ch. 06)
  • IEEE-754 cancellation bounds for FP16/BF16 (Ch. 10)
  • Online softmax tiling without O(S²) HBM materialization (Ch. 11)
  • Grouped-Query Attention group-sum adjoint proof (Ch. 12)
  • RoPE & NTK/linear context-scaling backward pass (Ch. 13)
  • Absmax & block-wise FP8/INT8/INT4 outlier handling (Ch. 14)
  • LoRA low-rank backward & MoE auxiliary balance gradients (Ch. 15–16)

Audience — ML Systems & Kernel Engineers · Research Engineers · Training Infrastructure Teams · AI Platform Architects

REF. — Class A public evidencepinned · reproducible
Artifacthttps://github.com/TensorScholar/transformer-backward-pass
Pinned commit7a451f1d07b4b9d148fcb382fb66f048cca89e49
Verificationpython3 code/ch17/ch17_model_verify.py
REF. — The pinned public artifact. Verification command as recorded; the boundary rows above still apply.

Measurement contract — what would make the preferred answer fail?

EVALUATION METHOD

Reverse-mode autograd derivations are verified only when manual VJPs, cancellation bounds, and tiled memory contracts match dual numerical controls.

Standalone PyTorch verification harnesses (Ch. 01–17) comparing analytical formulas against PyTorch autograd and central finite differences.

01

Autograd parity

manual VJP vs torch.autograd across Ch. 01–17
02

Finite-diff margin

central difference numerical check
03

Tiled softmax HBM

SRAM rescaling without O(S^2) writeout
04

GQA broadcast backward

group-sum gradient identity verified
05

Quant & adapter path

FP8/INT8/INT4 · LoRA · MoE routing gradients
06

Full 91M synthesis

end-to-end GQA + RoPE + SwiGLU decoder

NOTE 1 — OWNERSHIP.

Personal authored technical monograph & PyTorch verification suite

Published under MIT at github.com/TensorScholar/transformer-backward-pass. Executable verification harnesses for Chapters 1–17.

NOTE 2 — READING. Numbers on this page carry their boundary lines. Quoting a result without its boundary omits its scope.

Exclusions — Not a Triton or CUDA kernel compiler · Not a pre-trained foundational checkpoint release · Hardware occupancy requires silicon profiling outside Python

Quick navigation

Jump to System or Page

↑↓ select↵ openESC close