Skip to course content
Free PyTorch course

Advanced Deep Learning with PyTorch

Unit ID: DLPY-M01-U04 Estimated active time: 25-35 minutes

The parts of a PyTorch workflow

Before writing PyTorch code, map the parts.

PartMeaning
TensorThe main data object used by PyTorch
ShapeThe size of each tensor dimension
dtypeThe data type, such as floating point or integer
DeviceWhere the tensor lives, such as CPU or GPU
DatasetObject that knows how to return examples
DataLoaderObject that gives batches from a dataset
ModuleA model or layer built with torch.nn
LossNumber that measures prediction error
OptimizerMethod that updates parameters
state_dictDictionary of model or optimizer state

You will learn these pieces one by one. Do not rush.

Package boundary

The first package plan is small:

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:

It should not silently save:

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:

  1. Which part stores trainable weights?
  2. Which part sends examples in batches?
  3. Which part says whether data is on CPU or GPU?
  4. Which artifact should you prefer saving for a small course model?

Answers:

  1. A model or layer module stores trainable parameters.
  2. A DataLoader sends batches.
  3. The device says CPU or GPU.
  4. A state_dict with metadata.