Skip to content

Instantly share code, notes, and snippets.

@thomwolf
Last active December 18, 2019 07:20
Show Gist options
  • Save thomwolf/be4c26b1baf05db92b3325f1b1be2798 to your computer and use it in GitHub Desktop.
Save thomwolf/be4c26b1baf05db92b3325f1b1be2798 to your computer and use it in GitHub Desktop.
A simple PyTorch training loop
predictions = model(inputs) # Forward pass
loss = loss_function(predictions, labels) # Compute loss function
loss.backward() # Backward pass
optimizer.step() # Optimizer step
predictions = model(inputs) # Forward pass with new parameters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment