Skip to content

Commit

Permalink
enable grad on loss tensor
Browse files Browse the repository at this point in the history
  • Loading branch information
abhilash1910 committed Sep 7, 2023
1 parent c6f8027 commit 81fecf3
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions src/llama_recipes/utils/train_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def train(model, train_dataloader,eval_dataloader, tokenizer, optimizer, lr_sche
loss = model(**batch).loss
loss = loss / gradient_accumulation_steps
total_loss += loss.detach().float()
loss = torch.autograd.Variable(loss, required_grad = True)
if train_config.use_fp16:
# if fp16 is enabled, use gradient scaler to handle gradient update
scaler.scale(loss).backward()
Expand Down

0 comments on commit 81fecf3

Please sign in to comment.