for epoch in range(num_epochs):
    train()  # function contains the training loop.
    with torch.no_grad():
        valid()  # function contains the validation loop.

I think I’ve made it more clear this time.