Repository navigation
closes #2214 Fix batch-dimension slicing in physicsnemo_fdm_swe_nonlin PDE residuals for batchsize=1 - #2233
closes #2214 Fix batch-dimension slicing in physicsnemo_fdm_swe_nonlin PDE residuals for batchsize=1#2233dmitriySem wants to merge 2 commits into
physicsnemo_fdm_swe_nonlin PDE residuals for batchsize=1#2233Conversation
The [1:-1] slice was applied along the batch dimension, making the PDE residual tensor empty for batchsize=1 and causing loss_pde to be NaN. Remove the batch-dim slice so the physical loss is computed correctly." Signed-off-by: Dmitriy <dvsemen93@gmail.com>
…iduals in the shallow water example, which caused `loss_pde` to be `NaN` for `batchsize=1` Signed-off-by: Dmitriy <dvsemen93@gmail.com>
CODEOWNERS review mapCurrent for commit No CODEOWNER
Comment |
|
[Medium impact] The change affects the shallow-water PINO example's PhysicsNeMo training path. The fix appears safe to merge, with a non-blocking request for regression coverage. Findings
SummaryFixes the shallow-water physics loss by keeping every batch element in
Reviews (1) · Last reviewed commit: "Fixed batch-dimension slicing in `physic..." · Reviewed by Greptile |
| Dh = pde_Dh["Dh"] | ||
| Du = pde_Du["Du"] | ||
| Dv = pde_Dv["Dv"] |
There was a problem hiding this comment.
Batch fix lacks regression coverage
The batch-slicing fix has no regression test. Add a small test for physicsnemo_fdm_swe_nonlin and physicsnemo_fourier with batch sizes 1, 2, and 3. Check that each residual keeps every batch element and that a nonconstant input produces a finite loss and finite, nonzero gradients. This would catch both empty residuals for small batches and silently dropped samples for larger batches.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
There was a problem hiding this comment.
Thanks for the concrete suggestion. I agree that a regression test would be valuable. Since this is my first contribution to PhysicsNeMo and the current PR is intentionally minimal, I'd like to get feedback from the project maintainers first. If a test is required for acceptance, I'll add it to this PR or prepare a separate one.
There was a problem hiding this comment.
That makes sense. My comment was a coverage suggestion, not a claim that a regression test is required for acceptance. Keeping this PR focused and waiting for maintainer feedback is reasonable; if they request coverage, you can add it here or in a follow-up.
Tip: You can customize Greptile's behavior for this repo with .greptile/rules.md and .greptile/config.json.
closes #2214
Problem
In
examples/cfd/swe_nonlinear_pino/train_utils/losses.py, the functionphysicsnemo_fdm_swe_nonlinslices the PDE residual tensorsDh,Du, andDvalong the batch dimension using[1:-1]. With the defaultbatchsize: 1in the example config, this produces an empty tensor (shape(0, ...)), causingloss_pdeto becomeNaNand the physics loss gradient to be zero. Training proceeds silently without any physics contribution.This is inconsistent with the reference function
fdm_swe_nonlinin the same file, which correctly slices along the last (spatial) dimension using[..., 1:-1].Fix
Removed the batch-dimension slicing from
physicsnemo_fdm_swe_nonlin: