### Training Loop# put the model in training mode(train state is default)model.train()# pass the data through the model for a number of epochsfor epoch in range(epochs): # 1. forward pass on train data y_pred = model.forward(X_train) # 2. calculate the loss loss = loss_fn(y_pred, y_true) # 3. zero the gradients of the optimizer(default: accumulated) optimizer.zero_grad() # 4. backward pass (gradient calculation) loss.backward() #5. progress the optimier (GD) optimizer.step() ### Testing Looop # put the model to evaluation mode(train state is default) model.eval() # turn on inference mode context message with torch.inference_mode(): # 1. do the forward pass test_pred = model(X_test) # 2. calculate the loss test_loss = loss_fn(test_pred, y_test) # print out print(f"Epoch:{epoch} | Train loss: {loss: .4f} | Test loss: {test_loss: .4f})