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

Bugfix: handle case where 'losses' is a list of tensors #1357

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

TeodorChiaburu
Copy link

Description

This PR fixes an issue I came across when applying NHiTS and TFT on my use case, namely that losses can be tensors within a list. In that case, the function mask_losses will fail. It is just a one-liner in base_metrics.py.

Copy link
Collaborator

@jdb78 jdb78 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think this might need some rework. selecting the first loss might make the function work but if a list goes in, a list should go out

@@ -822,6 +822,9 @@ def mask_losses(self, losses: torch.Tensor, lengths: torch.Tensor, reduction: st
"""
if reduction is None:
reduction = self.reduction

if isinstance(losses, list): losses = losses[0]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should that not be something like
losses = [self.mask_losses(loss, lengths, reduction=reduction) for loss in losses]?

@jdb78
Copy link
Collaborator

jdb78 commented Sep 10, 2023

BTW: Would be great to have a test for this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants