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

Fix errors of the RevGNN example #4715

Merged
merged 2 commits into from
May 25, 2022
Merged
Changes from 1 commit
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
7 changes: 4 additions & 3 deletions examples/rev_gnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

class GNNBlock(torch.nn.Module):
def __init__(self, in_channels, out_channels):
super().__init__(in_channels)
super().__init__()
self.norm = LayerNorm(in_channels, elementwise_affine=True)
self.conv = SAGEConv(in_channels, out_channels)

Expand Down Expand Up @@ -48,7 +48,7 @@ def __init__(self, in_channels, hidden_channels, out_channels, num_layers,

assert hidden_channels % num_groups == 0
self.convs = torch.nn.ModuleList()
for _ in range(self.num_layers):
for _ in range(num_layers):
conv = GNNBlock(
hidden_channels // num_groups,
hidden_channels // num_groups,
Expand All @@ -63,14 +63,15 @@ def reset_parameters(self):
conv.reset_parameters()

def forward(self, x, edge_index):
x = self.lin1(x)

# Generate a dropout mask which will be shared across GNN blocks:
mask = None
if self.training and self.dropout > 0:
mask = torch.zeros_like(x).bernoulli_(1 - self.dropout)
mask = mask.requires_grad_(False)
mask = mask / (1 - self.dropout)

x = self.lin1(x)
for conv in self.convs:
x = conv(x, edge_index, mask)
x = self.norm(x).relu()
Expand Down