Start studying
Module 17 · Research Level Module contents
Module 17  ·  Card 5 / 11intermediate

Implementing Architectures from Scratch

Building an architecture yourself exposes what reading it hides.

Write a minimal version first with no optimisations.

Test each component in isolation with tiny tensors of known shape.

Check your output against a reference implementation.

Attention, a small transformer and a CNN are the classic exercises.

Learn in depth ↓
Module 17 · Research Level · 11 concepts
In depth  /  15 lines

Implementing Architectures from Scratch, in more detail

Building an architecture yourself exposes everything reading it lets you skip.

You cannot hand-wave a tensor shape into existence.

Write the minimal version first, with no optimisations and no configuration.

Hard-code the sizes, since generality is what makes a first implementation unreadable.

Test each component in isolation with tiny tensors whose shapes you can check by hand.

Attention on a sequence of four tokens is verifiable on paper.

Print shapes at every step, since most bugs are a transposed or broadcast dimension.

Check against a reference implementation with the same weights and input.

Matching outputs to a few decimal places is the only real confirmation.

Overfit a single batch deliberately, since a correct model can memorise ten examples.

If it cannot, the bug is in the model rather than in the training setup.

Attention, a small transformer and a CNN are the classic exercises for good reason.

Each takes an afternoon and teaches more than a week of reading.

Then read a production implementation and see what the optimisations cost in clarity.

Keep the toy version, since it stays readable in a way the fast one never will.

Test yourself

One question on this card. Every option explains itself once you pick, right or wrong.

Question 1
What is the best way to verify a from-scratch implementation?
Research Level

11 concepts in this module, then a graded test with every answer explained.

Study this module →
↑↓ move↵ openesc close