A coordinate check (or coord check) is a method to verify that your Maximal Update Parametrization (μP) implementation is correct. It involves calculating the average size (the l1 norm, or x.abs().mean()) of activation vectors and model outputs across different model widths and training steps.
Correct Implementation Behavior:
- The
l1 values should remain stable (horizontal curves) as width increases. - Performance (training loss) should consistently improve as the model gets wider.
Incorrect Implementation Behavior:
l1 values blow up or shrink to 0 as width increases.- Performance gets worse as the model gets wider.
Exceptions to watch for:
In a correct μP implementation, the following may shrink to 0 at initialization (at a $1/\sqrt{\text{width}}$ rate) but should become roughly flat after a few training steps:
- The network output.
- The attention logits in a Transformer.
To resolve these transient discrepancies at initialization, it is recommended to:
- Initialize the output layer (using
MuReadout) with readout_zero_init=True. - Manually initialize the query matrix in a Transformer to 0.
from mup.coord_check import get_coord_data, plot_coord_data
# construct a dictionary of lazy μP models with differing widths
def lazy_model(width):
# `set_base_shapes` returns the model
return lambda: set_base_shapes(MyMuModel(width), 'my/base/shape/path.bsh')
# Note: any custom initialization with `mup.init` would need to
# be done inside the lambda as well
models = {64: lazy_model(64), ..., 1024: lazy_model(1024)}
# make a dataloader with small batch size/seq len
# just for testing
dataloader = ...
# record data from the model activations over a few steps of training
# this returns a pandas dataframe
df = get_coord_data(models, dataloader)
# This saves the coord check plots to filename.
plot_coord_data(df, save_to=filename)
# If you are in jupyter notebook, you can also do
# `plt.show()`
# to show the plot