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

Add bias to TAGConv #4597

Merged
merged 2 commits into from
May 5, 2022
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 @@ -9,5 +9,6 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Added support for graph-level outputs in `to_hetero` ([#4582](https://github.com/pyg-team/pytorch_geometric/pull/4582))
- Added `CHANGELOG.md` ([#4581](https://github.com/pyg-team/pytorch_geometric/pull/4581))
### Changed
- The `bias` argument in `TAGConv` is now actually apllied ([#4597](https://github.com/pyg-team/pytorch_geometric/pull/4597))
- Fixed subclass behaviour of `process` and `download` in `Datsaet` ([#4586](https://github.com/pyg-team/pytorch_geometric/pull/4586))
### Removed
16 changes: 14 additions & 2 deletions torch_geometric/nn/conv/tag_conv.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from torch_geometric.nn.conv import MessagePassing
from torch_geometric.nn.conv.gcn_conv import gcn_norm
from torch_geometric.nn.dense.linear import Linear
from torch_geometric.nn.inits import zeros
from torch_geometric.typing import Adj, OptTensor


Expand Down Expand Up @@ -51,14 +52,21 @@ def __init__(self, in_channels: int, out_channels: int, K: int = 3,
self.K = K
self.normalize = normalize

self.lins = torch.nn.ModuleList(
[Linear(in_channels, out_channels) for _ in range(K + 1)])
self.lins = torch.nn.ModuleList([
Linear(in_channels, out_channels, bias=False) for _ in range(K + 1)
])

if bias:
self.bias = torch.nn.Parameter(torch.Tensor(out_channels))
else:
self.register_parameter('bias', None)

self.reset_parameters()

def reset_parameters(self):
for lin in self.lins:
lin.reset_parameters()
zeros(self.bias)

def forward(self, x: Tensor, edge_index: Adj,
edge_weight: OptTensor = None) -> Tensor:
Expand All @@ -80,6 +88,10 @@ def forward(self, x: Tensor, edge_index: Adj,
x = self.propagate(edge_index, x=x, edge_weight=edge_weight,
size=None)
out += lin.forward(x)

if self.bias is not None:
out += self.bias

return out

def message(self, x_j: Tensor, edge_weight: OptTensor) -> Tensor:
Expand Down