So if a model has a dropout layer (or a batch-norm layer), then doing
model(x)
will/may yield a different result compared to
model.eval()
model(x)

But now for training what we have is an inference step and a training step. So do we actually have to do something like the following?
...
for epoch in range(epochs):
    model.eval()   # make sure we are in .eval() mode
    ...
    y_pred = model(x)
    ...
    model.train()  # make sure we are in .train() mode
    loss = loss_fun(y_pred, target)
    loss.backward()
    ...

What’s the correct way to train a network in this case?