Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add history loss #70

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion pts/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ def __call__(
train_iter: DataLoader,
validation_iter: Optional[DataLoader] = None,
) -> None:

self.training_loss = []
self.validation_loss = []
optimizer = Adam(
net.parameters(), lr=self.learning_rate, weight_decay=self.weight_decay
)
Expand Down Expand Up @@ -80,7 +83,6 @@ def __call__(
},
refresh=False,
)

loss.backward()
if self.clip_gradient is not None:
nn.utils.clip_grad_norm_(net.parameters(), self.clip_gradient)
Expand All @@ -92,6 +94,9 @@ def __call__(
break
it.close()

# Append the average loss for the epoch to the list of loss values
self.training_loss.append(avg_epoch_loss)

# validation loop
if validation_iter is not None:
cumm_epoch_loss_val = 0.0
Expand Down Expand Up @@ -121,6 +126,8 @@ def __call__(
break

it.close()
self.validation_loss.append(avg_epoch_loss_val)

# mark epoch end time and log time cost of current epoch
toc = time.time()