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

[DistGB] enable DistGraph to load graphbolt partitions #7048

Merged
merged 1 commit into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 30 additions & 10 deletions python/dgl/distributed/dist_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,21 @@ class InitGraphRequest(rpc.Request):
with shared memory.
"""

def __init__(self, graph_name):
def __init__(self, graph_name, use_graphbolt):
self._graph_name = graph_name
self._use_graphbolt = use_graphbolt

def __getstate__(self):
return self._graph_name
return self._graph_name, self._use_graphbolt

def __setstate__(self, state):
self._graph_name = state
self._graph_name, self._use_graphbolt = state

def process_request(self, server_state):
if server_state.graph is None:
server_state.graph = _get_graph_from_shared_mem(self._graph_name)
server_state.graph = _get_graph_from_shared_mem(
self._graph_name, self._use_graphbolt
)
return InitGraphResponse(self._graph_name)


Expand Down Expand Up @@ -153,13 +156,15 @@ def _exist_shared_mem_array(graph_name, name):
return exist_shared_mem_array(_get_edata_path(graph_name, name))


def _get_graph_from_shared_mem(graph_name):
def _get_graph_from_shared_mem(graph_name, use_graphbolt):
"""Get the graph from the DistGraph server.

The DistGraph server puts the graph structure of the local partition in the shared memory.
The client can access the graph structure and some metadata on nodes and edges directly
through shared memory to reduce the overhead of data access.
"""
if use_graphbolt:
return gb.load_from_shared_memory(graph_name)
g, ntypes, etypes = heterograph_index.create_heterograph_from_shared_memory(
graph_name
)
Expand Down Expand Up @@ -524,6 +529,8 @@ class DistGraph:
part_config : str, optional
The path of partition configuration file generated by
:py:meth:`dgl.distributed.partition.partition_graph`. It's used in the standalone mode.
use_graphbolt : bool, optional
Whether to load GraphBolt partition. Default: False.

Examples
--------
Expand Down Expand Up @@ -557,9 +564,15 @@ class DistGraph:
manually setting up servers and trainers. The setup is not fully tested yet.
"""

def __init__(self, graph_name, gpb=None, part_config=None):
def __init__(
self, graph_name, gpb=None, part_config=None, use_graphbolt=False
):
self.graph_name = graph_name
self._use_graphbolt = use_graphbolt
if os.environ.get("DGL_DIST_MODE", "standalone") == "standalone":
assert (
use_graphbolt is False
), "GraphBolt is not supported in standalone mode."
assert (
part_config is not None
), "When running in the standalone model, the partition config file is required"
Expand Down Expand Up @@ -600,7 +613,9 @@ def __init__(self, graph_name, gpb=None, part_config=None):
self._init(gpb)
# Tell the backup servers to load the graph structure from shared memory.
for server_id in range(self._client.num_servers):
rpc.send_request(server_id, InitGraphRequest(graph_name))
rpc.send_request(
server_id, InitGraphRequest(graph_name, use_graphbolt)
)
for server_id in range(self._client.num_servers):
rpc.recv_response()
self._client.barrier()
Expand All @@ -625,7 +640,9 @@ def _init(self, gpb):
assert (
self._client is not None
), "Distributed module is not initialized. Please call dgl.distributed.initialize."
self._g = _get_graph_from_shared_mem(self.graph_name)
self._g = _get_graph_from_shared_mem(
self.graph_name, self._use_graphbolt
)
self._gpb = get_shared_mem_partition_book(self.graph_name)
if self._gpb is None:
self._gpb = gpb
Expand Down Expand Up @@ -682,10 +699,10 @@ def _init_edata_store(self):
self._edata_store[etype] = data

def __getstate__(self):
return self.graph_name, self._gpb
return self.graph_name, self._gpb, self._use_graphbolt

def __setstate__(self, state):
self.graph_name, gpb = state
self.graph_name, gpb, self._use_graphbolt = state
self._init(gpb)

self._init_ndata_store()
Expand Down Expand Up @@ -1230,6 +1247,9 @@ def find_edges(self, edges, etype=None):
tensor
The destination node ID array.
"""
assert (
self._use_graphbolt is False
), "find_edges is not supported in GraphBolt."
if etype is None:
assert (
len(self.etypes) == 1
Expand Down
Loading
Loading