Contents
You can build an engine from bolts and steel stock. For a trip you need a car: gearbox, dashboard, a place for luggage. At the core, a neural net is matrices, activations, error, gradients, and weight updates. Writing that in plain Python is assembling the motor on a workbench by hand — every layer, every device, every checkpoint you save. An ML framework is the car for the cycle “data → prediction → error → gradient → new weights”: tensors, automatic gradients, CPU/GPU placement, the training loop, and serialization.
Below: what sits under the hood, how PyTorch, TensorFlow/Keras, JAX, tinygrad, and micrograd differ, where building the car ends and driving begins (including ONNX and browser WebGPU), and which path makes sense for a beginner.
Key takeaways
A framework is the car, not “the neural net”. The model is math and weights; the stack gives you tensors, a graph, gradients, and devices.
micrograd takes the engine apart on a workbench. tinygrad shows a stripped-down chassis with minimal panels. PyTorch is the practical road car for deep learning.
Building ≠ driving. Training needs backward and an optimizer; inference is load weights and get an answer. Often training stays in PyTorch, inference moves to ONNX Runtime or the browser.
Choice depends on task and hardware. CV and OCR — usually PyTorch; TPU — JAX/TensorFlow; Apple Silicon — also MLX; learning internals — tinygrad/micrograd.
Ecosystems sit on top of the core. Ultralytics, Hugging Face Transformers, timm — not replacements for the car, but body kits and add-ons.
You can build an engine from bolts — a trip needs a car
Without a stack you hand-roll matrix multiplies, storing activations for the backward pass, weight updates, batch loading, and checkpointing. That is the workbench with bolts: it works, but every step is manual. With a framework the picture changes: tensor on device, layer, optimizer, dataloader — pedals and gauges you already know how to use.
A framework is not “the neural net”. It removes the routine so you can think about the model and the data, not about how to stash activations in memory before the next backward pass.
Under the hood: tensor, graph, and autograd
In a road car you watch the dashboard while the parts that make the trip possible spin under the hood. An ML framework has the same layout: a clear API on top; underneath, an array with a device, a record of operations, and automatic derivative calculation.
Typical architecture:
ML Framework
│
┌─────────────┼─────────────┐
↓ ↓ ↓
Tensor Autograd Models
│ │ │
↓ ↓ ↓
CPU / GPU Gradients Layers
│ │ │
└─────────────┼─────────────┘
↓
Optimizer → Training
Tensor — a multidimensional array with dtype, shape, and device. An image is often [C, H, W]; a batch is [B, C, H, W]. Neural nets live on tensors because almost every operation is bulk linear algebra. Computational graph — a record of which operations produced a tensor (for the backward pass). Automatic differentiation (autograd) — automatic gradient computation along that graph.
On top come the familiar body parts: loss function, optimizer (SGD, Adam, …), layers (Linear, Conv2d), a model as a composition of layers, Dataset/DataLoader, device abstraction (cpu / cuda / …), weight serialization. The training loop is the route the car drives again and again:
data → model → prediction → loss → backpropagation → gradients → optimizer → new weights
On the workbench and on a bare chassis: micrograd and tinygrad
Before you sit in a road car, it helps once to take the engine apart on a workbench and once to roll on a stripped chassis without extra panels. That is how you see what turns under the hood, not only which buttons to press.
micrograd (Andrej Karpathy’s idea) — a tiny scalar autograd implementation. The goal is clarity, not speed: each node holds a value and a local gradient; backward walks edges in reverse. After that section you see autograd is not magic — it is a careful graph traversal. tinygrad — a small framework with its own minimalist, transparent-stack philosophy (not “PyTorch lite”). Useful when you want to see how an op reaches the accelerator without miles of industrial abstraction. You rarely pick it first for production CV; for learning how the ML stack is built — yes.
On fingers. A node stores a value and a local contribution to the derivative. If c = a * b, then on the backward pass the contribution to a is proportional to b, and to b proportional to a. The chain a → b → c is successive applications of the chain rule. That is what loss.backward() does in a large stack — on tensors, with memory optimizations.
PyTorch — the road car for most routes
PyTorch became the de facto standard for deep learning in research and much of applied CV/LLM work. This is not a training mock-up: behind the wheel you get torch.Tensor, torch.nn, torch.optim, Dataset/DataLoader, autograd, CUDA, saving (state_dict, .pt) — a full kit for everyday trips.
Minimal loop:
for x, y in dataloader:
optimizer.zero_grad()
prediction = model(x)
loss = criterion(prediction, y)
loss.backward()
optimizer.step()
zero_grad clears old gradients; forward computes the prediction; criterion is the error; backward fills .grad; step updates weights. One line loss.backward() on the outside — inside: graph traversal, derivatives, memory, and kernel launches on the chosen device. You already saw that chain on the micrograd workbench; here it sits behind the dashboard.
For OCR, CRNN, the YOLO ecosystem, and most vision pilots, PyTorch is a sensible start. Weights often move to ONNX for server or browser deployment next. Saving a model is a separate skill. Usually you save a state_dict (weights), not the whole Python object: easier to version model code and load a checkpoint on another machine. .pt / .pth is a torch ecosystem convention, not a universal “any neural net” format.
TensorFlow, Keras, and JAX — different roads, different cars
Not every route follows the same highway. Somewhere serving infrastructure is already paved; somewhere you need a different driving style; somewhere the road runs through Google cloud accelerators.
TensorFlow was long the main industrial stack. Today it matters together with Keras, tf.data, model serving, and places where TF infrastructure is already in place. TensorFlow 2.x emphasized eager execution — closer to familiar imperative style. Keras — high-level model API. Historically it merged with TF as tf.keras; Keras also evolves as a convenient layer over different backends. Simplified:
Keras → high-level model API
TensorFlow → compute and ecosystem (often as backend)
JAX — a different angle: “NumPy + differentiation + JIT + accelerators” in a functional style. jax.numpy, grad, jit, vmap — transformations of functions, not a stateful nn.Module object like classic PyTorch API. Strong in research and on TPU; steeper entry if you come from object-oriented nn.Module. A simple JAX mental model: write the loss as a pure function of parameters and a batch, then grad(loss_fn) yields the gradient, jit speeds things via compilation, vmap vectorizes over the batch axis. Model state is usually explicit arrays/trees, not hidden buffers inside a layer object. Great for research and unusual transforms; it asks for discipline if you are used to “a layer with .parameters() inside”.
Next to the car — body kits, parts, and a separate motor for the trip
On the same shelf as frameworks sit ready-made bodies and motors meant only for driving. They are easy to confuse with the training car itself.
Brief periphery: MXNet — historically important, less common now; PaddlePaddle — its own ecosystem; OneFlow — niche scenarios; MLX — interesting on Apple Silicon (unified memory, Apple GPU). ONNX Runtime — primarily an inference engine, not a full training framework in the PyTorch sense:
Training (PyTorch / TF / …) → ONNX → ONNX Runtime → Inference
Separately: training framework ≠ library of ready-made models.
PyTorch → tool to build and train
Ultralytics YOLO → ready detection pipeline on top of the ecosystem
HF Transformers → models and pipelines on top of frameworks
timm / Diffusers → model zoos and utilities
Confusing “we’ll install YOLO” with “we picked a framework” is like confusing a ready body kit with the car. A common beginner mistake.
Which road — which car
The table below is not a “who is best” ranking — it matches the tool to the route. Task and hardware first, logo second.
| Task | What to consider |
|---|---|
| Understand backpropagation | micrograd |
| See how a framework is built | tinygrad |
| Computer Vision, CRNN, OCR | PyTorch |
| YOLO | ecosystem around PyTorch |
| LLM | PyTorch + Transformers |
| Research / nonstandard transforms | PyTorch / JAX |
| TPU | JAX / TensorFlow |
| Apple Silicon | PyTorch / MLX |
| Fast UI model prototype | PyTorch / Keras |
| Production inference | ONNX Runtime and other inference runtimes |
| Browser inference | ONNX → Web (Transformers.js / ORT Web + WebGPU) |
Which engine bay: CPU, GPU, and TPU
A car only moves when the engine bay matches the road. Device placement in a framework is the same kind of contract: not the name on the badge, but drivers, builds, and backend.
Framework → CPU | GPU (CUDA / Apple / …) | TPU
- CPU — always available; often enough for learning models and debugging.
- NVIDIA CUDA — the main accelerator for
PyTorch/TensorFlowin production and research. - Apple GPU — Metal /
MPSinPyTorch, plus interest inMLXon unified memory. - AMD — depends on the stack (ROCm and builds); check support for your framework version.
- TPU — a strength of
JAX/TensorFlowin Google cloud scenarios.
device = "cuda" is a contract with your environment, not a spell. Moving tensors and the model to a device (to(device)) must stay consistent — otherwise you get an error or a quiet speed loss.
Building the car and driving it are not the same job
Factory assembly and a city drive are different work. Training: forward, loss, backward, gradients, optimizer. Inference: load weights, feed data, get output — no training.
TRAINING: data → model → loss → backprop → weights
INFERENCE: data → model → result
From Python to GPU the path is longer than the dashboard suggests:
Python → Framework API → tensor ops → backend → CUDA/Metal/TPU runtime → hardware
A line like x @ weights can unfold into a huge amount of work on the GPU — so a “simple API” does not mean a “simple implementation”. The browser link is when a finished car is handed to another garage only for the trip:
PyTorch (training) → ONNX → Transformers.js / ORT Web + WebGPU (inference in the tab)
Client-side details — WebGPU + Transformers.js; export — ONNX: from PyTorch to Runtime.
A route map: comparison and a beginner path
Comparing road cars side by side beats slogan shopping. Below — where the start is friendly, where the vision ecosystem is strong, where TPU is the focus, and where a learning chassis belongs.
| Criterion | PyTorch | TF / Keras | JAX | tinygrad |
|---|---|---|---|---|
| Getting started | Very friendly | Keras easier “from zero” | Steeper curve | For the curious |
| Deep learning / CV | Excellent ecosystem | Strong where TF already lives | Research / TPU | Not the main pick |
| Research | Standard | Present | Strong | Educational |
| GPU | Mature CUDA path | Mature | Mature | Present — check status |
| TPU | Weaker focus | Yes | Yes | Not the focus |
| Learning internals | Complex codebase | Complex codebase | Its own style | Strong suit |
| Prod inference | Often via export | Own serving ecosystem | Own pipelines | Rarely the only stack |
Learning route — workbench and basics first, then the road car:
Python → NumPy → network basics → micrograd → PyTorch → CNN → CRNN → Transformers → LLM
Vision branch: PyTorch → YOLO / detection → OCR.
First trip: a mini-project on handwritten digits
Theory without a steering wheel fades fast. Take handwritten digits (MNIST or your own set) and walk the loop once by hand — from loading data to a separate inference script.
- Load data and build a
DataLoaderwith batches. - Define a small CNN (
Conv→ activation → pooling → linear layer). - Write the training loop:
zero_grad→ forward → loss →backward→step. - Measure accuracy on a held-out set.
- Save a
state_dictto.pt. - In a separate script, load weights and run inference with no training.
- Mentally map the same steps to
micrograd/tinygrad: where the graph is, where the gradient is, where API “magic” hides.
Hands-on digits on the site: CNN → TrOCR.
Common mistakes at the start
Most early surprises are not a “broken car” — they are confusion about what is the engine, what is the body, and what is only the trip.
- Treating
PyTorchas “the neural net”, not the framework. - Confusing the framework with a ready model zoo (YOLO/Transformers).
- Not understanding tensor shape and batch dimension.
- Copying
backward()without a mental picture of the graph. - Assuming GPU is mandatory for every learning exercise.
- Mixing up training and inference; expecting
.ptto be universal for any runtime. - Picking
deviceat random without checking drivers.
FAQ
Where to start if the goal is document OCR?
Python + PyTorch, a compact model on crops, then export to ONNX if needed. See also compact CRNN in practice.
Do I need TensorFlow if I already have PyTorch?
Not “for the checklist”. You need it if the team/infrastructure is already on TF or you have TF services in place. Otherwise one primary training stack is easier to maintain.
Is JAX better than PyTorch?
Not “better” — different style: pure functions, jit/vmap/grad, convenience on TPU. For a classic CV pipeline PyTorch’s ecosystem usually wins.
Can you train seriously in the browser on WebGPU?
Usually no for serious training; the browser stack is tuned for inference. Training belongs on a dev machine or server.
Where does a trained model go?
Save framework weights (.pt, etc.); for portable inference — ONNX; for the tab — ORT Web / Transformers.js.
Further reading
Conclusion
A neural net is a mathematical model. A framework is the car around tensors, gradients, and devices: you can build an engine from bolts, but a trip needs a dashboard and a body. micrograd and tinygrad teach you to take the motor apart and look at the chassis; PyTorch covers most applied routes; TensorFlow/Keras and JAX remain important branches for ecosystem and accelerators; inference often lives separately — in ONNX Runtime or even in the browser. Picking a tool answers “what road, what hardware, who maintains it”, not a hunt for a fashionable badge on the hood.
Concepts (tensor, grad) → Frameworks → Models (YOLO, CRNN, LLM)
↓
Training → GPU/TPU/CPU
↓
Inference → Server | Browser (WebGPU)



Comments