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

Unify LightningNodeData and LightningLinkData #6473

Merged
merged 4 commits into from
Jan 19, 2023
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 @@ -59,6 +59,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

### Changed

- Unified `LightningNodeData` and `LightningLinkData` code paths ([#6473](https://github.com/pyg-team/pytorch_geometric/pull/6473))
- Allow indices with any integer type in `RGCNConv` ([#6463](https://github.com/pyg-team/pytorch_geometric/pull/6463))
- Re-structured the documentation ([#6420](https://github.com/pyg-team/pytorch_geometric/pull/6420), [#6423](https://github.com/pyg-team/pytorch_geometric/pull/6423), [#6429](https://github.com/pyg-team/pytorch_geometric/pull/6429), [#6440](https://github.com/pyg-team/pytorch_geometric/pull/6440), [#6443](https://github.com/pyg-team/pytorch_geometric/pull/6443), [#6445](https://github.com/pyg-team/pytorch_geometric/pull/6445), [#6452](https://github.com/pyg-team/pytorch_geometric/pull/6452), [#6453](https://github.com/pyg-team/pytorch_geometric/pull/6453), [#6458](https://github.com/pyg-team/pytorch_geometric/pull/6458), [#6459](https://github.com/pyg-team/pytorch_geometric/pull/6459), [#6460](https://github.com/pyg-team/pytorch_geometric/pull/6460))
- Fix the default arguments of `DataParallel` class ([#6376](https://github.com/pyg-team/pytorch_geometric/pull/6376))
Expand Down
18 changes: 9 additions & 9 deletions test/data/lightning/test_datamodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def __init__(self, in_channels, hidden_channels, out_channels):

def forward(self, x, batch):
# Basic test to ensure that the dataset is not replicated:
self.trainer.datamodule.train_dataset.data.x.add_(1)
self.trainer.datamodule.train_dataset._data.x.add_(1)

x = self.lin1(x).relu()
x = global_mean_pool(x, batch)
Expand Down Expand Up @@ -93,14 +93,14 @@ def test_lightning_dataset(get_dataset, strategy_type):
max_epochs=1, log_every_n_steps=1)
datamodule = LightningDataset(train_dataset, val_dataset, test_dataset,
batch_size=5, num_workers=3)
old_x = train_dataset.data.x.clone()
old_x = train_dataset._data.x.clone()
assert str(datamodule) == ('LightningDataset(train_dataset=MUTAG(50), '
'val_dataset=MUTAG(30), '
'test_dataset=MUTAG(10), batch_size=5, '
'num_workers=3, pin_memory=True, '
'persistent_workers=True)')
trainer.fit(model, datamodule)
new_x = train_dataset.data.x
new_x = train_dataset._data.x
offset = 10 + 6 + 2 * devices # `train_steps` + `val_steps` + `sanity`
assert torch.all(new_x > (old_x + offset - 4)) # Ensure shared data.
if strategy_type is None:
Expand Down Expand Up @@ -274,7 +274,7 @@ def test_lightning_hetero_node_data(get_dataset):
max_epochs=5, log_every_n_steps=1)
datamodule = LightningNodeData(data, loader='neighbor', num_neighbors=[5],
batch_size=32, num_workers=3)
assert isinstance(datamodule.neighbor_sampler, NeighborSampler)
assert isinstance(datamodule.graph_sampler, NeighborSampler)
old_x = data['author'].x.clone()
trainer.fit(model, datamodule)
new_x = data['author'].x
Expand All @@ -298,12 +298,12 @@ def sample_from_nodes(self, *args, **kwargs):

datamodule = LightningNodeData(data, node_sampler=DummySampler(),
input_train_nodes=torch.arange(2))
assert isinstance(datamodule.neighbor_sampler, DummySampler)
assert isinstance(datamodule.graph_sampler, DummySampler)

datamodule = LightningLinkData(
data, link_sampler=DummySampler(),
input_train_edges=torch.tensor([[0, 1], [0, 1]]))
assert isinstance(datamodule.neighbor_sampler, DummySampler)
assert isinstance(datamodule.graph_sampler, DummySampler)


@onlyCUDA
Expand All @@ -330,7 +330,7 @@ def test_lightning_hetero_link_data():
batch_size=32,
num_workers=0,
)
assert isinstance(datamodule.neighbor_sampler, NeighborSampler)
assert isinstance(datamodule.graph_sampler, NeighborSampler)
for batch in datamodule.train_dataloader():
assert 'edge_label_index' in batch['author', 'paper']

Expand Down Expand Up @@ -404,9 +404,9 @@ def test_eval_loader_kwargs(get_dataset):
)

assert datamodule.loader_kwargs['batch_size'] == 32
assert datamodule.neighbor_sampler.num_neighbors == [5]
assert datamodule.graph_sampler.num_neighbors == [5]
assert datamodule.eval_loader_kwargs['batch_size'] == 64
assert datamodule.eval_neighbor_sampler.num_neighbors == [-1]
assert datamodule.eval_graph_sampler.num_neighbors == [-1]

train_loader = datamodule.train_dataloader()
assert math.ceil(int(data.train_mask.sum()) / 32) == len(train_loader)
Expand Down
Loading