Skip to content

Commit

Permalink
Train step for cm3leon (#1922)
Browse files Browse the repository at this point in the history
Summary: Pull Request resolved: #1922

Reviewed By: xuzhao9

Differential Revision: D49584108

Pulled By: msaroufim

fbshipit-source-id: 6d08bdb33216f650f6ddd924eeb9a37949f3f90c
  • Loading branch information
msaroufim authored and facebook-github-bot committed Sep 25, 2023
1 parent 64dec59 commit 4ea3bba
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions torchbenchmark/models/cm3leon_generate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,26 @@ def __init__(self, test, device, batch_size=None, extra_args=[]):
self.example_inputs = (
torch.randint(1, vocab_size, (self.batch_size, prompt_size)).to(self.device),
)
self.criterion = torch.nn.CrossEntropyLoss()
self.optimizer = torch.optim.Adam(self.model.parameters())

def get_module(self):
return self.model, self.example_inputs

# The code included here is specialized for eval
def train(self):
return NotImplementedError("training script not published")
self.model.train()

outputs = self.model(*self.example_inputs)

# This doesn't make semantic sense but works for demonstration.
loss = self.criterion(outputs, self.example_inputs[0])

# Backward pass and optimization
self.optimizer.zero_grad()
loss.backward()
self.optimizer.step()

return loss.item()

def eval(self):
with torch.no_grad():
Expand Down

0 comments on commit 4ea3bba

Please sign in to comment.