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

refactor(sampler): consolidate link neighbor sampling interface, part 2 #5365

Merged
merged 41 commits into from
Sep 8, 2022

Conversation

mananshah99
Copy link
Contributor

@mananshah99 mananshah99 commented Sep 7, 2022

This PR continues the effort to consolidate PyG's sampling interface in preparation for moving sample(...) behind the GraphStore interface. This effort is somewhat large in scope and will be broken into multiple PRs for ease of review. It resolves some TODOs from #5312, and introduces others that will be resolved in follow-up PRs.

The major change removes LinkNeighborSampler, consolidating it under a the common BaseSampler interface with NeighborSampler. In doing so, it modifies the BaseSampler interface to support sample_from_nodes and sample_from_edges, since oftentimes edge-based sampling applies some transformations and then re-uses the same logic as node-based sampling. A sampler need not define both node-based and edge-based sampling, but if it doesn't, an appropriate error will be raised.

Resolved TODOs:

  • LinkNeighborSampler and NeighborSampler interfaces are aligned
  • No more special handling of edge_type_to_str in filter_*
  • No more special handling of perm_dict, which removes the need for edge_type_to_str entirely

@github-actions github-actions bot added the data label Sep 7, 2022
@codecov
Copy link

codecov bot commented Sep 7, 2022

Codecov Report

Merging #5365 (88e2764) into master (005f993) will increase coverage by 0.04%.
The diff coverage is 100.00%.

❗ Current head 88e2764 differs from pull request most recent head b5d1b6e. Consider uploading reports for the commit b5d1b6e to get more accurate results

@@            Coverage Diff             @@
##           master    #5365      +/-   ##
==========================================
+ Coverage   83.35%   83.39%   +0.04%     
==========================================
  Files         342      342              
  Lines       18771    18771              
==========================================
+ Hits        15646    15654       +8     
+ Misses       3125     3117       -8     
Impacted Files Coverage Δ
torch_geometric/data/lightning_datamodule.py 49.12% <100.00%> (+0.29%) ⬆️
torch_geometric/loader/hgt_loader.py 91.93% <100.00%> (+0.26%) ⬆️
torch_geometric/loader/link_neighbor_loader.py 91.30% <100.00%> (-2.69%) ⬇️
torch_geometric/loader/neighbor_loader.py 90.80% <100.00%> (ø)
torch_geometric/loader/utils.py 81.25% <100.00%> (-1.51%) ⬇️
torch_geometric/sampler/base.py 100.00% <100.00%> (+3.70%) ⬆️
torch_geometric/sampler/neighbor_sampler.py 97.33% <100.00%> (+6.42%) ⬆️
torch_geometric/sampler/utils.py 97.01% <100.00%> (+2.57%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Base automatically changed from remote_backend_2 to master September 7, 2022 19:59
@mananshah99 mananshah99 marked this pull request as ready for review September 7, 2022 21:45
@mananshah99 mananshah99 requested review from wsad1, rusty1s, a team and Padarn September 7, 2022 21:48
Copy link
Member

@rusty1s rusty1s left a comment

Choose a reason for hiding this comment

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

This looks perfect :)

torch_geometric/sampler/base.py Outdated Show resolved Hide resolved
Copy link
Member

@wsad1 wsad1 left a comment

Choose a reason for hiding this comment

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

Thanks. This looks good.

torch_geometric/sampler/neighbor_sampler.py Show resolved Hide resolved
torch_geometric/sampler/neighbor_sampler.py Show resolved Hide resolved
torch_geometric/sampler/utils.py Outdated Show resolved Hide resolved
torch_geometric/loader/link_neighbor_loader.py Outdated Show resolved Hide resolved
@Padarn
Copy link
Contributor

Padarn commented Sep 10, 2022

Didn't get around to reviewing before merged.. but all looks great to me :-)

mananshah99 added a commit that referenced this pull request Sep 12, 2022
This PR continues the effort to consolidate PyG's sampling interface in preparation for moving `sample(...)` behind the `GraphStore` interface. This effort is somewhat large in scope and will be broken into multiple PRs for ease of review. It resolves some TODOs from #5365.

The major change removes special handling of `input_type` and `perm` / `perm_dict` in the neighbor loader. This enables a full separation between the sampler interface and the NeighborLoader (the only other interaction that is not clearly documented or exposed well in the sampler class is `SamplerOutput.metadata`, which will take a bit more work to properly define.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants