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

Allow models to use a lightweight sparse structure #3782

Merged
merged 7 commits into from
Aug 17, 2023

Conversation

tingyu66
Copy link
Member

@tingyu66 tingyu66 commented Aug 11, 2023

This PR introduces SparseGraph class to allow SAGEConv to use a more lightweight graph structure. The goal is to provide an option to bypass to_block which is the bottleneck in the sampling workflow.

I will submit another PR to extend the pattern to other models.

@VibhuJawa
Copy link
Member

I think this works for us and we should priortize getting this done properly soon

@tingyu66 tingyu66 self-assigned this Aug 15, 2023
@tingyu66 tingyu66 added improvement Improvement / enhancement to an existing function non-breaking Non-breaking change labels Aug 15, 2023
@tingyu66 tingyu66 marked this pull request as ready for review August 15, 2023 03:16
@tingyu66 tingyu66 added this to the 23.10 milestone Aug 15, 2023
Copy link
Member

@VibhuJawa VibhuJawa left a comment

Choose a reason for hiding this comment

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

The overall implementation looks great. Thanks for prioritizing work on this.

Have asked a couple of followups and minor code changes.

ops_torch = import_optional("pylibcugraphops.pytorch")


class BaseConv(nn.Module):
class BaseConv(torch.nn.Module):
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

This is not a user-facing class. It is only used to handle the case where we fall back to full graph variant. In addition, with the recent cugraph-ops refactoring disabling the MFG-variant, we might totally remove this class.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, I am sorry, I left the review at wrong line. I meant SparseGraph class

Copy link
Member

Choose a reason for hiding this comment

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

Resolved

Comment on lines +69 to +73
csrc_ids: torch.Tensor, optional
Compressed source indices. It is a monotonically increasing array of
size (num_src_nodes + 1,). For the k-th source node, its neighborhood
consists of the destinations between `dst_indices[csrc_indices[k]]` and
`dst_indices[csrc_indices[k+1]]`.
Copy link
Member

Choose a reason for hiding this comment

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

I have a question regarding when num_dst_nodes > len(cdst_ids)-1 for this case.

Lets look at below case:

cdst_ids (Compressed Destinations Indices):0,2,5,7
src_indices: 1,2,2,3,4,4,5

I believe following will work (please correct me):

num_src_nodes = 6
num_dst_nodes = 3 

And i guess below will fail ((please correct me):

num_src_nodes = 6
num_dst_nodes = 5 # Modified it to a higher value to ensure alignment for output nodes that are missing

Question:
So this will have to handled by ensuring correct creation because we want to handle alignment problem b/w blocks.

Copy link
Member Author

Choose a reason for hiding this comment

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

It should be illegal when num_dst_nodes != len(cdst_ids)-1. I will improve the error handling in this case. For example, pyg does lots of assertions to check the size. We should throw proper exceptions.

cdst_ids (Compressed Destinations Indices):0,2,5,7
src_indices: 1,2,2,3,4,4,5

In your example with num_src_nodes = 6, num_dst_nodes = 3, this translates to a COO of
(1,2,2,3,4,4,5)
(0,0,1,1,1,2,2)

With num_src_nodes = 6, num_dst_nodes = 5, the constructor should have failed, unless cdst_ids is augmented (cdst_ids = 0,2,5,7,7,7).

Copy link
Member

Choose a reason for hiding this comment

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

Thanks. Yup, this is what i was expecting. We will just make sure that the changes @seunghwak from cugraph sampling ensures that all the MFGs line up.

self.num_dst_nodes,
out_int32=self._dst_ids.dtype == torch.int32,
)

Copy link
Member

Choose a reason for hiding this comment

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

Do you think we should remove dst_ids if we are forcing CSC conversion because that will mean memory overhead of maintaining it always ?

Copy link
Member

Choose a reason for hiding this comment

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

I think if we are forcing csc conversions for now but in future we may want to expand to other formats right, I think we might want to either have this configurable via a class variable.

We can probably borrow the convention from formats.

We wont follow their default of 'coo' -> 'csr' -> 'csc', but have our own version.

See formats docs .

Copy link
Member Author

Choose a reason for hiding this comment

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

As we discussed via slack, we will provide input_format and output_format to help specify which tensor is needed.

Comment on lines 86 to 88
COO-format requires `src_ids` and `dst_ids`.
CSC-format requires `cdst_ids` and `src_ids`.
CSR-format requires `csrc_ids` and `dst_ids`.
Copy link
Member

Choose a reason for hiding this comment

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

I think we should force user to provide the format requirement to prevent confusion. Like add a format variable something like input_format which will take values coo, csc and csr.

Then we can raise errors according to the input what the user provided.

Also, i dont like input_format variable name but you get the idea.

python/cugraph-dgl/cugraph_dgl/nn/conv/sageconv.py Outdated Show resolved Hide resolved
@tingyu66 tingyu66 marked this pull request as draft August 15, 2023 14:22
@tingyu66
Copy link
Member Author

@VibhuJawa Please review it again. Here are some example usages. The formats option denotes the layouts users want to create. I chose not to add an "input_format" because it is redundant. The kwargs already carries the information, and __init__() gets unnecessarily complicated with it. The reduce_memory flag does what you suggested -- removing unused tensors from class.

Copy link
Member

@VibhuJawa VibhuJawa left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for making these changes quickly @tingyu66 . I think the PR is good to merge.

ops_torch = import_optional("pylibcugraphops.pytorch")


class BaseConv(nn.Module):
class BaseConv(torch.nn.Module):
Copy link
Member

Choose a reason for hiding this comment

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

Resolved

@alexbarghi-nv
Copy link
Member

@tingyu66 should this still be in draft? It seems to be ready for review.

@tingyu66 tingyu66 marked this pull request as ready for review August 16, 2023 21:05
@tingyu66
Copy link
Member Author

@tingyu66 should this still be in draft? It seems to be ready for review.

Yes, it's ready. Forgot to click the button.

@BradReesWork
Copy link
Member

/merge

@rapids-bot rapids-bot bot merged commit a3bb1fb into rapidsai:branch-23.10 Aug 17, 2023
55 checks passed
@tingyu66 tingyu66 deleted the bypass_dgl_class branch August 23, 2023 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement Improvement / enhancement to an existing function non-breaking Non-breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants