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

Feature/improve loss functions #70

Open
wants to merge 54 commits into
base: develop
Choose a base branch
from

Conversation

HCookie
Copy link
Member

@HCookie HCookie commented Oct 2, 2024

Improve loss functions.

Prior, WeightedMSELoss was the hard coded loss for training and metrics.
This PR changes the loss function configuration to be fully modular, so that any nn.Module can be used.

Additionally, this adds the following additonal loss functions into anemoi-training

  • WeightedMAE
  • WeightedRMSE
  • WeightedLogCosh
  • WeightedHuber
  • CombinedLoss

Arbitary Scalars

See #96 for more information

  • Allows for arbitary scalars to be applied to the loss values

📚 Documentation preview 📚: https://anemoi-training--70.org.readthedocs.build/en/70/

@HCookie HCookie self-assigned this Oct 2, 2024
@HCookie HCookie added the enhancement New feature or request label Oct 2, 2024
@HCookie HCookie marked this pull request as ready for review October 2, 2024 15:59
Copy link
Member

@JesperDramsch JesperDramsch left a comment

Choose a reason for hiding this comment

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

Thanks for tackling these.

I have some doubts about some design decisions, as I have also mentioned in a conversation.

Could you please elaborate why the loss functions now have a dynamic feature index?

I think the metrics could be a nice list, so we can calculate multiple metrics as well.

src/anemoi/training/losses/mse.py Outdated Show resolved Hide resolved
src/anemoi/training/losses/mse.py Outdated Show resolved Hide resolved
src/anemoi/training/losses/mse.py Outdated Show resolved Hide resolved
src/anemoi/training/losses/mse.py Outdated Show resolved Hide resolved
src/anemoi/training/train/forecaster.py Outdated Show resolved Hide resolved
src/anemoi/training/config/training/default.yaml Outdated Show resolved Hide resolved
src/anemoi/training/config/training/default.yaml Outdated Show resolved Hide resolved
src/anemoi/training/losses/mse.py Show resolved Hide resolved
src/anemoi/training/losses/mse.py Outdated Show resolved Hide resolved
src/anemoi/training/config/training/default.yaml Outdated Show resolved Hide resolved
- Add comment to if dim == 4
- Move to inplace out multiplication
- Is an abstract weighted loss class
- Combines feature weighting and node weighting
- mse, mae, rmse, logcosh now subclass from WeightedLoss
- Was causing issues with training, due to new shape of data
Copy link
Member

@JesperDramsch JesperDramsch left a comment

Choose a reason for hiding this comment

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

I left a partial review on some of the core problems I see with the current implementation. Thank you for already addressing a lot of my previous comments.

I think there are a few main issues from my side regarding the initialization of the losses. It's likely we could just solve this in a quick call rather than asynchronously.

src/anemoi/training/losses/weightedloss.py Outdated Show resolved Hide resolved
src/anemoi/training/losses/weightedloss.py Outdated Show resolved Hide resolved
src/anemoi/training/losses/weightedloss.py Outdated Show resolved Hide resolved
src/anemoi/training/losses/weightedloss.py Outdated Show resolved Hide resolved
src/anemoi/training/losses/weightedloss.py Show resolved Hide resolved
src/anemoi/training/train/forecaster.py Outdated Show resolved Hide resolved
src/anemoi/training/train/forecaster.py Outdated Show resolved Hide resolved
src/anemoi/training/train/forecaster.py Outdated Show resolved Hide resolved
src/anemoi/training/train/forecaster.py Outdated Show resolved Hide resolved
src/anemoi/training/train/forecaster.py Outdated Show resolved Hide resolved
- Also chage latitude to Node
@HCookie
Copy link
Member Author

HCookie commented Oct 18, 2024

Provides a way to use arbitary scalings
#96

@mc4117
Copy link
Member

mc4117 commented Oct 21, 2024

We now have a downstream application which depends on this branch so it would be nice if it could be merged soonish

HCookie and others added 7 commits October 22, 2024 14:15
- Allows for multiple losses to be combined with associated weights
- Allows access to underlying functions
* Add ScaleTensor
- Allows dynamic setup of scalars
- Rework variable_scaler to use it
@HCookie HCookie dismissed JesperDramsch’s stale review October 23, 2024 15:56

JesperDramsch is currently absent

HCookie and others added 9 commits October 24, 2024 08:02
- Also fix scalar being incorrectly made
- Info about indexing
- Remove 'include_', and 'add_scalar_'
- Add 'scalars' to control scalars
- Add docs
- Rework tests
- Add functional loss function
- Remove variable_scaling from kwargs
- Require subclass of BaseWeightedLoss
@HCookie HCookie requested a review from mchantry October 25, 2024 08:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants