You are given a PyTorch neural network model, a DataLoader that yields (inputs, targets) batches, an optimizer, and a loss function.
Write a function train(model, train_loader, optimizer, loss_fn, device, num_epochs) that:
num_epochs
epochs.
Clearly show the order of operations inside the training loop (zeroing gradients, forward pass, loss computation, backward pass, optimizer step).