Skip to content

Enable AMP Compatibility for GCP Model to Reduce VRAM Usage #102

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

Merged
merged 3 commits into from
Apr 27, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* Add support for handling backward OOMs gracefully [#83](https://github.com/a-r-j/ProteinWorkshop/pull/83)
* Update GCPNet paper link [#85](https://github.com/a-r-j/ProteinWorkshop/pull/85)
* Add ability for `BenchmarkModel` to have its decoder disabled [#101](https://github.com/a-r-j/ProteinWorkshop/pull/101)
* Fix dtype mismatch in `gcp.py` that broke Automatic Mixed Precision (AMP) training [#102](https://github.com/a-r-j/ProteinWorkshop/pull/102)

### Framework

Expand Down
8 changes: 7 additions & 1 deletion proteinworkshop/models/graph_encoders/layers/gcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,14 +265,20 @@ def scalarize(

if node_mask is not None:
edge_mask = node_mask[row] & node_mask[col]
# Initialize destination tensor
local_scalar_rep_i = torch.zeros(
(edge_index.shape[1], 3, 3), device=edge_index.device
)
local_scalar_rep_i[edge_mask] = torch.matmul(
# Calculate the source value (result of matmul, likely Half under AMP)
matmul_result = torch.matmul(
frames[edge_mask], vector_rep_i[edge_mask]
)
# Explicitly cast the source value to the destination's dtype before assignment
local_scalar_rep_i[edge_mask] = matmul_result.to(local_scalar_rep_i.dtype)

local_scalar_rep_i = local_scalar_rep_i.transpose(-1, -2)
else:
# This path might need similar treatment if it causes issues
local_scalar_rep_i = torch.matmul(frames, vector_rep_i).transpose(-1, -2)

# potentially enable E(3)-equivariance and, thereby, chirality-invariance
Expand Down