Optimize attention computation with local window bias#254
Open
kaistroh wants to merge 1 commit intoRosettaCommons:productionfrom
Open
Optimize attention computation with local window bias#254kaistroh wants to merge 1 commit intoRosettaCommons:productionfrom
kaistroh wants to merge 1 commit intoRosettaCommons:productionfrom
Conversation
Refactor attention mechanism to compute pair bias within local windows, avoiding large tensor operations.
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.
Refactor attention mechanism to compute pair bias within local windows, avoiding large tensor operations.
For systems with >16,384 atoms RF3 produces partially unphysical structures.
In
AttentionPairBiasDiffusion.atom_attention(), the pair representation tensor is processed as:For large systems the number of elements in Z_II exceeds 2^32. (At least in some versions) PyTorch's CUDA
nn.LayerNormkernel uses 32-bit unsigned integer offsets internally. Which causes corrupt output if the number of elements is > 2^32.The fix gathers the local Z_II window before applying the LayerNorm, instead of computing self.to_b(self.ln_0(Z_II)) on the full [1, L, L, 16] tensor and then indexing into it. This is mathematically identical (LayerNorm normalizes over the last dimension independently per position), but keeps the tensor size to [1, nqbatch, 32, 128, 16]
This fixes #238 and saves a fair amount of GPU RAM because the full B_IIH is never materialized.