# Can we use model.eval() and model.train() alternatively in Pytorch?

Hi! I’m trying to get two representation of the same input in model.eval() and model.train(), respectively. I write the following codes:

``````for id, batch in enumerate(loader):
model.train()
rep1 = model(batch.text)
model.eval()
rep2 = model(bacth.text)
``````

However, it seems it didn’t work, so is there any ways to do that?

Could you describe what exactly is not working? Do you see any errors using it?

Thanks for your attention. I just found I put model.eval() in the forward process, and it works now, I’ll be more careful next time.