Skip to content

fix: Use batch in GraphNorm #68

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
13 changes: 7 additions & 6 deletions ocpmodels/models/faenet.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""
Code of the Scalable Frame Averaging (Rotation Invariant) GNN
"""
from typing import Dict, Optional

from typing import Optional

import torch
import torch.nn.functional as F
Expand Down Expand Up @@ -240,7 +241,7 @@ def reset_parameters(self):
nn.init.xavier_uniform_(self.lin_h.weight)
self.lin_h.bias.data.fill_(0)

def forward(self, h, edge_index, e):
def forward(self, h, edge_index, e, batch=None):
# Define edge embedding

if self.dropout_lin > 0:
Expand All @@ -264,7 +265,7 @@ def forward(self, h, edge_index, e):
h = self.act(self.lin_down(h)) # downscale node rep.
h = self.propagate(edge_index, x=h, W=e) # propagate
if self.graph_norm:
h = self.act(self.graph_norm(h))
h = self.act(self.graph_norm(h, batch=batch))
h = F.dropout(
h, p=self.dropout_lin, training=self.training or self.deup_inference
)
Expand All @@ -279,7 +280,7 @@ def forward(self, h, edge_index, e):
e = self.lin_geom(e)
h = self.propagate(edge_index, x=h, W=e) # propagate
if self.graph_norm:
h = self.act(self.graph_norm(h))
h = self.act(self.graph_norm(h, batch=batch))
h = torch.cat((h, chi), dim=1)
h = F.dropout(
h, p=self.dropout_lin, training=self.training or self.deup_inference
Expand All @@ -289,7 +290,7 @@ def forward(self, h, edge_index, e):
elif self.mp_type in {"base", "simple"}:
h = self.propagate(edge_index, x=h, W=e) # propagate
if self.graph_norm:
h = self.act(self.graph_norm(h))
h = self.act(self.graph_norm(h, batch=batch))
h = F.dropout(
h, p=self.dropout_lin, training=self.training or self.deup_inference
)
Expand Down Expand Up @@ -739,7 +740,7 @@ def energy_forward(self, data, q=None):
self.first_trainable_layer.split("_")[1]
):
q = h.clone().detach()
h = h + interaction(h, edge_index, e)
h = h + interaction(h, edge_index, e, batch)

# Atom skip-co
if self.skip_co == "concat_atom":
Expand Down