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 eval_loader_kwargs in lightning modules #6456

Merged
merged 3 commits into from
Jan 18, 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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

### Added

- Added option to customize loader arguments for evaluation in `LightningNodeData` and `LightningLinkData` ([#6450](https://github.com/pyg-team/pytorch_geometric/pull/6450))
- Added option to customize loader arguments for evaluation in `LightningNodeData` and `LightningLinkData` ([#6450](https://github.com/pyg-team/pytorch_geometric/pull/6450), [#6456](https://github.com/pyg-team/pytorch_geometric/pull/6456))
- Added option to customize `num_neighbors` in `NeighborSampler` after instantiation ([#6446](https://github.com/pyg-team/pytorch_geometric/pull/6446))
- Added the `Taobao` dataset and a corresponding example for it ([#6144](https://github.com/pyg-team/pytorch_geometric/pull/6144))
- Added `pyproject.toml` ([#6431](https://github.com/pyg-team/pytorch_geometric/pull/6431))
Expand Down
34 changes: 12 additions & 22 deletions torch_geometric/data/lightning/datamodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,29 +372,24 @@ def __init__(

# Determine validation sampler and loader arguments ###################

self.eval_loader_kwargs = copy.copy(self.loader_kwargs)
if eval_loader_kwargs is not None:
# The user wants to override certain values during evaluation, so
# If the user wants to override certain values during evaluation,
# we shallow-copy the sampler and update its attributes.

if hasattr(self, 'neighbor_sampler'):
self.eval_neighbor_sampler = copy.copy(self.neighbor_sampler)
self.eval_loader_kwargs = copy.copy(self.loader_kwargs)

eval_sampler_kwargs, eval_loader_kwargs = split_kwargs(
eval_loader_kwargs,
self.neighbor_sampler.__class__,
)
for key, value in eval_sampler_kwargs.items():
setattr(self.eval_neighbor_sampler, key, value)
self.eval_loader_kwargs.update(eval_loader_kwargs)
else:
self.eval_loader_kwargs = copy.copy(self.loader_kwargs)
self.eval_loader_kwargs.update(eval_loader_kwargs)
else:
if hasattr(self, 'neighbor_sampler'):
self.eval_neighbor_sampler = self.neighbor_sampler

self.eval_loader_kwargs = self.loader_kwargs
self.eval_loader_kwargs.update(eval_loader_kwargs)

elif hasattr(self, 'neighbor_sampler'):
self.eval_neighbor_sampler = self.neighbor_sampler

self.eval_loader_kwargs.pop('sampler', None)
self.eval_loader_kwargs.pop('batch_sampler', None)
Expand Down Expand Up @@ -689,29 +684,24 @@ def __init__(

# Determine validation sampler and loader arguments ###################

self.eval_loader_kwargs = copy.copy(self.loader_kwargs)
if eval_loader_kwargs is not None:
# The user wants to override certain values during evaluation, so
# If the user wants to override certain values during evaluation,
# we shallow-copy the sampler and update its attributes.

if hasattr(self, 'neighbor_sampler'):
self.eval_neighbor_sampler = copy.copy(self.neighbor_sampler)
self.eval_loader_kwargs = copy.copy(self.loader_kwargs)

eval_sampler_kwargs, eval_loader_kwargs = split_kwargs(
eval_loader_kwargs,
self.neighbor_sampler.__class__,
)
for key, value in eval_sampler_kwargs.items():
setattr(self.eval_neighbor_sampler, key, value)
self.eval_loader_kwargs.update(eval_loader_kwargs)
else:
self.eval_loader_kwargs = copy.copy(self.loader_kwargs)
self.eval_loader_kwargs.update(eval_loader_kwargs)
else:
if hasattr(self, 'neighbor_sampler'):
self.eval_neighbor_sampler = self.neighbor_sampler

self.eval_loader_kwargs = self.loader_kwargs
self.eval_loader_kwargs.update(eval_loader_kwargs)

elif hasattr(self, 'neighbor_sampler'):
self.eval_neighbor_sampler = self.neighbor_sampler

self.eval_loader_kwargs.pop('sampler', None)
self.eval_loader_kwargs.pop('batch_sampler', None)
Expand Down