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

Fix LinkNeighborLoader producing double-sized edge_label_time for homogeneous graphs #7807

Merged
merged 16 commits into from
Jul 31, 2023
Merged
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

### Changed

- Fixed `edge_label_time` computation in `LinkNeighborLoader` for homogeneous graphs ([#7807](https://github.com/pyg-team/pytorch_geometric/pull/7807))
- Fixed `edge_label_index` computation in `LinkNeighborLoader` for the homogeneous+`disjoint` mode ([#7791](https://github.com/pyg-team/pytorch_geometric/pull/7791))
- Fixed `CaptumExplainer` for `binary_classification` tasks ([#7787](https://github.com/pyg-team/pytorch_geometric/pull/7787))
- Warn user when using the `training` flag in `to_hetero` modules ([#7772](https://github.com/pyg-team/pytorch_geometric/pull/7772))
Expand Down
28 changes: 28 additions & 0 deletions test/loader/test_link_neighbor_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,34 @@ def test_link_neighbor_loader_edge_label():
assert torch.all(batch.edge_label[10:] == 0)


@withPackage("pyg_lib")
def test_temporal_homo_link_neighbor_loader():
data = Data(
x=torch.randn(10, 5),
edge_index=torch.randint(0, 10, (2, 1234)),
edge_time=torch.arange(1234),
edge_label=torch.ones(1234),
)

batch_size = 1
loader = LinkNeighborLoader(
data,
num_neighbors=[-1],
time_attr="edge_time",
edge_label_time=data.edge_time,
batch_size=batch_size,
shuffle=True,
)

for sample in loader:
assert sample.edge_label_index.size() == (2, batch_size)
assert sample.edge_label_time.size() == (batch_size, )
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before this PR, the size of edge_label_time was (2*batch_size, ).

assert sample.edge_label.size() == (batch_size, )
assert torch.all(
sample.edge_time <= sample.edge_label_time
), "The target time should be later than all timestamps in the subgraph"


@withPackage('pyg_lib')
def test_temporal_hetero_link_neighbor_loader():
data = HeteroData()
Expand Down
2 changes: 1 addition & 1 deletion torch_geometric/sampler/neighbor_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ def edge_sample(
else:
edge_label_index = inverse_seed.view(2, -1)

out.metadata = (input_id, edge_label_index, edge_label, seed_time)
out.metadata = (input_id, edge_label_index, edge_label, src_time)

elif neg_sampling.is_triplet():
if disjoint:
Expand Down