Skip to content

Add scale-consistency training#645

Open
zongyi-li wants to merge 5 commits intoneuraloperator:mainfrom
zongyi-li:main
Open

Add scale-consistency training#645
zongyi-li wants to merge 5 commits intoneuraloperator:mainfrom
zongyi-li:main

Conversation

@zongyi-li
Copy link
Copy Markdown
Collaborator

Implement the scale-consistency training from paper https://arxiv.org/abs/2507.18813
We added four files; no existing filed is modified.

  • neuralop/losses/scale_consistency_losses.py the loss scale_consistency by compare global domain and sub domains.
  • neuralop/data/transforms/rescale.py rescaling transforms that zoom in to subdomains.
  • neuralop/training/scale_consistency.py the subclass trainer that pass the model to the loss.
  • example/training/plot_scale_consistency_FNO_darcy.py an example of scale consistency training on boundary-valued darcy problem.

@zongyi-li zongyi-li requested a review from dhpitt September 1, 2025 21:46
@dhpitt
Copy link
Copy Markdown
Member

dhpitt commented Sep 2, 2025

This is great, thanks so much @zongyi-li ! Comments to follow but this looks really good.

One note: the online runner does not haver access to the 128x128 darcy-flow dataset by default as it is not pre-included in the library; we can either download it (e.g. call DarcyDataset(..., download = True) or use a smaller example.

Copy link
Copy Markdown
Member

@dhpitt dhpitt left a comment

Choose a reason for hiding this comment

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

Thanks again for this contribution, @zongyi-li. A few minor notes on style and clarity for future maintainability but overall this looks very good. Passing on to @JeanKossaifi for review.

Comment thread neuralop/data/transforms/rescale.py Outdated
Comment thread neuralop/data/transforms/rescale.py
Comment thread neuralop/data/transforms/rescale.py Outdated
Comment thread neuralop/data/transforms/rescale.py
Comment thread neuralop/data/transforms/rescale.py
Comment thread neuralop/data/transforms/rescale.py Outdated
if type == "darcy":
y_small_ = model(x_small)
else:
y_small_ = model(x_small, re)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This forward call seems like it might belong better in the custom trainer's training loop

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yea we added a custom trainer, but I feel it will also be beneficial to have a loss, which we can use in other trainers in the future.

model = self._unwrap_model()
if self.mixed_precision:
with torch.autocast(device_type=self.autocast_device_type):
sc_loss = self.selfconsistency_loss(model, sample["x"], loss_fn=training_loss, y=sample["y"])
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

As above; might make more sense if things like the model's forward call went here, and as little as possible of the computation belonged in the loss function

@dhpitt dhpitt requested a review from JeanKossaifi September 2, 2025 11:56
@JeanKossaifi
Copy link
Copy Markdown
Member

This looks good, thanks @zongyi-li for the PR and @dhpitt for the review.

My main question is whether there shouldn't be some more separation between the concepts (the algorithm) and the problem specific implementation (for Darcy, Burgers, etc). Perhaps this is just a matter of refactoring a little. What do you think?

@dhpitt
Copy link
Copy Markdown
Member

dhpitt commented Sep 19, 2025

My main question is whether there shouldn't be some more separation between the concepts (the algorithm) and the problem specific implementation (for Darcy, Burgers, etc). Perhaps this is just a matter of refactoring a little. What do you think?

This makes sense to me. The more we can centralize the simpler this will be to maintain in the future

@zongyi-li
Copy link
Copy Markdown
Collaborator Author

sorry for the delay! I will rename the specific implementation to generic one.
Darcy -> 2D boundary value problem
Helmholtz -> 2D Complex boundary value problem
Burger -> 1D temporal problem
NS -> 2D temporal problem

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.

3 participants