liveBook · Manning

Weight tying

As explained in Build a Large Language Model (From Scratch)

A parameter-sharing technique that reuses the token embedding weights in the output layer to reduce the effective parameter count.

Weight tying reuses the token embedding weights in the output layer, so the model shares one large vocabulary-sized matrix instead of learning two separate ones. section 4.6

In the GPT pipeline, it sits at the input/output ends of the model: token embeddings build the hidden representation, and the output head maps back to vocabulary logits.

Implementation details to notice:

  • The shared matrix also lowers memory footprint and computational complexity. section 4.6

Parameter-count check

A model instance reports 163,009,536 parameters before tying, then 124,412,160 trainable parameters when the output head is excluded from the count.

The treatment explains the idea from the shape of the layers through the parameter-count effect, but stops short of implementing tied weights in the shown GPTModel and notes that separate layers are used here. section 4.6

How Build a Large Language Model (From Scratch) covers it

How deep it goes
Defines the sharing idea, shows matching tensor shapes, and computes its parameter-count effect, but does not implement tied weights in GPTModel here.
Examples
Uses GPTModel shape prints and parameter-count listings to show the tied-versus-untied difference.
What it assumes
Assumes token embeddings, linear output heads, tensor shapes, and parameter counting from scratch.
What you can do after
Understand the parameter-sharing tradeoff and estimate the resulting model-size reduction.
How it connects
Links token embedding, output layer, GPTModel, and GPT-2 architecture.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build a Large Language Model (From Scratch). The section links point to the parts of the book it draws on.