Fix template offload helpers for long-sequence inference#574
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 #489.
This PR repairs the monomer template memory-saving paths used by long-sequence inference.
embed_templates_offloadandembed_templates_averagenow call template submodules through the actual owner,model.template_embedder, instead of looking for stale direct attributes onAlphaFold.Root Cause
AlphaFoldconstructs monomer template machinery as aTemplateEmbedderinstance atself.template_embedder. The normal template path already uses that object, but the offload and average helper functions still calledmodel.template_pair_embedder,model.template_pair_stack,model.template_pointwise_att, andmodel.template_single_embedderdirectly. Enablinglong_sequence_inference=Trueturns on template offload, so the stale direct access raises:Changes
embed_templates_offloadandembed_templates_averagethroughmodel.template_embedder.*.model.globalsand template-specific config on the template embedder config.inplace_safefinal mask branch.sys.getrefcountassertion from the offload helper.trace_utils.pyto usemodel.template_embedder.template_pair_stack.Validation
Validated in an isolated worktree. The local macOS environment does not have the compiled OpenFold attention extension installed, so I used a disposable
/private/tmptest venv and a test-only stub for the optionalattn_core_inplace_cudaimport; the tested code path does not call that extension.Commands run:
PYTHONPATH=/private/tmp/openfold-issue-489-test-stubs:/private/tmp/openfold-issue-489-template-offload /private/tmp/openfold-issue-489-test-venv/bin/python -m unittest tests.test_template.TemplateOffloadRegression PYTHONPATH=/private/tmp/openfold-issue-489-test-stubs:/private/tmp/openfold-issue-489-template-offload /private/tmp/openfold-issue-489-test-venv/bin/python -m unittest tests.test_template python -m py_compile openfold/model/template.py openfold/utils/trace_utils.py tests/test_template.py git diff --check rg -n "model\\.template_(pair_embedder|pair_stack|pointwise_att|single_embedder)|getrefcount|import sys" openfold/model/template.py openfold/utils/trace_utils.pyResults:
TemplateOffloadRegression: 3 tests passedtests.test_template: 7 tests passed, 2 skipped