Skip to content

Commit 01d3690

Browse files
authored
Bug fix for layer_and_model documentation (#4069)
1 parent b8e5ef7 commit 01d3690

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

docs/guides/01_paddle2.0_introduction/basic_concept/layer_and_model_cn.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,9 @@ Tensor(shape=[10, 1], dtype=float32, place=CPUPlace, stop_gradient=True,
303303
同样的也可以使用 ``register_forward_pre_hook()`` 来注册**pre_hook**
304304

305305
```python
306-
def forward_pre_hook(layer, input, output):
307-
return 2*output
306+
def forward_pre_hook(layer, input):
307+
print(input)
308+
return input
308309

309310
x = paddle.ones([10, 1], 'float32')
310311
model = Model()
@@ -313,10 +314,17 @@ out = model(x)
313314
```
314315

315316
```text
316-
Tensor(shape=[10, 1], dtype=float32, place=CPUPlace, stop_gradient=True,
317-
[[2.],
318-
[2.],
319-
...
317+
(Tensor(shape=[10, 1], dtype=float32, place=CUDAPlace(0), stop_gradient=True,
318+
[[1.],
319+
[1.],
320+
[1.],
321+
[1.],
322+
[1.],
323+
[1.],
324+
[1.],
325+
[1.],
326+
[1.],
327+
[1.]]),)
320328
```
321329

322330
## 模型数据保存

docs/guides/01_paddle2.0_introduction/basic_concept/layer_and_model_en.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,9 @@ Tensor(shape=[10, 1], dtype=float32, place=CPUPlace, stop_gradient=True,
311311
Similarly, we can also register a **pre_hook** through ``register_forward_pre_hook()``
312312

313313
```python
314-
def forward_pre_hook(layer, input, output):
315-
return 2*output
314+
def forward_pre_hook(layer, input):
315+
print(input)
316+
return input
316317

317318
x = paddle.ones([10, 1], 'float32')
318319
model = Model()
@@ -321,10 +322,17 @@ out = model(x)
321322
```
322323

323324
```text
324-
Tensor(shape=[10, 1], dtype=float32, place=CPUPlace, stop_gradient=True,
325-
[[2.],
326-
[2.],
327-
...
325+
(Tensor(shape=[10, 1], dtype=float32, place=CUDAPlace(0), stop_gradient=True,
326+
[[1.],
327+
[1.],
328+
[1.],
329+
[1.],
330+
[1.],
331+
[1.],
332+
[1.],
333+
[1.],
334+
[1.],
335+
[1.]]),)
328336
```
329337

330338
## Save a model's data

0 commit comments

Comments
 (0)