Use rank-2 linear for UMA spectral gates - #2141
Open
mlazos wants to merge 1 commit into
Open
Conversation
SpectralAtomwise kept a singleton coefficient dimension when projecting its scalar slice. Linear consequently lowered the production [1000, 1, 128] input to four broadcast BMMs in both the forward and input-gradient graphs. Squeeze that known singleton dimension before the scalar MLP. GateActivation already consumes the resulting rank-2 tensor, so this changes no model semantics and lets Inductor emit ordinary addmm/mm calls without layout conversions. The focused test compares the old expression with the new path bitwise on CPU and records the Linear input rank. The exact internal-v3, external_graph_gen=False endpoint improved by an order-balanced 0.250852 ms (1.353%), with all six paired cycles positive and all seven energy/forces/stress perturbations passing. Test Plan: ``` PYTHONPATH=$PWD/src:/data/users/mlazos/pytorch python -m pytest -q tests/core/models/uma/test_escn_md.py ruff check --ignore UP035 src/fairchem/core/models/uma/escn_md_block.py tests/core/models/uma/test_escn_md.py git diff --check ``` Authored with assistance from Codex.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SpectralAtomwiseretains a singleton coefficient dimension when projectingits scalar slice. That sends
[num_atoms, 1, sphere_channels]tensors throughLinear, which lowers the production shape to broadcast BMMs in the forwardand input-gradient graphs.
Squeeze the known singleton dimension before the scalar MLP. The gate already
accepts the resulting rank-2 tensor, so model semantics are unchanged while
Inductor can emit ordinary addmm/mm calls without layout conversions.
Performance
Testing
All 13 tests passed.
Authored with assistance from Codex.