Thanks for the quick response Chris.
I did not know about the initialization of the hidden state of encoder and realized i somehow deleted the torch.no_grad() condition during evaluation. it seems both things combined led to the failure.
Corrected both and code worked fine