Sixth phase of Arc 4. Deep learning from tensors up.

Phase 35 showed classical ML wins on tabular. This phase teaches deep learning for the cases where it wins: unstructured data (text, images, audio), large datasets, when the patterns are too rich for hand-engineered features. PyTorch is the canonical framework in 2026. By phase end you’ve trained MLPs, CNNs, and a basic attention model from scratch, understanding the math + the code at each step.

This phase is the substrate every Arc 5 LLM/agent phase builds on. LLMs are transformers, transformers are attention, attention is matrix math on tensors. Master tensors here; the rest of Arc 5 reads naturally.


Prerequisites

  • Phase 35 complete; classical ML fluency
  • GPU available (local NVIDIA or cloud burst); Apple Silicon MPS works for small models
  • You accept: deep learning is just calculus and linear algebra with good engineering. Most of the work is data + plumbing.

Why this phase exists

You can’t operate a Arc 5 LLM gateway without understanding what an LLM is computing. You can’t reason about distributed training without understanding the training loop. You can’t tune fine-tuning without understanding the loss + optimizer + autograd. This phase installs the foundations so Arc 5 is engineering, not magic.


The pattern-first frame

Same eight steps.


1. PROBLEM

You have unstructured data (text, images, audio) or structured data with rich nonlinear patterns. Classical ML doesn’t capture the relevant structure. You want a model that learns hierarchical representations from data: that’s deep learning.

PyTorch is the canonical framework. TensorFlow + JAX are the alternatives. Hugging Face Transformers is the standard library for transformer models.


2. PRINCIPLES

2.1 Tensors and autograd

A tensor is a multi-dimensional array with gradients. PyTorch’s autograd tracks operations and computes gradients via reverse-mode automatic differentiation.

→ Pattern: autograd

Investigate:

2.2 Gradient descent + backpropagation

Gradient descent: move weights in the negative-gradient direction to reduce loss. Backpropagation: efficient gradient computation via the chain rule.

→ Pattern: gradient-descent, backpropagation

Investigate:

2.3 NN modules + the training loop

PyTorch’s nn.Module is the abstraction. A training loop is: forward → loss → backward → optimizer.step → repeat.

Investigate:

2.4 Optimizers and learning rate schedules

SGD, momentum, Adam, AdamW. Each has a use case. Learning rate schedules (cosine, linear, constant) shape the trajectory.

Investigate:

2.5 Common architectures: MLP, CNN, attention

→ Pattern: attention-mechanism: first OUTLINE (Arc 5 deepens)

Investigate:

2.6 Overfitting, regularization, the validation curve

Same patterns as classical ML, plus DL-specific ones: dropout, weight decay, data augmentation, early stopping.

Investigate:


3. TRADE-OFFS

DecisionOptionsCost
FrameworkPyTorch; TensorFlow; JAXPyTorch: research + production standard. TF: enterprise legacy. JAX: research-leaning, fast.
Architecture for tabularXGBoost (Phase 35); MLPXGBoost usually wins; MLP only competitive with very large data + careful regularization.
Architecture for sequencesLSTM/GRU; TransformerLSTM: simpler, weaker. Transformer: better, more compute.
OptimizerSGD + momentum; AdamWSGD: classical, careful tuning. AdamW: modern default.

4. TOOLS (as of 2026-06)

Reading


5. MASTERY: Three models end-to-end

Build three models from scratch (no high-level wrappers; PyTorch + numpy only for the first two):

5.1 MLP for a tabular task

Same data as Phase 35. Train an MLP. Compare to XGBoost. Reflect.

5.2 CNN for an image task

MNIST or CIFAR-10 (or your own image dataset). Train a small CNN. Reach > 90% on MNIST.

5.3 Basic attention model

Implement a minimal self-attention layer + train a tiny transformer (~10M params or fewer) on a small text task. This is Karpathy-style “build GPT from scratch.”

5.4 Operational depth checklist

[ ] PyTorch installed; GPU detected (or MPS for Apple Silicon)
[ ] MLP trained on tabular data; compared to XGBoost
[ ] CNN trained on MNIST/CIFAR; reached >90% on MNIST
[ ] Attention layer implemented from scratch
[ ] Tiny transformer trained on a text task
[ ] Profiled training: GPU util, memory, throughput
[ ] Used a learning rate scheduler; observed the loss curve
[ ] Applied dropout + weight decay; observed regularization effect
[ ] Saved + loaded model checkpoints
[ ] Used Hugging Face Transformers to load a pretrained model; observe vs your from-scratch impl

6. COMPARE: JAX or Hugging Face

Pick one:

400-word reflection.


7. OPERATE


8. CONTRIBUTE


What ships from this phase


Validation criteria

[ ] MLP, CNN, tiny transformer all trained from scratch
[ ] Attention layer implemented from scratch
[ ] Compared to pretrained via HF
[ ] All 10 operational depth checks
[ ] Compare reflection (400 words)
[ ] 2-3 DL runbooks
[ ] 1-2 ADRs
[ ] Pattern entries:
    - autograd → OUTLINE
    - gradient-descent → OUTLINE
    - backpropagation → OUTLINE
    - attention-mechanism → OUTLINE (Arc 5 deepens)
[ ] Exit Test passed

Exit Test

Time: 3 hours.

Part 1: Build (120 min)

Implement a tiny transformer from scratch (≤ 50 lines of PyTorch). Train it on a small text task. Get loss to converge.

Part 2: Diagnose (45 min)

A training scenario (loss is NaN; model isn’t learning; GPU OOM). Possible causes for each.

Part 3: Articulate (15 min)

~400 words: “Walk a single backprop step through a 2-layer MLP. Cover forward pass, loss computation, gradient computation per layer, weight update.”


Anti-patterns

Anti-patternWhy
Forgetting optimizer.zero_grad()Gradients accumulate; training breaks silently
Using .train()/.eval() interchangeablyBatchNorm + Dropout behave differently; results lie
Loading data without num_workers > 0GPU idle waiting on data
Not profiling trainingYou optimize the wrong thing
Reaching for SOTA architectures before baselinesSometimes a strong baseline + good data beats a complex model

Patterns touched this phase


→ Next: Phase 37: Distributed Training (KubeRay)