Created
July 22, 2026 02:52
-
-
Save Dirga36/0c20d0fcf0d8fcd83780700139fde918 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import torch.distributed as dist | |
| from torch.nn.parallel import DistributedDataParallel as DDP | |
| dist.init_process_group(backend="nccl") | |
| model = MyModel().cuda() | |
| model = DDP(model, device_ids=[local_rank]) | |
| for batch in dataloader: | |
| optimizer.zero_grad() | |
| outputs = model(batch) | |
| loss = criterion(outputs, targets) | |
| loss.backward() # gradients synchronized across processes automatically | |
| optimizer.step() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment