Per-Layer Learning Rates
Problem Statement
Configure different learning rates for different layers using parameter groups.
Background
PyTorch optimizers accept a list of parameter groups, each with its own hyperparameters. This is essential for fine-tuning where you want lower LR for pretrained layers.
Your Task
The starter code creates a 2-layer model. Create an Adam optimizer with different learning rates per layer: 0.001 for fc1 and 0.01 for fc2.
Output Format
Returns a dictionary with "num_param_groups", "group0_lr", "group1_lr", "group0_num_params", and "group1_num_params".
Example
None
{'num_param_groups': 2, 'group0_lr': 0.001, 'group1_lr': 0.01, 'group0_num_params': 2, 'group1_num_params': 2}- The function takes no arguments. It builds a fixed two-layer network: fc1 maps , a ReLU follows, and fc2 maps . The ReLU has no learnable weights.
- The model's learnable tensors are split into two groups, each with its own step size . Group 0 holds fc1 with and group 1 holds fc2 with . So
num_param_groupsis2. - With Adam, every update in a group is scaled by that group's . So the output layer moves times faster than the first layer.
- Each linear layer has two tensors, a weight and a bias. For fc1 they are an matrix (32 numbers) and a length-8 vector. For fc2 they are a matrix (16 numbers) and a length-2 vector.
- Notice that
group0_num_paramsandgroup1_num_paramsare both2. They count tensors, not scalars: 40 values and 18 values both come out as2. The group order also matters, because the first group listed becomes group 0.
Constraints
- Two parameter groups with different LRs
- fc1: lr=0.001, fc2: lr=0.01
- Use Adam optimizer