Skip to content

Commit 213424d

Browse files
committedJun 3, 2024
Distinguish outputs from different ranks
1 parent 6d9effe commit 213424d

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed
 

‎tests/test_ddp.py

+16-3
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,29 @@ def _run_distributed(func, world_size, args: Dict, script=__file__, env=dict()):
4444

4545
for i in range(world_size):
4646
env["OMPI_COMM_WORLD_RANK"] = str(i)
47+
output = ''
4748
p = subprocess.Popen(
4849
[sys.executable, script, func, json.dumps(args)],
49-
env=env
50+
stdout=subprocess.PIPE,
51+
stderr=subprocess.STDOUT, # Combine stderr into stdout
52+
text=True,
53+
env=env,
5054
)
5155
ps.append(p)
5256

57+
outputs = []
58+
retcs = []
5359
for p in ps:
54-
p.wait()
60+
output, _ = p.communicate()
5561
retc = p.poll()
56-
assert retc == 0
62+
retcs.append(retc)
63+
outputs.append(output)
64+
65+
for i, output in enumerate(outputs):
66+
print("\n".join(map(lambda l: f"Rank {i}: {l}", output.splitlines())))
67+
68+
for i, retc in enumerate(retcs):
69+
assert retc == 0, f"Process {i} returns {retc}"
5770

5871

5972
@pytest.mark.parametrize("num_expert", [4, 8])

0 commit comments

Comments
 (0)
Please sign in to comment.