Skip to content

Conversation

@peterdsharpe
Copy link
Collaborator

@peterdsharpe peterdsharpe commented Nov 20, 2025

PhysicsNeMo Pull Request

Adds a new CombinedOptimizer utility, which is useful for the increasingly-popular "architecture-aware optimizers", such as Muon.

This PR targets the v2.0 refactor branch, so this should only be merged after #1235 .

Description

Checklist

  • I am familiar with the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.
  • The CHANGELOG.md is up to date with these changes.
  • An issue is linked to this pull request.

Dependencies

Review Process

All PRs are reviewed by the PhysicsNeMo team before merging.

Depending on which files are changed, GitHub may automatically assign a maintainer for review.

We are also testing AI-based code review tools (e.g., Greptile), which may add automated comments with a confidence score.
This score reflects the AI’s assessment of merge readiness and is not a qualitative judgment of your work, nor is
it an indication that the PR will be accepted / rejected.

AI-generated feedback should be reviewed critically for usefulness.
You are not required to respond to every AI comment, but they are intended to help both authors and reviewers.
Please react to Greptile comments with 👍 or 👎 to provide feedback on their accuracy.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Nov 20, 2025

Greptile Overview

Greptile Summary

Adds CombinedOptimizer utility that wraps multiple PyTorch optimizers into a unified interface for architecture-aware optimization strategies. The implementation provides proper state management, serialization, and learning rate scheduler compatibility.

Critical Issue Found:

  • The documentation claims closures are evaluated once (line 53-55), but the implementation passes the closure directly to each optimizer, causing multiple evaluations. This leads to redundant forward/backward passes and conflicts with optimizers like LBFGS that may call the closure multiple times internally.
  • The test suite validates this incorrect behavior (test_combined_optimizer.py:158-174), which needs alignment with the intended design.

Recommendations:

  • Decide on the desired closure behavior (single evaluation vs. per-optimizer evaluation)
  • Update either the implementation or documentation to match
  • Adjust the corresponding test case to validate the correct behavior

Important Files Changed

File Analysis

Filename Score Overview
physicsnemo/optim/combined_optimizer.py 2/5 New CombinedOptimizer wrapper for multiple optimizers. Critical bug: docstring claims closure evaluated once but implementation evaluates it per optimizer
test/optim/test_combined_optimizer.py 3/5 Comprehensive test coverage for CombinedOptimizer. Tests validate incorrect behavior (multiple closure calls) that contradicts documentation

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

3 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

Copy link
Collaborator

@coreyjadams coreyjadams left a comment

Choose a reason for hiding this comment

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

Overall, looks good. I appreciate extensive testing.

This adds a new package, physicsnemo.optim, which I think is overdue. As part of the refactor let's make sure to get it in the docs too :).

I left some comments but do have another question. What happens when users instantiate and use this and the parameter groups are not disjoint? Will it cause an error? Silent bugs? Should we include a check that each parameter group is completely disjoint?

@peterdsharpe peterdsharpe added the 5 - Merge After Dependencies Depends on another PR: do not merge out of order label Dec 12, 2025
This commit introduces a new documentation file for the PhysicsNeMo Optim module, detailing its purpose and functionality. The documentation includes an overview of the CombinedOptimizer class, which allows the integration of multiple PyTorch optimizers into a single interface, enhancing flexibility in training physics-informed machine learning models.
This update modifies the CombinedOptimizer class to ensure that parameter groups are disjoint. A ValueError is now raised if any parameter appears in multiple optimizers, preventing potential issues during optimization. Additionally, a new test case has been added to verify this behavior.
This commit introduces a new test case in `test_combined_optimizer.py` to verify that saving and restoring the optimizer state using `state_dict` preserves numerical accuracy. The test checks that the parameter updates remain consistent before and after loading the state, ensuring the integrity of the optimizer's internal state across training sessions.
This commit updates the tests for the `zero_grad` method in `test_combined_optimizer.py`. The test for `set_to_none=True` is renamed for clarity and now asserts that gradients are set to None. A new test for `set_to_none=False` is added to verify that gradients are set to zero, ensuring comprehensive coverage of the `zero_grad` functionality.
@peterdsharpe
Copy link
Collaborator Author

/blossom-ci

@peterdsharpe
Copy link
Collaborator Author

/blossom-ci

@peterdsharpe
Copy link
Collaborator Author

/blossom-ci

Copy link
Collaborator

@megnvidia megnvidia left a comment

Choose a reason for hiding this comment

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

looks good to me. Doc approval given.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

5 - Merge After Dependencies Depends on another PR: do not merge out of order

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants