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

Enable torch compile with DDP #62

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
9 changes: 4 additions & 5 deletions train_gpt2.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,8 @@ def get_most_likely_row(tokens, mask, logits):
model = GPT(GPTConfig(vocab_size=50304))
# model = GPT.from_pretrained("gpt2") # or init from OpenAI GPT-2
model.to(device)
use_compile = False # torch.compile interferes with HellaSwag eval and Generation. TODO fix
if use_compile:
model = torch.compile(model)
model = torch.compile(model)
torch._dynamo.config.optimize_ddp = False
if ddp:
model = DDP(model, device_ids=[ddp_local_rank])
raw_model = model.module if ddp else model # always contains the "raw" unwrapped model
Expand Down Expand Up @@ -411,7 +410,7 @@ def get_lr(it):
torch.save(checkpoint, checkpoint_path)

# once in a while evaluate hellaswag
if (step % 250 == 0 or last_step) and (not use_compile):
if (step % 250 == 0 or last_step):
num_correct_norm = 0
num_total = 0
for i, example in enumerate(iterate_examples("val")):
Expand Down Expand Up @@ -444,7 +443,7 @@ def get_lr(it):
f.write(f"{step} hella {acc_norm:.4f}\n")

# once in a while generate from the model (except step 0, which is noise)
if ((step > 0 and step % 250 == 0) or last_step) and (not use_compile):
if ((step > 0 and step % 250 == 0) or last_step):
model.eval()
num_return_sequences = 4
max_length = 32
Expand Down