Skip to content

Self_training_fix #239

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

Merged
merged 2 commits into from
Feb 27, 2025
Merged

Self_training_fix #239

merged 2 commits into from
Feb 27, 2025

Conversation

changbiHub
Copy link
Contributor

@changbiHub changbiHub commented Feb 26, 2025

Fix bugs in EncoderDecoderTrainer and EncoderDecoderLoss

I identified two bugs while using EncoderDecoderTrainer for pretraining:

Issue 1: Negative Loss Values in EncoderDecoderLoss

When calculating the loss, if x_true_stds is zero, it's replaced with the corresponding value from x_true_means. If these mean values are negative, they cause the loss to become negative, which is problematic for optimization.

The problematic code:

x_true_stds = torch.std(x_true, dim=0) ** 2
x_true_stds[x_true_stds == 0] = x_true_means[x_true_stds == 0]

Issue 2: Inconsistent Return Order in _forward_tabnet

The _forward_tabnet method returns values in a different order compared to other encoder-decoder models:

  • Other models: x_embed, x_embed_rec, mask
  • TabNet: x_embed_rec, x_embed, mask

This inconsistency causes incorrect inputs to the loss function when using TabNet with EncoderDecoderTrainer.

Solution

For Issue 1:

Modified the EncoderDecoderLoss to use the absolute value of means when replacing zero standard deviations:

x_true_stds[x_true_stds == 0] = torch.abs(x_true_means[x_true_stds == 0])

This ensures that the scaling factor remains positive, which is conceptually correct since standard deviations are always non-negative.

For Issue 2:

Changed the return order in _forward_tabnet to match the convention used by other models:

return x_embed, x_embed_rec, mask  # Previously: x_embed_rec, x_embed, mask

@changbiHub changbiHub marked this pull request as ready for review February 26, 2025 21:53
@jrzaurin jrzaurin merged commit 4187bbd into jrzaurin:master Feb 27, 2025
2 checks passed
@changbiHub changbiHub deleted the self_training_fix branch February 27, 2025 10:35
@jrzaurin
Copy link
Owner

jrzaurin commented Feb 27, 2025

thanks for opening the PR. Next time (I hope there is a next time :) ), if you could please open it from a brach in the repo would be great, as it would go through the tests. Now it has broken a few tests. I will try to fix them

Thanks anyway!

@jrzaurin
Copy link
Owner

ok, errors have to do with pytorch 2.6.

I will open an issue

@changbiHub
Copy link
Contributor Author

Sorry about that, first time PR.

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