-
Notifications
You must be signed in to change notification settings - Fork 133
Make pairformer_emb_per_sample call into pairformer_emb #223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -174,6 +174,161 @@ def test_pairformer_embedding_shape(self): | |
| expected_shape_pair = (batch_size, n_token, n_token, c_z) | ||
| np.testing.assert_array_equal(out_pair.shape, expected_shape_pair) | ||
|
|
||
| def test_pairformer_embedding_multisample_shape(self): | ||
| batch_size = consts.batch_size | ||
| n_sample = 5 | ||
| n_token = consts.n_res | ||
|
|
||
| proj_entry = OF3ProjectEntry() | ||
| config = proj_entry.get_model_config_with_presets() | ||
|
|
||
| c_s_input = config.architecture.shared.c_s_input | ||
| c_s = config.architecture.shared.c_s | ||
| c_z = config.architecture.shared.c_z | ||
|
|
||
| pair_emb = PairformerEmbedding( | ||
| **config.architecture.heads.pairformer_embedding | ||
| ).eval() | ||
|
|
||
| si_input = torch.randn(batch_size, 1, n_token, c_s_input) | ||
| si = torch.randn(batch_size, 1, n_token, c_s) | ||
| zij = torch.randn(batch_size, 1, n_token, n_token, c_z) | ||
| atom_positions_predicted = torch.randn(batch_size, n_sample, n_token, 3) | ||
| single_mask = torch.randint( | ||
| 0, | ||
| 2, | ||
| size=( | ||
| batch_size, | ||
| 1, | ||
| n_token, | ||
| ), | ||
| ) | ||
| pair_mask = torch.randint(0, 2, size=(batch_size, 1, n_token, n_token)) | ||
|
|
||
| out_single, out_pair = pair_emb( | ||
| si_input, | ||
| si, | ||
| zij, | ||
| atom_positions_predicted, | ||
| single_mask, | ||
| pair_mask, | ||
| chunk_size=4, | ||
| ) | ||
|
|
||
| expected_shape_single = (batch_size, n_sample, n_token, c_s) | ||
| np.testing.assert_array_equal(out_single.shape, expected_shape_single) | ||
|
|
||
| expected_shape_pair = (batch_size, n_sample, n_token, n_token, c_z) | ||
| np.testing.assert_array_equal(out_pair.shape, expected_shape_pair) | ||
|
|
||
| def test_pairformer_embedding_apply_per_sample_equal(self): | ||
| batch_size = consts.batch_size | ||
| n_sample = 5 | ||
| n_token = consts.n_res | ||
|
|
||
| proj_entry = OF3ProjectEntry() | ||
| config = proj_entry.get_model_config_with_presets() | ||
|
|
||
| c_s_input = config.architecture.shared.c_s_input | ||
| c_s = config.architecture.shared.c_s | ||
| c_z = config.architecture.shared.c_z | ||
|
|
||
| pair_emb = PairformerEmbedding( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be a separate utility, but for asserting equal tensors you have to modify the model weight init scheme like here: https://github.com/aqlaboratory/openfold-3/blob/main/openfold3/tests/test_kernels.py#L411
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh thanks for flagging. I've hit this with other models before, but didn't think about it here. It would be really nice if Torch had some way to let the init function itself declare different options for different purposes
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added non-zero initialization, although I actually found that the outputs weren't zero even without that.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. they wouldnt be zero bc they have the initial embeddings, but the updates should be zero if i remember correctly
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jnwei we should modify tests to use this util after it's merged in (i.e. kernel and offloading tests)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a nice addition, thanks for adding this utility and for all of the testing fixes @GMNGeoffrey ! |
||
| **config.architecture.heads.pairformer_embedding | ||
| ).eval() | ||
|
|
||
| si_input = torch.randn(batch_size, 1, n_token, c_s_input) | ||
| si = torch.randn(batch_size, 1, n_token, c_s) | ||
| zij = torch.randn(batch_size, 1, n_token, n_token, c_z) | ||
| atom_positions_predicted = torch.randn(batch_size, n_sample, n_token, 3) | ||
| single_mask = torch.randint( | ||
| 0, | ||
| 2, | ||
| size=( | ||
| batch_size, | ||
| 1, | ||
| n_token, | ||
| ), | ||
| ) | ||
| pair_mask = torch.randint(0, 2, size=(batch_size, 1, n_token, n_token)) | ||
|
|
||
| out_single, out_pair = pair_emb( | ||
| si_input, | ||
| si, | ||
| zij, | ||
| atom_positions_predicted, | ||
| single_mask, | ||
| pair_mask, | ||
| chunk_size=4, | ||
| ) | ||
|
|
||
| out_single_per_sample, out_pair_per_sample = pair_emb( | ||
| si_input, | ||
| si, | ||
| zij, | ||
| atom_positions_predicted, | ||
| single_mask, | ||
| pair_mask, | ||
| chunk_size=4, | ||
| apply_per_sample=True, | ||
| ) | ||
|
|
||
| torch.testing.assert_close(out_single, out_single_per_sample) | ||
| torch.testing.assert_close(out_pair, out_pair_per_sample) | ||
|
|
||
| def test_pairformer_embedding_apply_per_sample_one_batch_dim_equal(self): | ||
| n_sample = 5 | ||
| n_token = consts.n_res | ||
|
|
||
| proj_entry = OF3ProjectEntry() | ||
| config = proj_entry.get_model_config_with_presets() | ||
|
|
||
| c_s_input = config.architecture.shared.c_s_input | ||
| c_s = config.architecture.shared.c_s | ||
| c_z = config.architecture.shared.c_z | ||
|
|
||
| pair_emb = PairformerEmbedding( | ||
| **config.architecture.heads.pairformer_embedding | ||
| ).eval() | ||
|
|
||
| si_input = torch.randn(1, n_token, c_s_input) | ||
| si = torch.randn(1, n_token, c_s) | ||
| zij = torch.randn(1, n_token, n_token, c_z) | ||
| atom_positions_predicted = torch.randn(n_sample, n_token, 3) | ||
| single_mask = torch.randint( | ||
| 0, | ||
| 2, | ||
| size=( | ||
| 1, | ||
| n_token, | ||
| ), | ||
| ) | ||
| pair_mask = torch.randint(0, 2, size=(1, n_token, n_token)) | ||
|
|
||
| out_single, out_pair = pair_emb( | ||
| si_input, | ||
| si, | ||
| zij, | ||
| atom_positions_predicted, | ||
| single_mask, | ||
| pair_mask, | ||
| chunk_size=4, | ||
| ) | ||
|
|
||
| out_single_per_sample, out_pair_per_sample = pair_emb( | ||
| si_input, | ||
| si, | ||
| zij, | ||
| atom_positions_predicted, | ||
| single_mask, | ||
| pair_mask, | ||
| chunk_size=4, | ||
| apply_per_sample=True, | ||
| ) | ||
|
|
||
| torch.testing.assert_close(out_single, out_single_per_sample) | ||
| torch.testing.assert_close(out_pair, out_pair_per_sample) | ||
|
|
||
|
|
||
| class TestAuxiliaryHeadsAllAtom(unittest.TestCase): | ||
| def test_auxiliary_heads_all_atom_shape(self): | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.