Workflow
A full PyTorch model cycle — data, model, training, evaluation and saving — illustrated step by step on a regression problem.
Goal of the lesson
By the end of this 3-hour session you should be able to:
- recognize the five steps every PyTorch project follows,
- prepare data and split it into train and test,
- build a model by subclassing
nn.Module, - write a training loop with a loss, an optimizer and gradient descent,
- track and plot loss curves,
- save and reload a trained model,
- fit a noisy non-linear curve as a capstone.
This is the most important lesson of the series. Every chapter that follows reuses the same five-step skeleton — only the data and the model change.
Suggested timing
| Block | Topic |
|---|---|
| 20 min | What a workflow is, the 5 steps |
| 25 min | Generate and split the data |
| 30 min | Build a linear-regression model |
| 45 min | Train, track loss curves, evaluate |
| 20 min | Save and reload |
| 40 min | Capstone — fit a noisy sine wave |
The 5-step workflow
In machine learning, the model is a tiny part of the project. Most of your time will be on data and on training/diagnostics. The shape of the workflow stays remarkably constant: the same five steps for a 50-line linear regression and for a 500-million-parameter language model.
In this lesson we work on the smallest interesting problem — a linear regression that learns the line y = 0.7 x + 0.3 — so we can focus entirely on the workflow.
Setup
uv init --python 3.12 workflow
cd workflow
uv add torch matplotlibImports we will reuse:
=
1. Prepare data
Real ML starts with real data. Here we generate it ourselves so we know the answer in advance and can verify whether the model finds it.
= 0.7
= 0.3
= # shape [50, 1]
= * + # shape [50, 1]
Estàs llegint una vista prèvia.
Inicia sessió amb Google per llegir la pàgina completa.
Inicia sessió amb GoogleAmb qualsevol compte de Google. Només et demanarem que acceptis les condicions del servei.