"tests/git@developer.sourcefind.cn:OpenDAS/dgl.git" did not exist on "ae97049e6ccd4cfaebdc911ecd79407fc2a5ffc6"
Unverified Commit a19e0efd authored by Ramon Zhou's avatar Ramon Zhou Committed by GitHub
Browse files

[GraphBolt] Modify the doc string of DistributedItemSampler (#6420)

parent 7d87dcec
...@@ -345,6 +345,10 @@ class DistributedItemSampler(ItemSampler): ...@@ -345,6 +345,10 @@ class DistributedItemSampler(ItemSampler):
counterparts. The original item set is sharded such that each replica counterparts. The original item set is sharded such that each replica
(process) receives an exclusive subset. (process) receives an exclusive subset.
Note: DistributedItemSampler may not work as expected when it is the last
datapipe before the data is fetched. Please wrap a SingleProcessDataLoader
or another datapipe on it.
Note: The items will be first sharded onto each replica, then get shuffled Note: The items will be first sharded onto each replica, then get shuffled
(if needed) and batched. Therefore, each replica will always get a same set (if needed) and batched. Therefore, each replica will always get a same set
of items. of items.
...@@ -387,48 +391,97 @@ class DistributedItemSampler(ItemSampler): ...@@ -387,48 +391,97 @@ class DistributedItemSampler(ItemSampler):
Examples Examples
-------- --------
1. num_replica = 4, batch_size = 2, shuffle = False, drop_last = False, 0. Preparation: DistributedItemSampler needs multi-processing environment to
drop_uneven_inputs = False, item_set = [0, 1, 2, ..., 7, 8, 9] work. You need to spawn subprocesses and initialize processing group before
- Replica#0 gets [[0, 4], [8]] executing following examples. Due to randomness, the output is not always
- Replica#1 gets [[1, 5], [9]] the same as listed below.
- Replica#2 gets [[2, 6]]
- Replica#3 gets [[3, 7]] >>> import torch
>>> from dgl import graphbolt as gb
2. num_replica = 4, batch_size = 2, shuffle = False, drop_last = True, >>> item_set = gb.ItemSet(torch.arange(0, 13))
drop_uneven_inputs = False, item_set = [0, 1, 2, ..., 7, 8, 9]. >>> num_replicas = 4
- Replica#0 gets [[0, 4]] >>> batch_size = 2
- Replica#1 gets [[1, 5]] >>> mp.spawn(...)
- Replica#2 gets [[2, 6]]
- Replica#3 gets [[3, 7]] 1. shuffle = False, drop_last = False, drop_uneven_inputs = False.
3. num_replica = 4, batch_size = 2, shuffle = False, drop_last = True, >>> item_sampler = gb.DistributedItemSampler(
drop_uneven_inputs = False, item_set = [0, 1, 2, ..., 11, 12, 13]. >>> item_set, batch_size=2, shuffle=False, drop_last=False,
- Replica#0 gets [[0, 4], [8, 12]] >>> drop_uneven_inputs=False
- Replica#1 gets [[1, 5], [9, 13]] >>> )
- Replica#2 gets [[2, 6]] >>> data_loader = gb.SingleProcessDataLoader(item_sampler)
- Replica#3 gets [[3, 7]] >>> print(f"Replica#{proc_id}: {list(data_loader)})
Replica#0: [tensor([0, 4]), tensor([ 8, 12])]
3. num_replica = 4, batch_size = 2, shuffle = False, drop_last = False, Replica#1: [tensor([1, 5]), tensor([ 9, 13])]
drop_uneven_inputs = True, item_set = [0, 1, 2, ..., 11, 12, 13]. Replica#2: [tensor([2, 6]), tensor([10])]
- Replica#0 gets [[0, 4], [8, 12]] Replica#3: [tensor([3, 7]), tensor([11])]
- Replica#1 gets [[1, 5], [9, 13]]
- Replica#2 gets [[2, 6], [10]] 2. shuffle = False, drop_last = True, drop_uneven_inputs = False.
- Replica#3 gets [[3, 7], [11]]
>>> item_sampler = gb.DistributedItemSampler(
4. num_replica = 4, batch_size = 2, shuffle = False, drop_last = True, >>> item_set, batch_size=2, shuffle=False, drop_last=True,
drop_uneven_inputs = True, item_set = [0, 1, 2, ..., 11, 12, 13]. >>> drop_uneven_inputs=False
- Replica#0 gets [[0, 4]] >>> )
- Replica#1 gets [[1, 5]] >>> data_loader = gb.SingleProcessDataLoader(item_sampler)
- Replica#2 gets [[2, 6]] >>> print(f"Replica#{proc_id}: {list(data_loader)})
- Replica#3 gets [[3, 7]] Replica#0: [tensor([0, 4]), tensor([ 8, 12])]
Replica#1: [tensor([1, 5]), tensor([ 9, 13])]
5. num_replica = 4, batch_size = 2, shuffle = True, drop_last = True, Replica#2: [tensor([2, 6])]
drop_uneven_inputs = False, item_set = [0, 1, 2, ..., 11, 12, 13]. Replica#3: [tensor([3, 7])]
One possible output:
- Replica#0 gets [[8, 0], [12, 4]] 3. shuffle = False, drop_last = False, drop_uneven_inputs = True.
- Replica#1 gets [[13, 1], [9, 5]]
- Replica#2 gets [[10, 2]] >>> item_sampler = gb.DistributedItemSampler(
- Replica#3 gets [[7, 11]] >>> item_set, batch_size=2, shuffle=False, drop_last=False,
>>> drop_uneven_inputs=True
>>> )
>>> data_loader = gb.SingleProcessDataLoader(item_sampler)
>>> print(f"Replica#{proc_id}: {list(data_loader)})
Replica#0: [tensor([0, 4]), tensor([ 8, 12])]
Replica#1: [tensor([1, 5]), tensor([ 9, 13])]
Replica#2: [tensor([2, 6]), tensor([10])]
Replica#3: [tensor([3, 7]), tensor([11])]
4. shuffle = False, drop_last = True, drop_uneven_inputs = True.
>>> item_sampler = gb.DistributedItemSampler(
>>> item_set, batch_size=2, shuffle=False, drop_last=True,
>>> drop_uneven_inputs=True
>>> )
>>> data_loader = gb.SingleProcessDataLoader(item_sampler)
>>> print(f"Replica#{proc_id}: {list(data_loader)})
Replica#0: [tensor([0, 4])]
Replica#1: [tensor([1, 5])]
Replica#2: [tensor([2, 6])]
Replica#3: [tensor([3, 7])]
5. shuffle = True, drop_last = True, drop_uneven_inputs = False.
>>> item_sampler = gb.DistributedItemSampler(
>>> item_set, batch_size=2, shuffle=True, drop_last=True,
>>> drop_uneven_inputs=False
>>> )
>>> data_loader = gb.SingleProcessDataLoader(item_sampler)
>>> print(f"Replica#{proc_id}: {list(data_loader)})
(One possible output:)
Replica#0: [tensor([0, 8]), tensor([ 4, 12])]
Replica#1: [tensor([ 5, 13]), tensor([9, 1])]
Replica#2: [tensor([ 2, 10])]
Replica#3: [tensor([11, 7])]
6. shuffle = True, drop_last = True, drop_uneven_inputs = True.
>>> item_sampler = gb.DistributedItemSampler(
>>> item_set, batch_size=2, shuffle=True, drop_last=True,
>>> drop_uneven_inputs=True
>>> )
>>> data_loader = gb.SingleProcessDataLoader(item_sampler)
>>> print(f"Replica#{proc_id}: {list(data_loader)})
(One possible output:)
Replica#0: [tensor([8, 0])]
Replica#1: [tensor([ 1, 13])]
Replica#2: [tensor([10, 6])]
Replica#3: [tensor([ 3, 11])]
""" """
def __init__( def __init__(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment