-
Notifications
You must be signed in to change notification settings - Fork 989
Partially revert broadcast-join change #20779
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
rjzamora
wants to merge
3
commits into
rapidsai:main
Choose a base branch
from
rjzamora:revert-bcast-join-simplify
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+107
−50
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ | |
| import asyncio | ||
| from typing import TYPE_CHECKING, Any, Literal | ||
|
|
||
| from rapidsmpf.memory.buffer import MemoryType | ||
| from rapidsmpf.streaming.core.message import Message | ||
| from rapidsmpf.streaming.cudf.table_chunk import TableChunk | ||
|
|
||
|
|
@@ -40,7 +41,7 @@ async def get_small_table( | |
| context: Context, | ||
| small_child: IR, | ||
| ch_small: ChannelPair, | ||
| ) -> list[DataFrame]: | ||
| ) -> tuple[list[DataFrame], int]: | ||
| """ | ||
| Get the small-table DataFrame partitions from the small-table ChannelPair. | ||
|
|
||
|
|
@@ -55,16 +56,17 @@ async def get_small_table( | |
|
|
||
| Returns | ||
| ------- | ||
| list[DataFrame] | ||
| The small-table DataFrame partitions. | ||
| The small-table DataFrame partitions and the size of the small-side in bytes. | ||
| """ | ||
| small_chunks = [] | ||
| small_size = 0 | ||
| while (msg := await ch_small.data.recv(context)) is not None: | ||
| small_chunks.append( | ||
| TableChunk.from_message(msg).make_available_and_spill( | ||
| context.br(), allow_overbooking=True | ||
| ) | ||
| ) | ||
| small_size += small_chunks[-1].data_alloc_size(MemoryType.DEVICE) | ||
| assert small_chunks, "Empty small side" | ||
|
|
||
| return [ | ||
|
|
@@ -75,7 +77,7 @@ async def get_small_table( | |
| small_chunk.stream, | ||
| ) | ||
| for small_chunk in small_chunks | ||
| ] | ||
| ], small_size | ||
|
|
||
|
|
||
| @define_py_node() | ||
|
|
@@ -88,6 +90,7 @@ async def broadcast_join_node( | |
| ch_right: ChannelPair, | ||
| broadcast_side: Literal["left", "right"], | ||
| collective_id: int, | ||
| target_partition_size: int, | ||
| ) -> None: | ||
| """ | ||
| Join node for rapidsmpf. | ||
|
|
@@ -108,8 +111,10 @@ async def broadcast_join_node( | |
| The right input ChannelPair. | ||
| broadcast_side | ||
| The side to broadcast. | ||
| collective_id: int | ||
| collective_id | ||
| Pre-allocated collective ID for this operation. | ||
| target_partition_size | ||
| The target partition size in bytes. | ||
| """ | ||
| async with shutdown_on_error( | ||
| context, | ||
|
|
@@ -156,26 +161,34 @@ async def broadcast_join_node( | |
| await ch_out.send_metadata(context, output_metadata) | ||
|
|
||
| # Collect small-side | ||
| small_df = _concat( | ||
| *await get_small_table(context, small_child, small_ch), | ||
| context=ir_context, | ||
| ) | ||
| if context.comm().nranks > 1 and not small_duplicated: | ||
| small_dfs, small_size = await get_small_table(context, small_child, small_ch) | ||
| need_allgather = context.comm().nranks > 1 and not small_duplicated | ||
| if ( | ||
| ir.options[0] != "Inner" or small_size < target_partition_size | ||
| ) and not need_allgather: | ||
| # Pre-concat for non-inner joins, otherwise | ||
| # we need a local shuffle, and face additional | ||
| # memory pressure anyway. | ||
| small_dfs = [_concat(*small_dfs, context=ir_context)] | ||
|
Comment on lines
-159
to
+172
Member
Author
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. Before #20724, we were only pre-concatenating for non-inner joins (to avoid the extra local shuffle). After #20724, we were always pre-concatenating. Now, we pre-concatenate when it makes sense:
|
||
| if need_allgather: | ||
| allgather = AllGatherManager(context, collective_id) | ||
| allgather.insert( | ||
| 0, | ||
| TableChunk.from_pylibcudf_table( | ||
| small_df.table, small_df.stream, exclusive_view=True | ||
| ), | ||
| ) | ||
| for s_id in range(len(small_dfs)): | ||
| small_df = small_dfs.pop() | ||
| allgather.insert( | ||
| s_id, | ||
| TableChunk.from_pylibcudf_table( | ||
| small_df.table, small_df.stream, exclusive_view=True | ||
| ), | ||
| ) | ||
| allgather.insert_finished() | ||
| small_table = await allgather.extract_concatenated(small_df.stream) | ||
| small_df = DataFrame.from_table( | ||
| small_table, | ||
| list(small_child.schema.keys()), | ||
| list(small_child.schema.values()), | ||
| small_df.stream, | ||
| ) | ||
| small_dfs = [ | ||
| DataFrame.from_table( | ||
| await allgather.extract_concatenated(small_df.stream), | ||
| list(small_child.schema.keys()), | ||
| list(small_child.schema.values()), | ||
| small_df.stream, | ||
| ) | ||
| ] | ||
|
|
||
| # Stream through large side, joining with the small-side | ||
| while (msg := await large_ch.data.recv(context)) is not None: | ||
|
|
@@ -191,14 +204,22 @@ async def broadcast_join_node( | |
| ) | ||
|
|
||
| # Perform the join | ||
| df = await asyncio.to_thread( | ||
| ir.do_evaluate, | ||
| *ir._non_child_args, | ||
| *( | ||
| [large_df, small_df] | ||
| if broadcast_side == "right" | ||
| else [small_df, large_df] | ||
| ), | ||
| df = _concat( | ||
| *[ | ||
| ( | ||
| await asyncio.to_thread( | ||
| ir.do_evaluate, | ||
| *ir._non_child_args, | ||
| *( | ||
| [large_df, small_df] | ||
| if broadcast_side == "right" | ||
| else [small_df, large_df] | ||
| ), | ||
| context=ir_context, | ||
| ) | ||
| ) | ||
| for small_df in small_dfs | ||
| ], | ||
| context=ir_context, | ||
| ) | ||
|
|
||
|
|
@@ -270,6 +291,12 @@ def _( | |
| else: | ||
| broadcast_side = "left" | ||
|
|
||
| # Get target partition size | ||
| config_options = rec.state["config_options"] | ||
| executor = config_options.executor | ||
| assert executor.name == "streaming", "Join node requires streaming executor" | ||
| target_partition_size = executor.target_partition_size | ||
|
|
||
| nodes[ir] = [ | ||
| broadcast_join_node( | ||
| rec.state["context"], | ||
|
|
@@ -280,6 +307,7 @@ def _( | |
| channels[right].reserve_output_slot(), | ||
| broadcast_side=broadcast_side, | ||
| collective_id=rec.state["collective_id_map"][ir], | ||
| target_partition_size=target_partition_size, | ||
| ) | ||
| ] | ||
| return nodes, channels | ||
Oops, something went wrong.
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.
All changes to this file are directly reverting #20724