Skip to content

Commit

Permalink
Code consistency fix in linear-regression-scratch.md
Browse files Browse the repository at this point in the history
Model.train() and Model.eval() are used without explanation. In addition, the other parts of the section directly set Model.training = True/False instead of invoking the methods.
  • Loading branch information
dkmoon authored Jan 2, 2025
1 parent 23d7a5a commit 2304da9
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions chapter_linear-regression/linear-regression-scratch.md
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ def prepare_batch(self, batch):
%%tab pytorch
@d2l.add_to_class(d2l.Trainer) #@save
def fit_epoch(self):
self.model.train()
self.model.training = True
for batch in self.train_dataloader:
loss = self.model.training_step(self.prepare_batch(batch))
self.optim.zero_grad()
Expand All @@ -360,7 +360,7 @@ def fit_epoch(self):
self.train_batch_idx += 1
if self.val_dataloader is None:
return
self.model.eval()
self.model.training = False
for batch in self.val_dataloader:
with torch.no_grad():
self.model.validation_step(self.prepare_batch(batch))
Expand Down

0 comments on commit 2304da9

Please sign in to comment.