For a single layer, you could pass only these parameters to the optimizer:
optimizer = torch.optim.SGD(model.layer1.parameters(), lr=1e-3)

If you need to pass some combination of different parameter sets, you can just pass them as a list:
params = list(model.layer1.parameters()) + list(model.layer17.parameters())
torch.optim.SGD(params, lr=1e-3)