PyTorch 2 · Training and saving

Choose a loss and optimizer

Set up cross-entropy loss and the Adam optimizer.

loss_fn = nn.CrossEntropyLoss()
optimizer = torch.optim.Adam(model.parameters(), lr=1e-3)

Official PyTorch 2 documentation

More training and saving commands

All training and saving commands · PyTorch 2 cheatsheet

Was this page helpful?