From 3f60f4d0140460f4eb7c8099225310a80062085b Mon Sep 17 00:00:00 2001 From: Andrew Grangaard Date: Wed, 7 Jan 2026 20:21:54 -0800 Subject: [PATCH] lab2-PT-MNIST: fix train() to use parameters rather than global values + global values `fc_model` and `loss_function` were used inside the train() function rather than the passed parameters `model` and `criterion`. + fix duplicated in both the student and solution versions of the pytorch notebook. --- lab2/PT_Part1_MNIST.ipynb | 4 ++-- lab2/solutions/PT_Part1_MNIST_Solution.ipynb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lab2/PT_Part1_MNIST.ipynb b/lab2/PT_Part1_MNIST.ipynb index 4a345b27..7bcde853 100644 --- a/lab2/PT_Part1_MNIST.ipynb +++ b/lab2/PT_Part1_MNIST.ipynb @@ -418,12 +418,12 @@ " images, labels = images.to(device), labels.to(device)\n", "\n", " # Forward pass\n", - " outputs = fc_model(images)\n", + " outputs = model(images)\n", "\n", " # Clear gradients before performing backward pass\n", " optimizer.zero_grad()\n", " # Calculate loss based on model predictions\n", - " loss = loss_function(outputs, labels)\n", + " loss = criterion(outputs, labels)\n", " # Backpropagate and update model parameters\n", " loss.backward()\n", " optimizer.step()\n", diff --git a/lab2/solutions/PT_Part1_MNIST_Solution.ipynb b/lab2/solutions/PT_Part1_MNIST_Solution.ipynb index efb23831..779a6011 100644 --- a/lab2/solutions/PT_Part1_MNIST_Solution.ipynb +++ b/lab2/solutions/PT_Part1_MNIST_Solution.ipynb @@ -423,9 +423,9 @@ " # Clear gradients before performing backward pass\n", " optimizer.zero_grad()\n", " # Forward pass\n", - " outputs = fc_model(images)\n", + " outputs = model(images)\n", " # Calculate loss based on model predictions\n", - " loss = loss_function(outputs, labels)\n", + " loss = criterion(outputs, labels)\n", " # Backpropagate and update model parameters\n", " loss.backward()\n", " optimizer.step()\n",