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

[FEA] Allow sampling per edge type in Uniform Neighbor Sample #2696

Closed
Tracked by #4351 ...
VibhuJawa opened this issue Sep 13, 2022 · 2 comments
Closed
Tracked by #4351 ...

[FEA] Allow sampling per edge type in Uniform Neighbor Sample #2696

VibhuJawa opened this issue Sep 13, 2022 · 2 comments
Assignees
Labels
feature request New feature or request

Comments

@VibhuJawa
Copy link
Member

VibhuJawa commented Sep 13, 2022

Describe the solution you'd like and any additional context

We should allow sampling per edge type in uniform neighbor sample. After PR 2660 we have graph with type values.

I believe we should include an argument like do_fanout_per_type and sample fan_out number of edges for each seed node for every edge type.

Context:

DGL Behaviour:
DGL when sampling neighbors on Heterogeneous Graphs uses type information and by default samples fanout value per type . See below example.

import dgl
import torch as th

graph_data = {
        ('drug', 'interacts', 'drug'): (th.tensor([0,1,2]), th.tensor([3,4,5])),
        ('drug', 'treats', 'disease'): (th.tensor([0,1,2]), th.tensor([6,7,8])),
        ('gene', 'treats', 'disease'): (th.tensor([10,11,12]), th.tensor([6,7,8]))
        }
g = dgl.heterograph(graph_data)

frontier_0 = g.sample_neighbors(nodes={'drug':th.tensor([0]) }, fanout=1, edge_dir='out')
for etype in frontier_0.canonical_etypes:
    print(etype,frontier_0.edges(etype=etype))
('drug', 'interacts', 'drug') (tensor([0]), tensor([3]))
('drug', 'treats', 'disease') (tensor([0]), tensor([6]))
('gene', 'treats', 'disease') (tensor([], dtype=torch.int64), tensor([], dtype=torch.int64))

From DGL API docs (link)

fanout (int or dict[etype, int]) –
The number of edges to be sampled for each node on each edge type.

This argument can take a single int or a dictionary of edge types and ints.
If a single int is given, DGL will sample this number of edges "for each node for every edge type".

If -1 is given for a single edge type, all the neighboring edges with that edge type will be selected.

cuGraph current behavior:

import cudf
import cugraph
df = cudf.DataFrame({'source':[0,1,2,0,1,2,10,11,12],
                     'destination':[3,4,5,6,7,8,6,7,8],
                     'type': [0,0,0,1,1,1,2,2,2]
                     # 0- ('drug', 'interacts', 'drug')
                     # 1-('drug', 'treats', 'disease')
                     # 2-('gene', 'treats', 'disease')
                    })


G = cugraph.MultiGraph(directed=True)
G.from_cudf_edgelist(df, edge_attr='type')

sample_df = cugraph.uniform_neighbor_sample(
    G,
    cudf.Series([0]),
    fanout_vals=[1],
    is_edge_ids=False
)
sample_df = sample_df.rename(columns={'indices':'type'})
 # 0- ('drug', 'interacts', 'drug')
 # 1-('drug', 'treats', 'disease')
 # 2-('gene', 'treats', 'disease')
print(sample_df)
   type  sources  destinations
0     0        0             3

cuGraph requested feature

After PR 2660 we have graph with type values. #2660, we incude an argument like do_fanout_per_type and sample fanoout number of edges for each seed node for every edge type.

sample_df = cugraph.uniform_neighbor_sample(
    G,
    cudf.Series([0]),
    fanout_vals=[1],
    do_fanout_per_type = True
    is_edge_ids=False
)
   type  sources  destinations
0     0        0             3
1     1        0             6

Alternate work-around

We store n_etypes views of the data and do the sampling call for each edge type individually which will be slow because we will make n_etypes calls.

CC: @ChuckHastings , @seunghwak , @alexbarghi-nv

CC: @rlratzel, @BradReesWork

@VibhuJawa VibhuJawa added the ? - Needs Triage Need team to review and classify label Sep 13, 2022
@VibhuJawa VibhuJawa added this to the 22.10 milestone Sep 13, 2022
@BradReesWork BradReesWork removed the ? - Needs Triage Need team to review and classify label Sep 14, 2022
@BradReesWork BradReesWork modified the milestones: 22.10, 22.12 Sep 19, 2022
@github-actions
Copy link

This issue has been labeled inactive-30d due to no recent activity in the past 30 days. Please close this issue if no further response or action is needed. Otherwise, please respond with a comment indicating any updates or changes to the original issue and/or confirm this issue still needs to be addressed. This issue will be labeled inactive-90d if there is no activity in the next 60 days.

@ChuckHastings
Copy link
Collaborator

Implementation being handled by #4589

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants