There’s still a small problem when I avoided to do optimizer step after calling backward() in training mode. the problem is: for the same input sentence and the same model, the saliencies are different between the first time and second time I called. If the parameters are totally fixed, the results of saliency should be consistent. I guess that because my model contains a dropout layer and the randomness is generated in model.train() from drop out layer. Any ideas about how to deactivate drop out layer in model.train() mode?
Saliency for the first time calling backward():

Saliency for the second time calling backward():

The Saliency for each word is getting bigger.
Well actually I figured out how to do this, just set the drop out layer to eval by adding model.dropout.eval(), now the Saliency become consistent.