Fix Transolver structured-embedding flattening#1684
Conversation
…ed embeddings - Updated the documentation for the embedding parameter to clarify that spatially-shaped embeddings can be passed and will be flattened internally. - Modified output description to specify that the output tensor retains the spatial layout of the input. - Added a regression test to ensure that structured models correctly handle spatially-shaped embeddings, verifying that they align with the flattened input form.
Greptile SummaryThis PR fixes a one-line bug in
Important Files Changed
Reviews (1): Last reviewed commit: "Enhance Transolver documentation and add..." | Re-trigger Greptile |
|
/blossom-ci |
|
/ok to test 95892e0 |
|
Can we merge this into the 2D-3D cleanup PR? |
|
Specifically, I think we could merge this into here perhaps: #1676 |
|
Weak preference to keep these separate (since #1676 seems to have bigger scope, and in-general I'm a fan of more-and-smaller PRs rather than fewer-and-larger PRs). I'm comfortable waiting until #1676 merges before merging this in, if you prefer. But, if you feel strongly that we should combine these PRs, that's fine too! Will sync up offline with you! |
PhysicsNeMo Pull Request
Transolver.forwardcrashed when given a spatially-shapedembeddingfor structured data withunified_pos=False. This corrects the reshape so the embedding is flattened to tokens the same wayfxalready is.Why
For structured data the forward pass flattens
fxfrom(B, H, W[, D], C)to(B, N, C), then concatenates it withembedding. The embedding branch did the opposite: it reshaped a non-3D embedding to(B, *structured_shape, -1), leaving it 4D/5D. The next line,torch.cat((embedding, fx), -1), requires equal rank, so it always raisedRuntimeError: Tensors must have same number of dimensions.The branch could never succeed, and it contradicted the docstring, which told users the embedding "should match
fxspatial dimensions" (exactly the shape that crashed). The fix flattens the embedding consistently withfx:What it affects
TransolverandFLARE(which inheritsTransolver.forward) now accept spatially-shaped embeddings for structured data.GeoTransolverhas its own forward and is unaffected.(B, N, C_emb)embedding, usesunified_pos=True(auto 3D buffer), or runs unstructured (structured_shape=None), so the branch was skipped. The change only turns the previously-crashing path into correct output, so it cannot regress working code. No signature or return-type changes.Tests
Added a parametrized (2D and 3D) regression test that runs the structured,
unified_pos=Falsepath with a spatially-shaped embedding, checks the output shape, and confirms it matches the equivalent pre-flattened(B, N, C_emb)input. Verified that irregular,unified_pos, and pre-flattened structured paths are unchanged.Docs
Clarified the
embeddingparameter docstring: for structured data it may be passed either flattened as(B, N, C_emb)or with the same spatial layout asfx; the output followsfx's layout.Checklist
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.