Back to problems

Implement PyTorch training loop

Algorithm · Amazon · Hard

Implement a simplified training loop for a single linear layer using ordinary gradient descent. Instead of real PyTorch tensors, all objects are standard Python collections so the solution can be evaluated automatically. Write a function train(model, train_loader, optimizer, loss_fn, device, num_epochs) that behaves as follows. The input objects are: model: a dictionary with keys 'weights' and 'bias', representing one linear layer. train_loader: a list of batches in order.…

Checking your access…