Skip to content

Commit abb1509

Browse files
2 parents a493dac + c1725a2 commit abb1509

File tree

3 files changed

+18
-48
lines changed

3 files changed

+18
-48
lines changed

docs/2.0/tutorials/beginner/basics/buildmodel_tutorial.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ pred_probab = softmax(logits)
222222
print(f"Model structure: {model}\n\n")
223223

224224
for name, param in model.named_parameters():
225-
print(f"Layer: {name} | Size: {param.size()} | Values : {param[:2]} \n"
225+
print(f"Layer: {name} | Size: {param.size()} | Values : {param[:2]} \n")
226226
```
227227

228228
输出:

docs/2.0/tutorials/beginner/basics/optimization_tutorial.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ epochs = 5
141141

142142
常见的损失函数包括给回归任务用的 `nn.MSELoss`(Mean Square Error, 均方误差)、给分类任务使用的 `nn.NLLLoss`(Negative Log Likelihood, 负对数似然)、`nn.CrossEntropyLoss`(交叉熵损失函数)结合了 `nn.LogSoftmax``nn.NLLLoss`.
143143

144-
我们把模型输出的 logits 传递给 `nn.CrossEntropyLoss`它会正则化 logits 并计算预测误差。
144+
我们把模型输出的 logits 传递给 `nn.CrossEntropyLoss`它会归一化 logits 并计算预测误差。
145145

146146
```py
147147
# 初始化损失函数
@@ -212,6 +212,18 @@ def test_loop(dataloader, model, loss_fn):
212212

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

215+
```py
216+
loss_fn = nn.CrossEntropyLoss()
217+
optimizer = torch.optim.SGD(model.parameters(), lr=learning_rate)
218+
219+
epochs = 10
220+
for t in range(epochs):
221+
print(f"Epoch {t+1}\n-------------------------------")
222+
train_loop(train_dataloader, model, loss_fn, optimizer)
223+
test_loop(test_dataloader, model, loss_fn)
224+
print("Done!")
225+
```
226+
215227
输出:
216228

217229
```py

docs/2.0/tutorials/intermediate/custom_function_conv_bn_tutorial.md

Lines changed: 4 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -46,53 +46,11 @@
4646

4747

4848

49+
For simplicity, in this tutorial we hardcode bias=False, stride=1, padding=0, dilation=1, and groups=1 for Conv2D. For BatchNorm2D, we hardcode eps=1e-3, momentum=0.1, affine=False, and track_running_statistics=False.
4950

50-
为简单起见,在本教程中我们硬编码
51+
为简单起见,在本教程中, 对于 Conv2D,我们硬编码 bias=False、 stride=1 、 padding=0 、 dilation=1 和 groups=1 。对于 BatchNorm2D,我们硬编码 eps=1e-3 、momentum=0.1 、 affine=False 和 track_running_statistics=False 。另一个小差异是我们在批量范数的计算中在平方根之外的分母中添加了epsilon。
5152

52-
bias=False
53-
54-
55-
56-
stride=1
57-
58-
59-
60-
padding=0
61-
62-
63-
64-
Conv2D 的 dilation=1
65-
66-
67-
and
68-
69-
groups=1
70-
71-
。对于 BatchNorm2D,我们硬编码
72-
73-
eps=1e-3
74-
75-
76-
77-
动量=0.1
78-
79-
80-
81-
affine=False
82-
83-
84-
85-
track\ \_running_statistics=False
86-
87-
。另一个小差异
88-
是我们在批量范数的计算中
89-
在平方根之外的分母中添加了epsilon。
90-
91-
92-
93-
94-
[0]
95-
<https://nenadmarkus.com/p/fusing-batchnorm-and-conv/>
53+
[0] <https://nenadmarkus.com/p/fusing-batchnorm-and-conv/>
9654

9755

9856

@@ -105,7 +63,7 @@ and
10563

10664
实现自定义函数需要我们自己实现向后的
10765
。在这种情况下,我们需要 Conv2D
108-
和 BatchNorm2D 的后向公式。最终我们’d 在统一的
66+
和 BatchNorm2D 的后向公式。最终我们 在统一的
10967
后向函数中将它们链接在一起,但下面我们首先将它们实现为自己的
11068
自定义函数,以便我们可以单独验证它们的正确性
11169

0 commit comments

Comments
 (0)