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

Add partitioning for distributed training #7502

Merged
merged 23 commits into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
f4b6a55
Merge pull request #1 from kaixuanliu/master
ZhengHongming888 Jun 2, 2023
129d6eb
add partition part support for distributed training
kaixuanliu Jun 3, 2023
ce92fc1
Merge pull request #2 from kaixuanliu/master
ZhengHongming888 Jun 3, 2023
03403bf
fix bug for put_edge_id
kaixuanliu Jun 3, 2023
50238e7
add example for graph partition; change ogb dataset to fakedataset in…
kaixuanliu Jun 3, 2023
dbc2e8f
Merge pull request #3 from kaixuanliu/master
ZhengHongming888 Jun 3, 2023
6342dcd
add CHANGELOG; fix unit test error; add train_idx and test_idx partit…
kaixuanliu Jun 7, 2023
b6484ce
Merge pull request #4 from kaixuanliu/dist_partition
ZhengHongming888 Jun 7, 2023
5402762
Merge branch 'master' into dist_partition
ZhengHongming888 Jun 14, 2023
a0ce3db
adapt to new implementation of LocalFeatureStore
kaixuanliu Jun 15, 2023
640bcd8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 15, 2023
d805992
change back to original design
kaixuanliu Jun 15, 2023
ed20b1b
small change to homo graph
kaixuanliu Jun 15, 2023
5ea24ca
Merge pull request #5 from kaixuanliu/dist_partition
ZhengHongming888 Jun 15, 2023
545de3c
Merge branch 'master' into dist_partition
ZhengHongming888 Jun 15, 2023
66ff4d1
update
rusty1s Jun 16, 2023
530df3a
update
rusty1s Jun 16, 2023
94e30b2
update
rusty1s Jun 16, 2023
db889fe
delete partition example temporarily
kaixuanliu Jun 16, 2023
8032400
Merge pull request #6 from kaixuanliu/dist_partition
ZhengHongming888 Jun 16, 2023
18edf19
update
rusty1s Jun 16, 2023
f8c98e4
update
rusty1s Jun 16, 2023
89f8eb8
update
rusty1s Jun 16, 2023
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
97 changes: 97 additions & 0 deletions test/distributed/test_partition.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import os.path as osp

import torch
from ogb.nodeproppred import PygNodePropPredDataset

from torch_geometric.datasets import OGB_MAG
from torch_geometric.distributed.partition.partitioner import Partitioner
from torch_geometric.typing import EdgeTypeStr


def test_partition_homo_graph():
ogbn_dataset = "ogbn-products"
root_dir = "./data/products"
num_partitions = 2
save_dir = root_dir + "/partition"
dataset = PygNodePropPredDataset(ogbn_dataset, root_dir)
data = dataset[0]

partitioner = Partitioner(output_dir=save_dir, num_parts=num_partitions,
data=data)
partitioner.generate_partition()

node_map_path = osp.join(save_dir, 'node_map.pt')
assert osp.exists(node_map_path)
node_map = torch.load(node_map_path)
assert node_map.size(0) == data.num_nodes

edge_map_path = osp.join(save_dir, 'edge_map.pt')
assert osp.exists(edge_map_path)
edge_map = torch.load(edge_map_path)
assert edge_map.size(0) == data.num_edges

meta_path = osp.join(save_dir, 'META.json')
assert osp.exists(meta_path)

graph_store_path1 = osp.join(save_dir, 'part_0', 'graph.pt')
graph_store_path2 = osp.join(save_dir, 'part_1', 'graph.pt')
assert osp.exists(graph_store_path1)
assert osp.exists(graph_store_path2)
node_feat_path1 = osp.join(save_dir, 'part_0', 'node_feats.pt')
node_feat_path2 = osp.join(save_dir, 'part_1', 'node_feats.pt')
assert osp.exists(node_feat_path1)
assert osp.exists(node_feat_path2)
graph_store1 = torch.load(graph_store_path1)
graph_store2 = torch.load(graph_store_path2)
attr1 = graph_store1.get_all_edge_attrs()
graph1 = graph_store1.get_edge_index(attr1[0])
attr2 = graph_store2.get_all_edge_attrs()
graph2 = graph_store2.get_edge_index(attr2[0])
assert graph1[0].size(0) + graph2[0].size(0) == data.num_edges
feature_store1 = torch.load(node_feat_path1)
node_attrs1 = feature_store1.get_all_tensor_attrs()
node_feat1 = feature_store1.get_tensor(node_attrs1[0])
node_id1 = feature_store1.get_global_id(node_attrs1[0])
feature_store2 = torch.load(node_feat_path2)
node_attrs2 = feature_store2.get_all_tensor_attrs()
node_feat2 = feature_store2.get_tensor(node_attrs2[0])
node_id2 = feature_store2.get_global_id(node_attrs2[0])
assert node_feat1.size(0) + node_feat2.size(0) == data.num_nodes
assert torch.allclose(data.x[node_id1], node_feat1)
assert torch.allclose(data.x[node_id2], node_feat2)


def test_partition_hetero_graph():
ogbn_dataset = "ogbn-mags"
root_dir = "./data/mags"
num_partitions = 2
save_dir = root_dir + "/partition"
dataset = OGB_MAG(root=ogbn_dataset, preprocess='metapath2vec')
data = dataset[0]

partitioner = Partitioner(output_dir=save_dir, num_parts=num_partitions,
data=data)
partitioner.generate_partition()

meta_path = osp.join(save_dir, 'META.json')
assert osp.exists(meta_path)

for k, v in data.num_edges_dict.items():
assert len(k) == 3
edge_name = EdgeTypeStr(k)
edge_map_path = osp.join(save_dir, 'edge_map', f'{edge_name}.pt')
assert osp.exists(edge_map_path)
type_edge_map = torch.load(edge_map_path)
assert type_edge_map.size(0) == v

for k, v in data.num_nodes_dict.items():
node_map_path = osp.join(save_dir, 'node_map', f'{k}.pt')
assert osp.exists(node_map_path)
type_node_map = torch.load(node_map_path)
assert type_node_map.size(0) == v

for pid in range(num_partitions):
graph_store_path = osp.join(save_dir, f'part_{pid}', 'graph.pt')
assert osp.exists(graph_store_path)
node_feat_path = osp.join(save_dir, f'part_{pid}', 'node_feats.pt')
assert osp.exists(node_feat_path)
Loading