To freeze certain parameters, you could either zero out their gradients (e.g. using hooks) or avoid passing them to the optimizer. Note that parameters could still be updated, if your optimizer uses internal running estimates or a momentum even if the gradients are zero.



 batlike:

Does PyTorch have this flexibility?


It should have the flexibility, as there are some HMM implementations in PyTorch, e.g. here 2.