Skip to content

use block_current_stream work api #241

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
lintrunner init

pip install .[dev] -v
pip install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/cu128
- name: Run lintrunner
run: |
set -eux
Expand Down
6 changes: 1 addition & 5 deletions .github/workflows/unittest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ jobs:
- runs-on: "linux.2xlarge"
gpu-arch-type: "cpu"
gpu-arch-version: ""
torch-version: "stable"
- runs-on: "linux.g5.12xlarge.nvidia.gpu"
gpu-arch-type: "cuda"
gpu-arch-version: "12.4"
torch-version: "stable"
torch-version: "nigthly"
- runs-on: "linux.g5.12xlarge.nvidia.gpu"
gpu-arch-type: "cuda"
gpu-arch-version: "12.4"
Expand Down
19 changes: 12 additions & 7 deletions torchft/local_sgd.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,13 +399,6 @@ def prepare_sync(self) -> None:
):
self._average_grads()

for work in self._allreduce_futures:
work.wait()

if self._stream is not None:
self._stop_event = torch.cuda.Event()
self._stop_event.record()

@torch.profiler.record_function("torchft::local_sgd::perform_sync")
def perform_sync(self) -> bool:
"""
Expand All @@ -415,6 +408,18 @@ def perform_sync(self) -> bool:
# Waiting for an allreduce before it has been sent is currently not supported.
assert len(self._allreduce_futures) > 0

with (
torch.cuda.stream(self._stream)
if self._stream is not None
else nullcontext()
):
for work in self._allreduce_futures:
work.wait()

if self._stream is not None:
self._stop_event = torch.cuda.Event()
self._stop_event.record()

self.wait()

# save the parameters so they can be used for merging
Expand Down
2 changes: 1 addition & 1 deletion torchft/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ def allreduce(
)
else:
work = self._pg.allreduce([tensor], ReduceOp.SUM)
work.wait()
work.block_current_stream()
fut = work.get_future()

stream: Optional[torch.cuda.Stream] = (
Expand Down
9 changes: 4 additions & 5 deletions train_diloco.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
ProcessGroupGloo,
ProcessGroupNCCL,
)
from torchft.checkpointing.pg_transport import PGTransport
from torchft.checkpointing.http_transport import HTTPTransport
from torchft.local_sgd import DiLoCo

logging.basicConfig(level=logging.INFO)
Expand Down Expand Up @@ -67,13 +67,12 @@ def state_dict():
timeout=timedelta(seconds=10),
)
if torch.cuda.is_available() and USE_NCCL
else ProcessGroupGloo(timeout=timedelta(seconds=5))
else ProcessGroupGloo(timeout=timedelta(seconds=10))
)

transport = PGTransport(
pg,
transport = HTTPTransport(
timeout=timedelta(seconds=10),
device=device,
num_chunks=0,
)

manager = Manager(
Expand Down
Loading