Align NAT functionals with FunctionSpec#1615
Align NAT functionals with FunctionSpec#1615loliverhennigh wants to merge 10 commits intoNVIDIA:mainfrom
Conversation
Greptile SummaryThis PR wraps the existing
Important Files Changed
Reviews (1): Last reviewed commit: "Align NAT functionals with FunctionSpec" | Re-trigger Greptile |
| @classmethod | ||
| def dispatch(cls, *args, **kwargs): | ||
| try: | ||
| return super().dispatch(*args, **kwargs) | ||
| except ImportError as exc: | ||
| installed_version = get_installed_version("natten") | ||
| if installed_version is not None: | ||
| raise ImportError( | ||
| f"{cls._NATTEN_REQUIREMENT} is required for {cls.__name__}, " | ||
| f"but found natten {installed_version}" | ||
| ) from exc | ||
| try: | ||
| _natten.functional | ||
| except ImportError as missing_exc: | ||
| raise missing_exc from exc | ||
| raise |
There was a problem hiding this comment.
Unreachable
raise at the end of the dispatch override
The final bare raise is only reached when installed_version is None and _natten.functional does not raise ImportError. Because installed_version is None means the package metadata is absent and the OptionalImport proxy always raises ImportError on attribute access when the underlying module cannot be imported, this branch is currently unreachable in practice. If _natten.functional somehow succeeds (e.g., metadata is absent but the package is importable), re-raising exc produces the cryptic "No available implementations found" message rather than any natten-specific hint. The code path should either be documented with a comment explaining the invariant, or the final raise should emit a more descriptive error.
|
@loliverhennigh my main question is have you tested that this still works with ShardTensor and domain parallelism? Want to make sure the dispatch path in that case does the right thing. Otherwise looks good |
| from physicsnemo.nn.functional.geometry import SignedDistanceField | ||
| from physicsnemo.nn.functional.geometry import ( | ||
| MeshPoissonDiskSample, | ||
| MeshToVoxelFraction, |
There was a problem hiding this comment.
Some of the functionals got left out so adding them back in
| All functionals must be implemented with `FunctionSpec`, even if only a single | ||
| implementation exists. This ensures the operation participates in validation | ||
| and benchmarking through input generators and `compare_forward` (and | ||
| All functionals with backend dispatch, optional accelerated implementations, or |
There was a problem hiding this comment.
Basically going to make some space for if we have very simple python functions and dont want to implement the whole FunctionSpec stuff
8da5e27 to
280d401
Compare
f0cb8a9 to
e3847e8
Compare
|
rst files looked good to me, I had one very minor suggestion for Nvidia style guide rules. Looks like you still have other comments, but I am ready to approve of this when you need. |
297f9cb to
62a0ef7
Compare
|
/blossom-ci |
|
/multi-gpu-ci |
|
/blossom-ci |
I have no idea if this still does anything. You might need to test manually on a cluster. |
|
Hey @coreyjadams and @pzharrington , Just manually ran on two GB200s and it passed. I think we are all good to merge unless there is something else |
| DualInteractionPlan, | ||
| SourceAggregates, | ||
| ) | ||
| from physicsnemo.experimental.models.globe.cluster_tree import ClusterTree |
There was a problem hiding this comment.
Motivation for this edit? Seems unrelated
|
/blossom-ci |
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| from .ops import ( |
There was a problem hiding this comment.
This change of equivariant_ops -> equivariant.ops is backwards-incompatible. We should at-bare-minimum have a CHANGELOG entry for this, but realistically this probably calls for a larger discussion about whether this is worth breaking back-compat for, given that there may be downstream users that are consumers of this API surface. In general, we shouldn't be breaking public (i.e., non-_-prefixed) API surface unless it's exceedingly important that we do so.
Also, tagging @laserkelvin for API thoughts on the equivariant module (not sure if you have any uses of this?)
There was a problem hiding this comment.
I don't think I have an issue with naming alignment itself (i.e. nn.functional.equivariant) - I'm just confused why this is happening now, and to your (@peterdsharpe's) point this is backwards incompatible. AFAIK there aren't public consumers of that API yet, but please make sure that the tests associated with this change pass
There was a problem hiding this comment.
Unless we introduced equivariant_ops within this current release cycle (in which case it's not part of the public API yet)? What does the git blame say?
There was a problem hiding this comment.
It's not in the 2.0.0 release, and I think you added it 2 months ago
There was a problem hiding this comment.
Ah - if it wasn't ever released publicly in an official release cut, then I'm more ok with breaking this API.
That said, it's not obvious to me that either naming convention is better than the other. In the absence of motivation, defaulting to the existing API seems like the best path forward. That said, there may be motivation for this change that I'm not seeing - @loliverhennigh can you speak to the motivation for this change?
There was a problem hiding this comment.
External customers should only use functionals via physicsnemo.nn.functionals.xyz. This is how the coding standards and docs are laid out at least. This PR does not change that import so I think we are good. Only internal imports might change.
|
/blossom-ci |
| @@ -22,11 +22,15 @@ | |||
|
|
|||
|
|
|||
| @overload | |||
| def smooth_log(x: Float[torch.Tensor, "..."]) -> Float[torch.Tensor, "..."]: ... | |||
| def smooth_log(x: Float[torch.Tensor, "..."]) -> Float[torch.Tensor, "..."]: | |||
| """Apply smooth log elementwise to a tensor.""" | |||
There was a problem hiding this comment.
These are @overloads - are docstrings needed to satisfy interrogate? I would hope that they would not be needed, but I don't know if interrogate is smart enough to handle this.
Maybe interrogate has an option to ignore overloaded functions?
|
@loliverhennigh can we flesh out the discussion in unresolved comment threads before merging? |
8519251 to
6885e86
Compare
|
/blossom-ci |
Co-authored-by: megnvidia <mmiranda@nvidia.com>
b8d31d3 to
e638afc
Compare
|
/blossom-ci |
PhysicsNeMo Pull Request
Description
Cleans up some of the NAT functional stuff and others that made it past my radar.