Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
209d0ed6
M
models
项目概览
PaddlePaddle
/
models
大约 1 年 前同步成功
通知
222
Star
6828
Fork
2962
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
602
列表
看板
标记
里程碑
合并请求
255
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
models
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
602
Issue
602
列表
看板
标记
里程碑
合并请求
255
合并请求
255
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
209d0ed6
编写于
4月 02, 2022
作者:
wc晨曦
提交者:
GitHub
4月 02, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update initializer.md (#5496)
上级
8e7ae1a7
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
51 addition
and
2 deletion
+51
-2
tutorials/article-implementation/initializer.md
tutorials/article-implementation/initializer.md
+51
-2
未找到文件。
tutorials/article-implementation/initializer.md
浏览文件 @
209d0ed6
...
...
@@ -54,6 +54,7 @@ plt.legend({"paddle.nn.Conv2D weight", "torch.nn.Conv2d weight"})
```
python
import
paddle
import
torch
import
math
import
numpy
as
np
import
matplotlib.pyplot
as
plt
import
paddle.nn.initializer
as
init
...
...
@@ -105,6 +106,7 @@ if isinstance(m, nn.Conv2d):
|
`paddle.nn.Conv2D`
bias参数 |
`torch.nn.Conv2d`
bias参数 | !
[](
https://paddle-model-ecology.bj.bcebos.com/images/initializer/conv2d_bias_default_diff.jpeg
)
| 见附录
`4.1.1`
| !
[](
https://paddle-model-ecology.bj.bcebos.com/images/initializer/conv2d_bias_fixed_diff.jpeg
)
|
|
`paddle.nn.Linear`
weight参数 |
`torch.nn.Linear`
weight参数 | !
[](
https://paddle-model-ecology.bj.bcebos.com/images/initializer/linear_weight_default_diff.jpeg
)
| 见附录
`4.1.2`
| !
[](
https://paddle-model-ecology.bj.bcebos.com/images/initializer/linear_weight_fixed_diff.jpeg
)
|
|
`paddle.nn.Linear`
bias参数 |
`torch.nn.Linear`
bias参数 | !
[](
https://paddle-model-ecology.bj.bcebos.com/images/initializer/linear_bias_default_diff.jpeg
)
| 见附录
`4.1.2`
| !
[](
https://paddle-model-ecology.bj.bcebos.com/images/initializer/linear_bias_fixed_diff.jpeg
)
|
|
`paddle.nn.Embedding`
weight参数 |
`torch.nn.Embedding`
weight参数 | !
[](
https://paddle-model-ecology.bj.bcebos.com/images/initializer/embedding_weight_default_diff.jpeg
)
| 见附录
`4.1.3`
| !
[](
https://paddle-model-ecology.bj.bcebos.com/images/initializer/embedding_weight_fixed_diff.jpeg
)
|
...
...
@@ -150,13 +152,12 @@ plt.ylabel("count")
plt
.
legend
({
"paddle.nn.Conv2D bias"
,
"torch.nn.Conv2d bias"
})
```
*
修正后初始化以及可视化代码
```
python
import
paddle
import
torch
import
math
import
numpy
as
np
import
matplotlib.pyplot
as
plt
import
paddle.nn.initializer
as
init
...
...
@@ -221,8 +222,10 @@ plt.legend({"paddle.nn.Linear bias", "torch.nn.Linear bias"})
```
python
import
paddle
import
torch
import
math
import
numpy
as
np
import
matplotlib.pyplot
as
plt
import
paddle.nn.initializer
as
init
%
matplotlib
inline
# linear的初始化方法同样适用于2.1节中的公式,此处的kernal_size等价于1。
linear_pd
=
paddle
.
nn
.
Linear
(
4096
,
512
,
...
...
@@ -246,3 +249,49 @@ plt.xlabel("value")
plt
.
ylabel
(
"count"
)
plt
.
legend
({
"paddle.nn.Linear bias"
,
"torch.nn.Linear bias"
})
```
### 4.1.3 paddle.nn.Embedding
*
默认初始化以及可视化代码
```
python
import
paddle
import
torch
import
numpy
as
np
import
matplotlib.pyplot
as
plt
%
matplotlib
inline
eb_pd
=
paddle
.
nn
.
Embedding
(
1024
,
512
)
eb_pt
=
torch
.
nn
.
Embedding
(
1024
,
512
)
eb_pd_weight
=
eb_pd
.
weight
.
numpy
().
reshape
((
-
1
,
))
eb_pt_weight
=
eb_pt
.
weight
.
detach
().
numpy
().
reshape
((
-
1
,
))
plt
.
figure
(
figsize
=
(
10
,
6
))
temp
=
plt
.
hist
([
eb_pd_weight
,
eb_pt_weight
],
bins
=
100
,
rwidth
=
0.8
,
histtype
=
"step"
)
plt
.
xlabel
(
"value"
)
plt
.
ylabel
(
"count"
)
plt
.
legend
({
"paddle.nn.Embedding weight"
,
"torch.nn.Embedding weight"
})
```
*
修正后初始化以及可视化代码
```
python
import
paddle
import
torch
import
numpy
as
np
import
matplotlib.pyplot
as
plt
import
paddle.nn.initializer
as
init
%
matplotlib
inline
# linear的初始化方法同样适用于2.1节中的公式,此处的kernal_size等价于1。
eb_pd
=
paddle
.
nn
.
Embedding
(
1024
,
512
,
weight_attr
=
init
.
Normal
(
0.0
,
1.0
))
eb_pt
=
torch
.
nn
.
Embedding
(
1024
,
512
)
eb_pd_weight
=
eb_pd
.
weight
.
numpy
().
reshape
((
-
1
,
))
eb_pt_weight
=
eb_pt
.
weight
.
detach
().
numpy
().
reshape
((
-
1
,
))
plt
.
figure
(
figsize
=
(
10
,
6
))
temp
=
plt
.
hist
([
eb_pd_weight
,
eb_pt_weight
],
bins
=
100
,
rwidth
=
0.8
,
histtype
=
"step"
)
plt
.
xlabel
(
"value"
)
plt
.
ylabel
(
"count"
)
plt
.
legend
({
"paddle.nn.Embedding weight"
,
"torch.nn.Embedding weight"
})
```
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录