Skip to content

Commit

Permalink
幸苦了! Merge pull request #688 from ice-world/master
Browse files Browse the repository at this point in the history
补全了缺失的部分代码
  • Loading branch information
jiangzhonglian authored Jul 21, 2024
2 parents 6aebc34 + bfd1eb2 commit 5e5e28a
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions docs/2.0/tutorials/beginner/basics/optimization_tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,18 @@ def test_loop(dataloader, model, loss_fn):

我们初始化了损失函数和优化器,传递给 `train_loop``test_loop`。你可以随意地修改 epochs 的数量来跟踪模型表现的进步情况。

```py
loss_fn = nn.CrossEntropyLoss()
optimizer = torch.optim.SGD(model.parameters(), lr=learning_rate)

epochs = 10
for t in range(epochs):
print(f"Epoch {t+1}\n-------------------------------")
train_loop(train_dataloader, model, loss_fn, optimizer)
test_loop(test_dataloader, model, loss_fn)
print("Done!")
```

输出:

```py
Expand Down

0 comments on commit 5e5e28a

Please sign in to comment.