PythiloLesson 2 of 9 · progress kept in this browser

Practice in Lab: Partition AdamW parameters without duplicate ownership →

Partition AdamW parameters without duplicate ownership

A training policy must say which parameters receive decoupled weight decay. This exercise uses an explicit dimensional rule: matrices decay, while vectors and scalars do not. It is a policy to review, not a universal theorem about every architecture. Shared embeddings and tied output heads can expose the same parameter through several module paths. Duplicating ownership changes the update or causes an optimizer error. The Lab checks identities and executes an actual AdamW step rather than accepting only a plausible list of names.

import torch
layer = torch.nn.Linear(3, 2)
for name, p in layer.named_parameters():
    print(name, p.ndim)
This example uses torch. Run it in the Pythilo app, where these features are available.
Your task

Return two optimizer group dicts with params lists. Include each distinct trainable parameter once. In this declared policy, tensors with ndim>=2 receive decay; scalars and vectors receive zero decay. Exclude frozen parameters. Reject negative/nonfinite decay and a model with no trainable parameters. Return original Parameter objects, not detached copies. Tied weights must not enter an optimizer twice.

This lesson uses torch, which Python in this browser does not include. Read it here, and run and check it in the Pythilo app on iPhone or iPad.