-
Notifications
You must be signed in to change notification settings - Fork 314
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
[REVIEW] python 2D shuffling #1133
Merged
BradReesWork
merged 10 commits into
rapidsai:branch-0.16
from
Iroy30:python_2D_pipeline
Sep 25, 2020
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7fc6400
add shuffle for 2D partitioning
Iroy30 6e32c22
Update CHANGELOG.md
BradReesWork a9f5298
Update CHANGELOG.md
BradReesWork a776f9e
shuffle updates as per review
Iroy30 86874e6
Merge branch 'python_2D_pipeline' of https://github.com/Iroy30/cugrap…
Iroy30 541e7c6
updated changelog
BradReesWork f1c0430
flake8
Iroy30 4a2d034
Merge branch 'python_2D_pipeline' of https://github.com/Iroy30/cugrap…
Iroy30 4ba9572
add transposed
Iroy30 baaec00
Merge branch 'branch-0.16' into python_2D_pipeline
Iroy30 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import math | ||
from dask.dataframe.shuffle import rearrange_by_column | ||
import cudf | ||
|
||
|
||
def get_n_workers(): | ||
from dask.distributed import default_client | ||
client = default_client() | ||
return len(client.scheduler_info()['workers']) | ||
|
||
|
||
def get_2D_div(ngpus): | ||
pcols = int(math.sqrt(ngpus)) | ||
while ngpus % pcols != 0: | ||
pcols = pcols - 1 | ||
return int(ngpus/pcols), pcols | ||
Comment on lines
+12
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Python code to find prows and pcols |
||
|
||
|
||
def _set_partitions_pre(df, vertex_row_partitions, vertex_col_partitions, | ||
prows, pcols, transposed): | ||
if transposed: | ||
r = df['dst'] | ||
c = df['src'] | ||
else: | ||
r = df['src'] | ||
c = df['dst'] | ||
r_div = vertex_row_partitions.searchsorted(r, side='right')-1 | ||
c_div = vertex_col_partitions.searchsorted(c, side='right')-1 | ||
partitions = r_div % prows + c_div * prows | ||
return partitions | ||
|
||
|
||
def shuffle(dg, transposed=False, prows=None, pcols=None): | ||
""" | ||
Shuffles the renumbered input distributed graph edgelist into ngpu | ||
partitions. The number of processes/gpus P = prows*pcols. The 2D | ||
partitioning divides the matrix into P*pcols rectangular partitions | ||
as per vertex partitioning performed in renumbering, and then shuffles | ||
these partitions into P gpus. | ||
""" | ||
|
||
ddf = dg.edgelist.edgelist_df | ||
ngpus = get_n_workers() | ||
if prows is None and pcols is None: | ||
prows, pcols = get_2D_div(ngpus) | ||
else: | ||
if prows is not None and pcols is not None: | ||
if ngpus != prows*pcols: | ||
raise Exception('prows*pcols should be equal to the\ | ||
number of processes') | ||
elif prows is not None: | ||
if ngpus % prows != 0: | ||
raise Exception('prows must be a factor of the number\ | ||
of processes') | ||
pcols = int(ngpus/prows) | ||
elif pcols is not None: | ||
if ngpus % pcols != 0: | ||
raise Exception('pcols must be a factor of the number\ | ||
of processes') | ||
prows = int(ngpus/pcols) | ||
|
||
renumber_vertex_count = dg.renumber_map.implementation.\ | ||
ddf.map_partitions(len).compute() | ||
renumber_vertex_cumsum = renumber_vertex_count.cumsum() | ||
src_dtype = ddf['src'].dtype | ||
dst_dtype = ddf['dst'].dtype | ||
|
||
vertex_row_partitions = cudf.Series([0], dtype=src_dtype) | ||
vertex_row_partitions = vertex_row_partitions.append(cudf.Series( | ||
renumber_vertex_cumsum, dtype=src_dtype)) | ||
num_verts = vertex_row_partitions.iloc[-1] | ||
vertex_col_partitions = [] | ||
for i in range(pcols + 1): | ||
vertex_col_partitions.append(vertex_row_partitions.iloc[i*prows]) | ||
vertex_col_partitions = cudf.Series(vertex_col_partitions, dtype=dst_dtype) | ||
|
||
meta = ddf._meta._constructor_sliced([0]) | ||
partitions = ddf.map_partitions( | ||
_set_partitions_pre, | ||
vertex_row_partitions=vertex_row_partitions, | ||
vertex_col_partitions=vertex_col_partitions, prows=prows, | ||
pcols=pcols, transposed=transposed, meta=meta) | ||
ddf2 = ddf.assign(_partitions=partitions) | ||
ddf3 = rearrange_by_column( | ||
ddf2, | ||
"_partitions", | ||
max_branch=None, | ||
npartitions=ngpus, | ||
shuffle="tasks", | ||
ignore_index=True, | ||
).drop(columns=["_partitions"]) | ||
|
||
return ddf3, num_verts, vertex_row_partitions |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Too lazy today to sit down and do math, but we should be able to directly compute this without a while loop.