Skip to content

Commit

Permalink
Merge branch 'master' into type_hints/ToDense
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastian-montero authored Oct 12, 2022
2 parents 191e366 + 6bda075 commit d8aeeab
Show file tree
Hide file tree
Showing 12 changed files with 206 additions and 65 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/full_testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,13 @@ jobs:
- name: Install internal dependencies
run: |
pip install pyg-lib -f https://data.pyg.org/whl/nightly/torch-${{ matrix.torch-version }}+cpu.html
pip install torch-scatter torch-sparse torch-cluster torch-spline-conv -f https://data.pyg.org/whl/torch-${{ matrix.torch-version }}+cpu.html
- name: Install pyg-lib
if: ${{ runner.os == 'Linux' }} # pyg-lib is currently only available on Linux.
run: |
pip install pyg-lib -f https://data.pyg.org/whl/nightly/torch-${{ matrix.torch-version }}+cpu.html
- name: Install main package
run: |
pip install -e .[full,test]
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ jobs:
matrix:
os: [ubuntu-latest]
python-version: [3.9]
torch-version: [1.11.0, 1.12.0]
torch-version: [1.12.0]
include:
- torch-version: 1.11.0
torchvision-version: 0.12.0
- torch-version: 1.12.0
torchvision-version: 0.13.0

Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Added `BaseStorage.get()` functionality ([#5240](https://github.com/pyg-team/pytorch_geometric/pull/5240))
- Added a test to confirm that `to_hetero` works with `SparseTensor` ([#5222](https://github.com/pyg-team/pytorch_geometric/pull/5222))
### Changed
- Support `in_channels` with `tuple` in `GENConv` for bipartite message passing ([#5627](https://github.com/pyg-team/pytorch_geometric/pull/5627), [#5641](https://github.com/pyg-team/pytorch_geometric/pull/5641))
- Handle cases of not having enough possible negative edges in `RandomLinkSplit` ([#5642](https://github.com/pyg-team/pytorch_geometric/pull/5642))
- Fix `RGCN+pyg-lib` for `LongTensor` input ([#5610](https://github.com/pyg-team/pytorch_geometric/pull/5610))
- Improved type hint support ([#5603](https://github.com/pyg-team/pytorch_geometric/pull/5603))
- Avoid modifying `mode_kwargs` in `MultiAggregation` ([#5601](https://github.com/pyg-team/pytorch_geometric/pull/5601))
Expand Down
41 changes: 40 additions & 1 deletion test/nn/conv/test_gen_conv.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def test_gen_conv(aggr):
adj1 = SparseTensor(row=row, col=col, sparse_sizes=(4, 4))
adj2 = SparseTensor(row=row, col=col, value=value, sparse_sizes=(4, 4))

conv = GENConv(16, 32, aggr)
conv = GENConv(16, 32, aggr, edge_dim=16)
assert conv.__repr__() == f'GENConv(16, 32, aggr={aggr})'
out11 = conv(x1, edge_index)
assert out11.size() == (4, 32)
Expand Down Expand Up @@ -74,3 +74,42 @@ def test_gen_conv(aggr):
jit = torch.jit.script(conv.jittable(t))
assert torch.allclose(jit((x1, x2), adj1.t()), out21, atol=1e-6)
assert torch.allclose(jit((x1, x2), adj2.t()), out22, atol=1e-6)

x1 = torch.randn(4, 8)
x2 = torch.randn(2, 16)
adj = adj1.sparse_resize((4, 2))
conv = GENConv((8, 16), 32, aggr)
assert str(conv) == f'GENConv((8, 16), 32, aggr={aggr})'
out1 = conv((x1, x2), edge_index)
out2 = conv((x1, None), edge_index, size=(4, 2))
assert out1.size() == (2, 32)
assert out2.size() == (2, 32)
assert conv((x1, x2), edge_index, size=(4, 2)).tolist() == out1.tolist()
assert conv((x1, x2), adj.t()).tolist() == out1.tolist()
assert conv((x1, None), adj.t()).tolist() == out2.tolist()

value = torch.randn(row.size(0), 4)
adj = SparseTensor(row=row, col=col, value=value, sparse_sizes=(4, 2))
conv = GENConv((-1, -1), 32, aggr, edge_dim=-1)
assert str(conv) == f'GENConv((-1, -1), 32, aggr={aggr})'
out1 = conv((x1, x2), edge_index, value)
out2 = conv((x1, None), edge_index, value, size=(4, 2))
assert out1.size() == (2, 32)
assert out2.size() == (2, 32)
assert conv((x1, x2), edge_index, value,
size=(4, 2)).tolist() == out1.tolist()
assert conv((x1, x2), adj.t()).tolist() == out1.tolist()
assert conv((x1, None), adj.t()).tolist() == out2.tolist()

if is_full_test():
t = '(OptPairTensor, Tensor, Size) -> Tensor'
jit = torch.jit.script(conv.jittable(t))
assert jit((x1, x2), edge_index).tolist() == out1.tolist()
assert jit((x1, x2), edge_index, size=(4, 2)).tolist() == out1.tolist()
assert jit((x1, None), edge_index,
size=(4, 2)).tolist() == out2.tolist()

t = '(OptPairTensor, SparseTensor, Size) -> Tensor'
jit = torch.jit.script(conv.jittable(t))
assert jit((x1, x2), adj.t()).tolist() == out1.tolist()
assert jit((x1, None), adj.t()).tolist() == out2.tolist()
38 changes: 19 additions & 19 deletions test/nn/conv/test_rgcn_conv.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ def test_rgcn_conv_equality(conf):
edge_type = torch.tensor([0, 1, 1, 0, 0, 1, 2, 3, 3, 2, 2, 3])

torch.manual_seed(12345)
conv1 = RGCNConv(4, 32, 4, num_bases, num_blocks)
conv1 = RGCNConv(4, 32, 4, num_bases, num_blocks, aggr='sum')

torch.manual_seed(12345)
conv2 = FastRGCNConv(4, 32, 4, num_bases, num_blocks)
conv2 = FastRGCNConv(4, 32, 4, num_bases, num_blocks, aggr='sum')

out1 = conv1(x1, edge_index, edge_type)
out2 = conv2(x1, edge_index, edge_type)
Expand All @@ -54,50 +54,50 @@ def test_rgcn_conv(cls, conf):
row, col = edge_index
adj = SparseTensor(row=row, col=col, value=edge_type, sparse_sizes=(4, 4))

conv = cls(4, 32, 2, num_bases, num_blocks)
conv = cls(4, 32, 2, num_bases, num_blocks, aggr='sum')
assert conv.__repr__() == f'{cls.__name__}(4, 32, num_relations=2)'
out1 = conv(x1, edge_index, edge_type)
assert out1.size() == (4, 32)
assert conv(x1, adj.t()).tolist() == out1.tolist()
assert torch.allclose(conv(x1, adj.t()), out1, atol=1e-6)

if num_blocks is None:
out2 = conv(None, edge_index, edge_type)
assert out2.size() == (4, 32)
assert conv(None, adj.t()).tolist() == out2.tolist()
assert torch.allclose(conv(None, adj.t()), out2, atol=1e-6)

if is_full_test():
t = '(OptTensor, Tensor, OptTensor) -> Tensor'
jit = torch.jit.script(conv.jittable(t))
assert jit(x1, edge_index, edge_type).tolist() == out1.tolist()
assert torch.allclose(jit(x1, edge_index, edge_type), out1)
if num_blocks is None:
assert jit(idx1, edge_index, edge_type).tolist() == out2.tolist()
assert jit(None, edge_index, edge_type).tolist() == out2.tolist()
assert torch.allclose(jit(idx1, edge_index, edge_type), out2)
assert torch.allclose(jit(None, edge_index, edge_type), out2)

t = '(OptTensor, SparseTensor, OptTensor) -> Tensor'
jit = torch.jit.script(conv.jittable(t))
assert jit(x1, adj.t()).tolist() == out1.tolist()
assert torch.allclose(jit(x1, adj.t()), out1)
if num_blocks is None:
assert jit(idx1, adj.t()).tolist() == out2.tolist()
assert jit(None, adj.t()).tolist() == out2.tolist()
assert torch.allclose(jit(idx1, adj.t()), out2, atol=1e-6)
assert torch.allclose(jit(None, adj.t()), out2, atol=1e-6)

adj = adj.sparse_resize((4, 2))
conv = cls((4, 16), 32, 2, num_bases, num_blocks)
conv = cls((4, 16), 32, 2, num_bases, num_blocks, aggr='sum')
assert conv.__repr__() == f'{cls.__name__}((4, 16), 32, num_relations=2)'
out1 = conv((x1, x2), edge_index, edge_type)
assert out1.size() == (2, 32)
assert conv((x1, x2), adj.t()).tolist() == out1.tolist()
assert torch.allclose(conv((x1, x2), adj.t()), out1, atol=1e-6)

if num_blocks is None:
out2 = conv((None, idx2), edge_index, edge_type)
assert out2.size() == (2, 32)
assert torch.allclose(conv((idx1, idx2), edge_index, edge_type), out2)
assert conv((None, idx2), adj.t()).tolist() == out2.tolist()
assert conv((idx1, idx2), adj.t()).tolist() == out2.tolist()
assert torch.allclose(conv((None, idx2), adj.t()), out2, atol=1e-6)
assert torch.allclose(conv((idx1, idx2), adj.t()), out2, atol=1e-6)

if is_full_test():
t = '(Tuple[OptTensor, Tensor], Tensor, OptTensor) -> Tensor'
jit = torch.jit.script(conv.jittable(t))
assert jit((x1, x2), edge_index, edge_type).tolist() == out1.tolist()
assert torch.allclose(jit((x1, x2), edge_index, edge_type), out1)
if num_blocks is None:
assert torch.allclose(jit((None, idx2), edge_index, edge_type),
out2)
Expand All @@ -106,7 +106,7 @@ def test_rgcn_conv(cls, conf):

t = '(Tuple[OptTensor, Tensor], SparseTensor, OptTensor) -> Tensor'
jit = torch.jit.script(conv.jittable(t))
assert jit((x1, x2), adj.t()).tolist() == out1.tolist()
assert torch.allclose(jit((x1, x2), adj.t()), out1, atol=1e-6)
if num_blocks is None:
assert jit((None, idx2), adj.t()).tolist() == out2.tolist()
assert jit((idx1, idx2), adj.t()).tolist() == out2.tolist()
assert torch.allclose(jit((None, idx2), adj.t()), out2, atol=1e-6)
assert torch.allclose(jit((idx1, idx2), adj.t()), out2, atol=1e-6)
4 changes: 2 additions & 2 deletions test/nn/test_to_hetero_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ def test_to_hetero_with_basic_model():

class GraphConv(MessagePassing):
def __init__(self, in_channels, out_channels):
super().__init__(aggr='mean')
super().__init__(aggr='sum')
self.lin = Linear(in_channels, out_channels, bias=False)

def reset_parameters(self):
Expand Down Expand Up @@ -351,7 +351,7 @@ def test_to_hetero_and_rgcn_equal_output():
edge_type[(row >= 6) & (col < 6)] = 2
assert edge_type.min() == 0

conv = RGCNConv(16, 32, num_relations=3)
conv = RGCNConv(16, 32, num_relations=3, aggr='sum')
out1 = conv(x, edge_index, edge_type)

# Run `to_hetero`:
Expand Down
14 changes: 14 additions & 0 deletions test/transforms/test_random_link_split.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,17 @@ def test_random_link_split_on_undirected_hetero_data():
rev_edge_types=('p', 'p'))
train_data, val_data, test_data = transform(data)
assert train_data['p', 'p'].is_undirected()


def test_random_link_split_insufficient_negative_edges():
edge_index = torch.tensor([[0, 0, 1, 1, 2, 2], [1, 3, 0, 2, 0, 1]])
data = Data(edge_index=edge_index, num_nodes=4)

transform = RandomLinkSplit(num_val=0.34, num_test=0.34,
is_undirected=False, neg_sampling_ratio=2,
split_labels=True)
train_data, val_data, test_data = transform(data)

assert train_data.neg_edge_label_index.size() == (2, 2)
assert val_data.neg_edge_label_index.size() == (2, 2)
assert test_data.neg_edge_label_index.size() == (2, 2)
2 changes: 1 addition & 1 deletion torch_geometric/nn/aggr/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Aggregation(torch.nn.Module):
# Assign each element to one of three sets:
index = torch.tensor([0, 0, 1, 0, 2, 0, 2, 1, 0, 2])
output = aggr(x, index) # Output shape: [4, 64]
output = aggr(x, index) # Output shape: [3, 64]
Alternatively, aggregation can be achieved via a "compressed" index vector
called :obj:`ptr`. Here, elements within the same set need to be grouped
Expand Down
Loading

0 comments on commit d8aeeab

Please sign in to comment.