Freeze final layer

I am trying to train layer by layer. In a stage I would like to freeze the final layer alone . When i tried to freeze it I encounter an error saying . How do i solve this problem ? any idea ?

  RuntimeError: element 0 of tensors does not require grad and does not have a grad_fn

I guess you need to set requires_grad = False in the final layer.
I refereed this - RuntimeError: element 0 of variables does not require grad and does not have a grad_fn when trying to implement Gumbel-ST sampler
Do let me know if it works.

1 Like

Works for me. Thanks.

Happy to learn through you.

Hi,
Is it is possible to freeze a layer partially. I want to freeze those parts of a layer which have not changed more than a pre-defined threshold in the last 10 iterations.