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

ProcessGroupBaby: use pipe for improved performance #121

Merged
merged 1 commit into from
Mar 6, 2025
Merged

Conversation

d4l3k
Copy link
Member

@d4l3k d4l3k commented Mar 5, 2025

This speeds up ProcessGroupBaby performance for small operations (4s -> 2.5s).

Optimizations:

  • use Pipe instead of Queue: 4s -> 3s
  • generate op_id in parent so _run_func is fully async with no synchronization with child process: 3s -> 2.5s

Test plan:

python torchft/checkpointing/pg_transport_bench.py --device cuda --inplace --total-size=16000 --chunk-size=4

With fix:

INFO:torchft.checkpointing.pg_transport:init_pg took 1.8898121230304241s
INFO:torchft.checkpointing.pg_transport:create state_dict took 0.024819843471050262s
INFO:torchft.checkpointing.pg_transport:preparing state_dict took 0.1422094851732254s
INFO:torchft.checkpointing.pg_transport:send pickle took 0.010462276637554169s
INFO:torchft.checkpointing.pg_transport:init_pg took 1.9368509724736214s
INFO:torchft.checkpointing.pg_transport:create state_dict took 0.02213948592543602s
INFO:torchft.checkpointing.pg_transport:send tensors took 2.2778245247900486s
INFO:torchft.checkpointing.pg_transport:send_checkpoint took 2.482279524207115s
INFO:torchft.checkpointing.pg_transport:recv_checkpoint took 2.641794554889202s

Baseline:

INFO:torchft.checkpointing.pg_transport:init_pg took 1.893109567463398s
INFO:torchft.checkpointing.pg_transport:create state_dict took 0.025067199021577835s
INFO:torchft.checkpointing.pg_transport:preparing state_dict took 0.1476067118346691s
INFO:torchft.checkpointing.pg_transport:init_pg took 1.9768157303333282s
INFO:torchft.checkpointing.pg_transport:create state_dict took 0.024319566786289215s
INFO:torchft.checkpointing.pg_transport:send pickle took 0.16672053188085556s
INFO:torchft.checkpointing.pg_transport:send tensors took 3.718041818588972s
INFO:torchft.checkpointing.pg_transport:send_checkpoint took 4.046096011996269s
INFO:torchft.checkpointing.pg_transport:recv_checkpoint took 4.189382903277874s

@d4l3k d4l3k requested review from teja-rao, fegin and H-Huang March 5, 2025 05:03
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Meta Open Source bot. label Mar 5, 2025
Copy link
Member

@H-Huang H-Huang left a comment

Choose a reason for hiding this comment

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

LGTM!

Args:
timeout: timeout in seconds
"""
def send(self, obj: object) -> None:
Copy link
Member

Choose a reason for hiding this comment

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

send doesnt need a 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.

There's not an easy mechanism to handle timeouts on write and from my testing the messages are small enough that the messages effectively instantly send as they just copy into the kernel default buffer size

If the remote process exits this will fail with a BrokenPipe error as well so that case is covered

@d4l3k d4l3k force-pushed the d4l3k/baby_pipe branch from 54e00f4 to 67bc4c2 Compare March 6, 2025 21:45
@d4l3k d4l3k force-pushed the d4l3k/baby_pipe branch from 67bc4c2 to e03f05e Compare March 6, 2025 21:45
@d4l3k d4l3k merged commit 2ab329e into main Mar 6, 2025
6 checks passed
@d4l3k d4l3k deleted the d4l3k/baby_pipe branch March 6, 2025 21:55
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.

3 participants