Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4.1.3 中提到的get_constant函数是MXNet中的 #141

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/chapter04_DL_computation/4.1_model-construction.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ ModuleDict(

## 4.1.3 构造复杂的模型

虽然上面介绍的这些类可以使模型构造更加简单,且不需要定义`forward`函数,但直接继承`Module`类可以极大地拓展模型构造的灵活性。下面我们构造一个稍微复杂点的网络`FancyMLP`。在这个网络中,我们通过`get_constant`函数创建训练中不被迭代的参数,即常数参数。在前向计算中,除了使用创建的常数参数外,我们还使用`Tensor`的函数和Python的控制流,并多次调用相同的层。
虽然上面介绍的这些类可以使模型构造更加简单,且不需要定义`forward`函数,但直接继承`Module`类可以极大地拓展模型构造的灵活性。下面我们构造一个稍微复杂点的网络`FancyMLP`。在这个网络中,我们通过将参数的require_grad属性设置为False(屏蔽对参数的自动追踪)创建训练中不被迭代的参数,即常数参数。在前向计算中,除了使用创建的常数参数外,我们还使用`Tensor`的函数和Python的控制流,并多次调用相同的层。

``` python
class FancyMLP(nn.Module):
Expand Down