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 PyTorch SparseTensor support for GINConv, SAGEConv, and GraphConv #6532

Merged
merged 7 commits into from
Jan 28, 2023
Merged
Show file tree
Hide file tree
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
Prev Previous commit
Next Next commit
update
  • Loading branch information
EdisonLeeeee committed Jan 27, 2023
commit 2c2ccf42517d868c5881715c6abbe7086289283e
6 changes: 3 additions & 3 deletions torch_geometric/nn/conv/gin_conv.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ def forward(self, x: Union[Tensor, OptPairTensor], edge_index: Adj,
def message(self, x_j: Tensor) -> Tensor:
return x_j

def message_and_aggregate(self, adj_t: SparseTensor,
x: OptPairTensor) -> Tensor:
adj_t = adj_t.set_value(None, layout=None)
def message_and_aggregate(self, adj_t: Adj, x: OptPairTensor) -> Tensor:
if isinstance(adj_t, SparseTensor):
adj_t = adj_t.set_value(None, layout=None)
return spmm(adj_t, x[0], reduce=self.aggr)

def __repr__(self) -> str:
Expand Down
4 changes: 1 addition & 3 deletions torch_geometric/nn/conv/graph_conv.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from typing import Tuple, Union

from torch import Tensor
from torch_sparse import SparseTensor

from torch_geometric.nn.conv import MessagePassing
from torch_geometric.nn.dense.linear import Linear
Expand Down Expand Up @@ -90,6 +89,5 @@ def forward(self, x: Union[Tensor, OptPairTensor], edge_index: Adj,
def message(self, x_j: Tensor, edge_weight: OptTensor) -> Tensor:
return x_j if edge_weight is None else edge_weight.view(-1, 1) * x_j

def message_and_aggregate(self, adj_t: SparseTensor,
x: OptPairTensor) -> Tensor:
def message_and_aggregate(self, adj_t: Adj, x: OptPairTensor) -> Tensor:
return spmm(adj_t, x[0], reduce=self.aggr)
6 changes: 3 additions & 3 deletions torch_geometric/nn/conv/sage_conv.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ def forward(self, x: Union[Tensor, OptPairTensor], edge_index: Adj,
def message(self, x_j: Tensor) -> Tensor:
return x_j

def message_and_aggregate(self, adj_t: SparseTensor,
x: OptPairTensor) -> Tensor:
adj_t = adj_t.set_value(None, layout=None)
def message_and_aggregate(self, adj_t: Adj, x: OptPairTensor) -> Tensor:
if isinstance(adj_t, SparseTensor):
adj_t = adj_t.set_value(None, layout=None)
return spmm(adj_t, x[0], reduce=self.aggr)

def __repr__(self) -> str:
Expand Down