To print every 300, check for the epoch value:

def train_model(train_dl, model):
criterion = MSELoss()                                               #loss function
optimizer = Adam(model.parameters(), lr=0.001, betas=0.9, 0.999))  #optimizer should be used
for epoch in range(300):
    running_loss = 0.0
    for i, (inputs, targets) in enumerate(train_dl):
        optimizer.zero_grad()
        pred = model(inputs)
        loss = criterion(pred, targets)
        loss.backward()
        optimizer.step()
        if i%300 ==0:
          print ("loss.item",loss.item())
        running_loss +=loss.item()
        epoch_loss += pred.shape[0]*loss.item()

print(‘Finished Training’)

On difference between running and epoch loss, please refer this link 120. Although they refer to the running_loss (epoch loss in your case), the concept should make things clear to you.

In your example, running_loss is the aggregated loss per mini-batch, whereas, epoch_loss is to get loss undoing the reduction …