There are many posts asking how to freeze layer, but the different authors have a somewhat different approach. Most of the time I saw something like this:
Imagine we have a nn.Sequential and only want to train the last layer:
for parameter in model.parameters():
    parameter.requires_grad = False
for parameter in model[-1].parameters():
    parameter.requires_grad = True
optimizer = optim.SGD(model.parameters(), lr=1e0)

I think it is much cleaner to solve this like this:
optimizer = optim.SGD(model[-1].parameters(), lr=1e0)

I ran some simple tests and both methods yield the same results.


Is my method functionally equivalent or did I miss something important?
Is the first method an agreed upon best practice or can I use my method?