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

process_group: add PG init timeouts + automatically assign manager port #60

Merged
merged 1 commit into from
Jan 9, 2025

Conversation

d4l3k
Copy link
Member

@d4l3k d4l3k commented Jan 8, 2025

This does two things:

  1. add PG init timeouts for ProcessGroupGloo and ProcessGroupBabyGloo/NCCL -- this does not add a timeout for ProcessGroupNCCL as it doesn't block on initialization so we can rely on our existing future timeouts
  2. automatically assigns the manager port rather than requiring it to be manually set

Test plan:

pytest torchft/process_group_test.py

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jan 8, 2025
Comment on lines 150 to 156

if port is None:
port_str = os.environ.get(MANAGER_PORT_ENV)
if port_str is None:
port = 0
else:
port = int(port_str)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it make sense to set the default value to 0? Would save these few lines and looks cleaner imo

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, thanks for the suggestion!

@d4l3k d4l3k force-pushed the d4l3k/pg_timeouts branch from 64eb94a to b1c3692 Compare January 9, 2025 19:55
@d4l3k d4l3k marked this pull request as ready for review January 9, 2025 19:57
@d4l3k d4l3k changed the title process_group: add PG timeouts + automatically assign manager port process_group: add PG init timeouts + automatically assign manager port Jan 9, 2025
Comment on lines +132 to +135
pg = ProcessGroupGloo(timeout=timedelta(seconds=0.01))
with self.assertRaisesRegex(RuntimeError, "timeout after 10ms"):
pg.configure(store_addr, 0, 2)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would an assert that the time taken to raise the timeout is now much smaller than the default be good here? Would make sure that future code does not break the ability for the wrapper to set the underlying PG creation timeout.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to compare to the default -- the message includes the time (in this case 10ms)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok I see. All good then

Comment on lines 203 to 207
a = ProcessGroupBabyGloo(timeout=timedelta(seconds=0.01))
with self.assertRaisesRegex(TimeoutError, "timed out after 0.01 seconds"):
a.configure(store_addr, 0, 2)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same suggestion as the gloo one about testing that timeout was changed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since we have the time in the message I think that's sufficient

@@ -178,6 +193,17 @@ def test_baby_gloo(self) -> None:

torch.testing.assert_close(at, bt)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can assert an exact value here? Would be more a check that all reduce actually does all reduce which might not be the intention here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 648 to 660
try:
# pyre-fixme[20]: expects argument options
pg = cls.PG_CLASS(store, rank, world_size)
except Exception as e:
logger.exception(f"got exception in worker: {e}")
tx.put(e)
return
tx.put(None)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since PGWrapper now uses _create_pg instead of PG_CLASS instantiation, should we make the code more consistent by having _create_pg here too?

Comment on lines +631 to +633
# fetch the status of the PG init
# if an exception was returned _get will throw
assert _get(rx, self._timeout) is None

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If _get will throw the Exception, why do we need this assertion?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just to make sure we consume the value -- doesn't really matter what the output is as long as it's consistent

@d4l3k d4l3k force-pushed the d4l3k/pg_timeouts branch from b1c3692 to d6f256c Compare January 9, 2025 21:11
@d4l3k d4l3k requested a review from Jackmin801 January 9, 2025 21:11
Copy link
Collaborator

@Jackmin801 Jackmin801 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! lgtm

@d4l3k d4l3k merged commit 141e419 into main Jan 9, 2025
6 checks passed
@d4l3k d4l3k deleted the d4l3k/pg_timeouts branch January 9, 2025 21:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Meta Open Source bot.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants