Downscaling loss weighting#1056
Merged
Merged
Conversation
Adds a `loss_weights` dict field to `DiffusionModelConfig` that applies multiplicative per-variable scaling to the denoising loss. Variables not listed default to a weight of 1.0. Includes a test confirming that zeroing a variable's weight eliminates its gradient contribution. Made-with: Cursor
frodre
approved these changes
Apr 20, 2026
Collaborator
frodre
left a comment
There was a problem hiding this comment.
LGTM! Thanks for the addition. Just a couple minor suggestions.
| output_channels: Per-variable multiplicative weights applied to the loss. | ||
| Keys are variable names from out_names; variables not listed default to 1.0. | ||
| noise_weight_exponent: Exponent applied to the EDM noise-level loss weight | ||
| ``(sigma^2 + sigma_data^2) / (sigma * sigma_data)^2``. The default |
Collaborator
There was a problem hiding this comment.
I would add the value found helpful for variables dominated by the lower-noise losses for easy reference like you did docs for the noise code.
| def _build_variable_loss_weight_tensor( | ||
| weights: dict[str, float], out_names: list[str] | ||
| ) -> torch.Tensor: | ||
| values = [weights.get(name, 1.0) for name in out_names] |
Collaborator
There was a problem hiding this comment.
I would consider putting something in here that errors if a requested loss weight name is not in out_names so that we get a fast turnaround on typos, etc.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds two configurable options to loss weighting in the downscaling training config, contained in the optional field
loss_weights. Both were found to improve the generated outputs.loss_weights.output_channels: dict with key, value corresponding to output channel name and weight to multiply that variable's loss by. Output names not in this dict are not adjusted. Downweighting precipitation improves the overall outputs' CRPS and extreme values with no adverse effect on precip skill.loss_weights.noise_weight_exponent: power to raise the default EDM noise-weighted loss by. By default 1.0. Experiments indicate lowering this to ~0.75 improves the generation of pressure and wind extremes; these fields tend to have their noise vs loss dominated by small noise values if using the default EDM weighting.