Premium problem87. Different Learning Rates per Group

Medium Locked

Build a model with a backbone (Linear(4, 4)) and a classifier (Linear(4, 2)), seeding once with torch.manual_seed(seed) before creating them in that order. Create an SGD optimizer with two parameter groups: the backbone at lr_backbone and the classifier at lr_classifier.

Return a list of (number_of_tensors_in_group, learning_rate) pairs, one per group, in the order the groups were given.

The optimizer itself cannot be returned -- two identically configured optimizers are different objects to the comparison -- so the question asks for what you would check instead: that the groups ended up with the rates you intended. This is how you give a pretrained backbone a smaller step than a fresh head.

Input

lr_backbone = 0.001
lr_classifier = 0.1
seed = 0

Output

[(2, 0.001), (2, 0.1)]

Premium problem

This one's part of Premium. Unlock the full PyTorch track plus every other premium problem on the site.

Implement solve(...)