diff --git a/appendix-E/01_main-chapter-code/previous_chapters.py b/appendix-E/01_main-chapter-code/previous_chapters.py index 6270b33..83c55ef 100644 --- a/appendix-E/01_main-chapter-code/previous_chapters.py +++ b/appendix-E/01_main-chapter-code/previous_chapters.py @@ -494,7 +494,7 @@ def train_classifier_simple(model, train_loader, val_loader, optimizer, device, model.train() # Set model to training mode for input_batch, target_batch in train_loader: - optimizer.zero_grad() # Reset loss gradients from previous epoch + optimizer.zero_grad() # Reset loss gradients from previous batch iteration loss = calc_loss_batch(input_batch, target_batch, model, device) loss.backward() # Calculate loss gradients optimizer.step() # Update model weights using loss gradients diff --git a/ch05/01_main-chapter-code/ch05.ipynb b/ch05/01_main-chapter-code/ch05.ipynb index fa3f663..5792c9d 100644 --- a/ch05/01_main-chapter-code/ch05.ipynb +++ b/ch05/01_main-chapter-code/ch05.ipynb @@ -1230,7 +1230,7 @@ " model.train() # Set model to training mode\n", " \n", " for input_batch, target_batch in train_loader:\n", - " optimizer.zero_grad() # Reset loss gradients from previous epoch\n", + " optimizer.zero_grad() # Reset loss gradients from previous batch iteration\n", " loss = calc_loss_batch(input_batch, target_batch, model, device)\n", " loss.backward() # Calculate loss gradients\n", " optimizer.step() # Update model weights using loss gradients\n", @@ -2477,7 +2477,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.4" + "version": "3.10.6" } }, "nbformat": 4, diff --git a/ch05/01_main-chapter-code/gpt_train.py b/ch05/01_main-chapter-code/gpt_train.py index d025d76..0061e5e 100644 --- a/ch05/01_main-chapter-code/gpt_train.py +++ b/ch05/01_main-chapter-code/gpt_train.py @@ -84,7 +84,7 @@ def train_model_simple(model, train_loader, val_loader, optimizer, device, num_e model.train() # Set model to training mode for input_batch, target_batch in train_loader: - optimizer.zero_grad() # Reset loss gradients from previous epoch + optimizer.zero_grad() # Reset loss gradients from previous batch iteration loss = calc_loss_batch(input_batch, target_batch, model, device) loss.backward() # Calculate loss gradients optimizer.step() # Update model weights using loss gradients diff --git a/ch06/01_main-chapter-code/ch06.ipynb b/ch06/01_main-chapter-code/ch06.ipynb index 01001de..f7e71ac 100644 --- a/ch06/01_main-chapter-code/ch06.ipynb +++ b/ch06/01_main-chapter-code/ch06.ipynb @@ -1871,7 +1871,7 @@ " model.train() # Set model to training mode\n", "\n", " for input_batch, target_batch in train_loader:\n", - " optimizer.zero_grad() # Reset loss gradients from previous epoch\n", + " optimizer.zero_grad() # Reset loss gradients from previous batch iteration\n", " loss = calc_loss_batch(input_batch, target_batch, model, device)\n", " loss.backward() # Calculate loss gradients\n", " optimizer.step() # Update model weights using loss gradients\n", @@ -2371,7 +2371,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.4" + "version": "3.10.6" } }, "nbformat": 4, diff --git a/ch06/01_main-chapter-code/gpt-class-finetune.py b/ch06/01_main-chapter-code/gpt-class-finetune.py index bc5666b..1a8a24e 100644 --- a/ch06/01_main-chapter-code/gpt-class-finetune.py +++ b/ch06/01_main-chapter-code/gpt-class-finetune.py @@ -201,7 +201,7 @@ def train_classifier_simple(model, train_loader, val_loader, optimizer, device, model.train() # Set model to training mode for input_batch, target_batch in train_loader: - optimizer.zero_grad() # Reset loss gradients from previous epoch + optimizer.zero_grad() # Reset loss gradients from previous batch iteration loss = calc_loss_batch(input_batch, target_batch, model, device) loss.backward() # Calculate loss gradients optimizer.step() # Update model weights using loss gradients diff --git a/ch06/03_bonus_imdb-classification/train-bert-hf.py b/ch06/03_bonus_imdb-classification/train-bert-hf.py index 8d9c796..8ab5ba5 100644 --- a/ch06/03_bonus_imdb-classification/train-bert-hf.py +++ b/ch06/03_bonus_imdb-classification/train-bert-hf.py @@ -120,7 +120,7 @@ def train_classifier_simple(model, train_loader, val_loader, optimizer, device, model.train() # Set model to training mode for input_batch, target_batch in train_loader: - optimizer.zero_grad() # Reset loss gradients from previous epoch + optimizer.zero_grad() # Reset loss gradients from previous batch iteration loss = calc_loss_batch(input_batch, target_batch, model, device) loss.backward() # Calculate loss gradients optimizer.step() # Update model weights using loss gradients diff --git a/ch06/03_bonus_imdb-classification/train-gpt.py b/ch06/03_bonus_imdb-classification/train-gpt.py index 2f47ece..cd9687c 100644 --- a/ch06/03_bonus_imdb-classification/train-gpt.py +++ b/ch06/03_bonus_imdb-classification/train-gpt.py @@ -149,7 +149,7 @@ def train_classifier_simple(model, train_loader, val_loader, optimizer, device, model.train() # Set model to training mode for input_batch, target_batch in train_loader: - optimizer.zero_grad() # Reset loss gradients from previous epoch + optimizer.zero_grad() # Reset loss gradients from previous batch iteration loss = calc_loss_batch(input_batch, target_batch, model, device, trainable_token=trainable_token) loss.backward() # Calculate loss gradients optimizer.step() # Update model weights using loss gradients