Unit ID: DLPY-M01-U04 Estimated active time: 25-35 minutes
The parts of a PyTorch workflow
Before writing PyTorch code, map the parts.
| Part | Meaning |
|---|---|
| Tensor | The main data object used by PyTorch |
| Shape | The size of each tensor dimension |
| dtype | The data type, such as floating point or integer |
| Device | Where the tensor lives, such as CPU or GPU |
| Dataset | Object that knows how to return examples |
| DataLoader | Object that gives batches from a dataset |
| Module | A model or layer built with torch.nn |
| Loss | Number that measures prediction error |
| Optimizer | Method that updates parameters |
| state_dict | Dictionary of model or optimizer state |
You will learn these pieces one by one. Do not rush.
Package boundary
The first package plan is small:
- Python;
- NumPy;
- pandas;
- Matplotlib;
- scikit-learn; and
- PyTorch.
torchvision is added when image modules begin. Transformer tooling is added only when the transformer module needs it and download rules are approved.
Install rule
Use the current official PyTorch installation guide when installing. Do not copy old CUDA commands from a blog post.
For the course source, we record only the package plan and the CPU-first runtime notebook. Actual installation and execution are runtime QA steps.
Artifact boundary
A course notebook may save small artifacts such as:
- loss history;
- a small model
state_dict; - a chart image;
- an error-analysis table; or
- a model card draft.
It should not silently save:
- private data;
- large model weights;
- API keys;
- downloaded datasets without approval;
- personal learner work unless the learner chooses to keep it locally.
State dict habit
When saving PyTorch model weights for course exercises, prefer saving state_dict plus useful metadata. This is easier to inspect than saving an entire model object.
For early course work, the question is not:
> Can I save the biggest model?
The better question is:
> Can another person understand what I saved, why I saved it, and what it proves?
Mini practice
Look at the setup map and answer:
- Which part stores trainable weights?
- Which part sends examples in batches?
- Which part says whether data is on CPU or GPU?
- Which artifact should you prefer saving for a small course model?
Answers:
- A model or layer module stores trainable parameters.
- A DataLoader sends batches.
- The device says CPU or GPU.
- A
state_dictwith metadata.
