Skip to content

Bi-directional Sampling for NeighborSampler #10126

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

Open
wants to merge 44 commits into
base: master
Choose a base branch
from

Conversation

zaristei
Copy link
Contributor

@zaristei zaristei commented Mar 19, 2025

This PR makes the following changes:

  • Modifies NeighborSampler so that sampling can occur from src to dst node, and not just from dst to src node, which is the current default behavior.
  • Adds a new sampler called BidirectionalNeighborSampler, which samples nodes/edges in both upstream and downstream directions for a directed graph, as if it were an undirected graph.
  • Add merge_with and collate methods to the SamplerOutput dataclass, allowing for different SamplerOutputs to be merged together. This also becomes useful in scenarios where the user may want to sample using multiple different unique sampling methods.

This PR will remain in draft until methods are also implemented on the corresponding Hetero graph classes, and unittests have been written to cover new behaviors.
UPDATE: Hetero Bidirectional Sampler and SamplerOutput merge will be a separate PR.

@puririshi98
Copy link
Contributor

looks good so far

puririshi98 added a commit that referenced this pull request Apr 2, 2025
While working on [this
PR](#10126), I noticed
that there are no sanity tests for the default NeighborSampler. Although
NeigborLoader effectively tests a lot of this functionality, having
lower level tests helps with ensuring consistency for each `sample` call
of the sampler, without the batching logic of `NeighborLoader` getting
involved.

---------

Co-authored-by: Zack Aristei <[email protected]>
Co-authored-by: Rishi Puri <[email protected]>
@puririshi98 puririshi98 marked this pull request as ready for review April 2, 2025 01:04
@puririshi98 puririshi98 requested review from wsad1, mananshah99 and a team as code owners April 2, 2025 01:04
@zaristei zaristei force-pushed the zaristei/bidirectional-sampler branch 2 times, most recently from fdf6450 to c9eab32 Compare April 3, 2025 18:52
@zaristei zaristei force-pushed the zaristei/bidirectional-sampler branch 2 times, most recently from d2506c8 to 9adc7b9 Compare April 11, 2025 23:51
@puririshi98
Copy link
Contributor

closing since matthias said theres an existing simple way to do this. please jsut put the fix into my branch:
#9992

@puririshi98 puririshi98 reopened this Apr 14, 2025
Copy link
Contributor

@puririshi98 puririshi98 left a comment

Choose a reason for hiding this comment

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

LGTM but i will request that @akihironitta or @rusty1s review this

@zaristei zaristei force-pushed the zaristei/bidirectional-sampler branch 2 times, most recently from e288d28 to d99fb71 Compare April 16, 2025 03:30
@zaristei
Copy link
Contributor Author

#10200 should be merged first

Copy link

codecov bot commented Apr 16, 2025

Codecov Report

Attention: Patch coverage is 92.83276% with 21 lines in your changes missing coverage. Please review.

Project coverage is 85.46%. Comparing base (c211214) to head (4e18c78).
Report is 15 commits behind head on master.

Files with missing lines Patch % Lines
torch_geometric/sampler/neighbor_sampler.py 87.28% 15 Missing ⚠️
torch_geometric/sampler/utils.py 82.85% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #10126      +/-   ##
==========================================
- Coverage   86.11%   85.46%   -0.65%     
==========================================
  Files         496      496              
  Lines       33655    34129     +474     
==========================================
+ Hits        28981    29169     +188     
- Misses       4674     4960     +286     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@zaristei zaristei force-pushed the zaristei/bidirectional-sampler branch from e6b47d0 to a2c6b11 Compare April 22, 2025 19:32
# Conflicts:
#	test/sampler/test_sampler_base.py
#	torch_geometric/sampler/base.py
@zaristei zaristei force-pushed the zaristei/bidirectional-sampler branch from 889e316 to f5333cf Compare April 22, 2025 20:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants