Skip to content

Commit

Permalink
very slight refactor, bit cleaner
Browse files Browse the repository at this point in the history
  • Loading branch information
karpathy committed Feb 4, 2023
1 parent dc14989 commit e108ffb
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions train.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,10 @@ def get_batch(split):
ix = torch.randint(len(data) - block_size, (batch_size,))
x = torch.stack([torch.from_numpy((data[i:i+block_size]).astype(np.int64)) for i in ix])
y = torch.stack([torch.from_numpy((data[i+1:i+1+block_size]).astype(np.int64)) for i in ix])
# pin arrays x,y, which allows us to move them to GPU asynchronously (non_blocking=True)
if "cuda" in device:
# GPU training
if device_type == 'cuda':
# pin arrays x,y, which allows us to move them to GPU asynchronously (non_blocking=True)
x, y = x.pin_memory().to(device, non_blocking=True), y.pin_memory().to(device, non_blocking=True)
else:
# CPU or MPS training
x, y = x.to(device), y.to(device)
return x, y

Expand Down

0 comments on commit e108ffb

Please sign in to comment.