Skip to content
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

Empty cache before we run folding #47

Merged
merged 5 commits into from
Sep 13, 2024
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion chai_lab/chai1.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,9 @@ def run_folding_on_context(
if device is None:
device = torch.device("cuda:0")

# Clear memory
torch.cuda.empty_cache()

##
## Validate inputs
##
Expand Down Expand Up @@ -443,6 +446,9 @@ def run_folding_on_context(
token_single_mask=token_single_mask,
token_pair_mask=token_pair_mask,
)
# We won't be using the trunk anymore; remove it from memory
del trunk
torch.cuda.empty_cache()

##
## Denoise the trunk representation by passing it through the diffusion module
Expand Down Expand Up @@ -534,6 +540,10 @@ def _denoise(atom_pos: Tensor, sigma: Tensor, s: int) -> Tensor:
d_i_prime = (atom_pos - denoised_pos) / sigma_next
atom_pos = atom_pos + (sigma_next - sigma_hat) * ((d_i_prime + d_i) / 2)

# We won't be running diffusion anymore
del diffusion_module
torch.cuda.empty_cache()

##
## Run the confidence model
##
Expand Down Expand Up @@ -610,6 +620,11 @@ def avg_per_token_1d(x):
##
## Write the outputs
##
# Move data to the CPU so we don't hit GPU memory limits
inputs = move_data_to_device(inputs, torch.device("cpu"))
atom_pos = atom_pos.cpu()
plddt_logits = plddt_logits.cpu()
pae_logits = pae_logits.cpu()

# Plot coverage of tokens by MSA, save plot
output_dir.mkdir(parents=True, exist_ok=True)
Expand Down Expand Up @@ -671,7 +686,7 @@ def avg_per_token_1d(x):
write_pdbs_from_outputs(
coords=atom_pos[idx : idx + 1],
bfactors=scaled_plddt_scores_per_atom,
output_batch=move_data_to_device(inputs, torch.device("cpu")),
output_batch=inputs,
write_path=pdb_out_path,
)
output_paths.append(pdb_out_path)
Expand Down
Loading