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

Support SparseTensor label in LightGCN #5046

Merged
merged 9 commits into from
Jul 30, 2022
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,5 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Fixed subclass behaviour of `process` and `download` in `Datsaet` ([#4586](https://github.com/pyg-team/pytorch_geometric/pull/4586))
- Fixed filtering of attributes for loaders in case `__cat_dim__ != 0` ([#4629](https://github.com/pyg-team/pytorch_geometric/pull/4629))
- Fixed `torch.fx` bug with `torch.nn.aggr` package ([#5021](https://github.com/pyg-team/pytorch_geometric/pull/5021)))
- Support SparseTensor label in LightGCN(#[5046](https://github.com/pyg-team/pytorch_geometric/issues/5046))
### Removed
10 changes: 9 additions & 1 deletion torch_geometric/nn/models/lightgcn.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from torch import Tensor
from torch.nn import Embedding, ModuleList
from torch.nn.modules.loss import _Loss
from torch_sparse import SparseTensor

from torch_geometric.nn.conv import LGConv
from torch_geometric.typing import Adj, OptTensor
Expand Down Expand Up @@ -110,7 +111,14 @@ def forward(self, edge_index: Adj,
:obj:`edge_index` will be used instead. (default: :obj:`None`)
"""
if edge_label_index is None:
edge_label_index = edge_index
if isinstance(edge_index, SparseTensor):
edge_label_index = torch.stack(edge_index.coo()[:2], dim=0)

elif isinstance(edge_index, torch.Tensor):

edge_label_index = edge_index
else:
raise TypeError

out = self.get_embedding(edge_index)

Expand Down