Skip to content

Commit 90be90e

Browse files
weilrcoreyjadams
andauthored
FIGConvNet: fixed 'split_by_node_equal', supports multi-GPU execution. (NVIDIA#1375)
* FIGConvNet: fixed 'split_by_node_equal', supports multi-GPU execution. Signed-off-by: lrwei <806871005@qq.com> * Refactor: simplify loop with itertools.islice for safety and clarity * Fix precommit --------- Signed-off-by: lrwei <806871005@qq.com> Co-authored-by: Corey adams <6619961+coreyjadams@users.noreply.github.com>
1 parent bc8905d commit 90be90e

1 file changed

Lines changed: 16 additions & 11 deletions

File tree

‎examples/cfd/external_aerodynamics/figconvnet/src/data/components/webdataset_utils.py‎

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,23 @@ def split_by_node_equal(
3232
"""Splits input iterable into equal-sized chunks according to multiprocessing configuration.
3333
3434
Similar to `Webdataset.split_by_node`, but the resulting split is equal-sized.
35+
Now supports multi-GPU execution.
3536
"""
36-
37-
rank, world_size, *_ = wds.utils.pytorch_worker_info(group=group)
38-
cur = iter(src)
39-
while len(next_items := list(itertools.islice(cur, world_size))) == world_size:
40-
yield next_items[rank]
41-
42-
tail_size = len(next_items)
43-
assert tail_size < world_size
44-
# If drop_last is not set, handle the tail.
45-
if not drop_last and tail_size > 0:
46-
yield next_items[rank % tail_size]
37+
rank, world_size, worker, num_workers = wds.utils.pytorch_worker_info(group=group)
38+
39+
worker = 0 if worker is None else worker
40+
num_workers = max(1, num_workers)
41+
g_worker = rank * num_workers + worker # Global worker id.
42+
g_world = world_size * num_workers # Total number of global workers.
43+
44+
it = iter(src)
45+
for chunk in iter(lambda: list(itertools.islice(it, g_world)), []):
46+
n = len(chunk)
47+
if n < g_world: # Tail chunk.
48+
if not drop_last and g_worker < n:
49+
yield chunk[g_worker]
50+
return
51+
yield chunk[g_worker]
4752

4853

4954
def from_numpy(sample: Mapping[str, Any], key: str):

0 commit comments

Comments
 (0)