Skip to content

Commit

Permalink
small tweaks to docs and variable names stylistically
Browse files Browse the repository at this point in the history
  • Loading branch information
karpathy committed Jan 16, 2023
1 parent 684800d commit 46ce997
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions train.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
$ torchrun --standalone --nproc_per_node=4 train.py
To run with DDP on 4 gpus across 2 nodes, example:
- Run on the first (master) node:
- Run on the first (master) node with example IP 123.456.123.456:
$ torchrun --nproc_per_node=8 --nnodes=2 --node_rank=0 --master_addr=123.456.123.456 --master_port=1234 train.py
- Run on the worker node:
$ torchrun --nproc_per_node=8 --nnodes=2 --node_rank=1 --master_addr=123.456.123.456 --master_port=1234 train.py
(If your cluster does not have Infiniband interconnect prepend NCCL_IB_DISABLE=1)
"""

import os
Expand Down Expand Up @@ -79,11 +80,11 @@
ddp = int(os.environ.get('RANK', -1)) != -1 # is this a ddp run?
if ddp:
init_process_group(backend=backend)
DDP_RANK = int(os.environ['RANK'])
DDP_LOCAL_RANK = int(os.environ['LOCAL_RANK'])
device = f'cuda:{DDP_LOCAL_RANK}'
master_process = DDP_RANK == 0 # this process will do logging, checkpointing etc.
seed_offset = DDP_RANK # each process gets a different seed
ddp_rank = int(os.environ['RANK'])
ddp_local_rank = int(os.environ['LOCAL_RANK'])
device = f'cuda:{ddp_local_rank}'
master_process = ddp_rank == 0 # this process will do logging, checkpointing etc.
seed_offset = ddp_rank # each process gets a different seed
else:
# if not ddp, we are running on a single gpu, and one process
master_process = True
Expand Down Expand Up @@ -181,7 +182,7 @@ def get_batch(split):

# wrap model into DDP container
if ddp:
model = DDP(model, device_ids=[DDP_LOCAL_RANK])
model = DDP(model, device_ids=[ddp_local_rank])

@torch.no_grad()
def estimate_loss():
Expand Down

0 comments on commit 46ce997

Please sign in to comment.