Loading...
Configure different learning rates for different layers using parameter groups.
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.
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.
Returns a dictionary with "num_param_groups", "group0_lr", "group1_lr", "group0_num_params", and "group1_num_params".
None
{'num_param_groups': 2, 'group0_lr': 0.001, 'group1_lr': 0.01, 'group0_num_params': 2, 'group1_num_params': 2}per_layer_lr_test() seeds the random number generator with torch.manual_seed(42) to ensure reproducibility.fc1 and fc2), and an Adam optimizer is initialized with two parameter groups: one for fc1 with a learning rate of 0.001, and one for fc2 with a learning rate of 0.01.