Fix batched multimer template embedding shapes#575
Open
taivu1998 wants to merge 1 commit into
Open
Conversation
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
Fixes #513.
This PR fixes batched multimer template embedding when
batch_size > 1. The previous multimer template loop selected one template withindex_selectbut retained the selected singleton template axis. With batched inputs, that left tensors shaped like[B, 1, N, ...], causing PyTorch to align the retained template axis against the batch axis when multiplying by the[B, N, N]multichain mask.Root Cause
The monomer template embedder already removes the selected template axis and restores it later with
torch.stack. The multimer template embedder did not, soTemplatePairEmbedderMultimerreceived single-template features with an extra dimension. That directly caused the reported broadcast error:Once the selected template axis is removed correctly, the pairwise unit-vector calculation also needs to make its point axis explicit (
points[..., None, :]) so batched rigid frames broadcast over residue pairs as intended.Changes
templ_dimafter selecting one multimer template.templ_diminstead of concatenating tensors that no longer contain that axis.batch_size=2,n_templ=2regression test forTemplateEmbedderMultimer.Validation
python -m py_compile openfold/model/embedders.py tests/test_template.pygit diff --checkpytest tests/test_template.py -k batched_template_embedding_shapepytest tests/test_template.pyLocal note: the tests were run in a temporary validation environment because the base Python on this macOS host was missing several declared OpenFold dependencies. Temporary import shims were used only for unavailable local infrastructure modules (
treeand the eagerattn_core_inplace_cudaimport); the focused multimer template path itself executed and passed.