Skip to content

Commit

Permalink
Support SparseTensor label in LightGCN (#5046)
Browse files Browse the repository at this point in the history
* fix the bug of models/lightgcn when edge_indx is an instance of SparseTensor in forward method

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update CHANGELOG.md

* Update torch_geometric/nn/models/lightgcn.py

Co-authored-by: Matthias Fey <matthias.fey@tu-dortmund.de>

* Update CHANGELOG.md

* Update lightgcn.py

drop all tensor.is_sparse

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* update

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Matthias Fey <matthias.fey@tu-dortmund.de>
  • Loading branch information
3 people authored Jul 30, 2022
1 parent 25ff6d9 commit 1d89adf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

## [2.0.5] - 2022-MM-DD
### Added
- Support `SparseTensor` as edge label in `LightGCN` (#[5046](https://github.com/pyg-team/pytorch_geometric/issues/5046))
- Added support for `BasicGNN` models within `to_hetero` ([#5091](https://github.com/pyg-team/pytorch_geometric/pull/5091))
- Added support for computing weighted metapaths in `AddMetapaths` ([#5049](https://github.com/pyg-team/pytorch_geometric/pull/5049))
- Added inference benchmark suite ([#4915](https://github.com/pyg-team/pytorch_geometric/pull/4915))
Expand Down
6 changes: 5 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,10 @@ 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)
else:
edge_label_index = edge_index

out = self.get_embedding(edge_index)

Expand Down

0 comments on commit 1d89adf

Please sign in to comment.