Skip to content
Open
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
10 changes: 6 additions & 4 deletions orb_models/common/atoms/batch/graph_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def __init__(
# repeat_interleave, e.g. tensor[node_batch_index] instead of tensor.repeat_interleave(n_node)
self.node_batch_index = torch.arange(
self.n_node.shape[0], dtype=torch.int64, device=self.n_node.device
).repeat_interleave(self.n_node)
).repeat_interleave(self.n_node, output_size=self.positions.shape[0])

def split(self: _T, clone=True) -> list["AtomGraphs"]:
"""Splits batched AtomGraphs into constituent system AtomGraphs.
Expand Down Expand Up @@ -218,11 +218,12 @@ def _get_per_node_graph_indices(self):
TODO: we could cache these indices.
"""
positions = self.node_features["positions"]
graph_indices = torch.zeros(len(positions), device=positions.device, dtype=torch.int)
n_atoms = positions.shape[0]
graph_indices = torch.zeros(n_atoms, device=positions.device, dtype=torch.int)
cumsums = torch.cumsum(self.n_node, dim=0)
graph_indices[:] = torch.searchsorted(
cumsums,
torch.arange(len(positions), device=positions.device),
torch.arange(n_atoms, device=positions.device),
right=True,
)
return graph_indices # (natoms,)
Expand All @@ -234,9 +235,10 @@ def _get_per_edge_graph_indices(self):
"""
graph_indices = torch.zeros_like(self.senders) # (nedges,)
cumsums = torch.cumsum(self.n_edge, dim=0) # (ngraphs,)
n_edges = self.senders.shape[0]
graph_indices[:] = torch.searchsorted(
cumsums,
torch.arange(len(self.senders), device=self.senders.device),
torch.arange(n_edges, device=self.senders.device),
right=True,
)
return graph_indices # (nedges,)
Expand Down
4 changes: 2 additions & 2 deletions orb_models/common/models/segment_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def aggregate_nodes(
# assert n_node.sum() == tensor.shape[0]

device = tensor.device
count = len(n_node)
count = n_node.shape[0]
if deterministic:
import os

Expand All @@ -40,7 +40,7 @@ def aggregate_nodes(
https://docs.nvidia.com/cuda/cublas/index.html#cublasApi_reproducibility"""
os.environ["CUBLAS_WORKSPACE_CONFIG"] = ":4096:8"
torch.use_deterministic_algorithms(True)
segments = torch.arange(count, device=device).repeat_interleave(n_node)
segments = torch.arange(count, device=device).repeat_interleave(n_node, output_size=tensor.shape[0])
if reduction == "sum":
return scatter_sum(tensor, segments, dim=0, dim_size=count)
elif reduction == "mean":
Expand Down