Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,9 @@ Tensor(shape=[10, 1], dtype=float32, place=CPUPlace, stop_gradient=True,
同样的也可以使用 ``register_forward_pre_hook()`` 来注册**pre_hook**:

```python
def forward_pre_hook(layer, input, output):
return 2*output
def forward_pre_hook(layer, input):
print(input)
return input

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

```text
Tensor(shape=[10, 1], dtype=float32, place=CPUPlace, stop_gradient=True,
[[2.],
[2.],
...
(Tensor(shape=[10, 1], dtype=float32, place=CUDAPlace(0), stop_gradient=True,
[[1.],
[1.],
[1.],
[1.],
[1.],
[1.],
[1.],
[1.],
[1.],
[1.]]),)
```

## 模型数据保存
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,9 @@ Tensor(shape=[10, 1], dtype=float32, place=CPUPlace, stop_gradient=True,
Similarly, we can also register a **pre_hook** through ``register_forward_pre_hook()``

```python
def forward_pre_hook(layer, input, output):
return 2*output
def forward_pre_hook(layer, input):
print(input)
return input

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

```text
Tensor(shape=[10, 1], dtype=float32, place=CPUPlace, stop_gradient=True,
[[2.],
[2.],
...
(Tensor(shape=[10, 1], dtype=float32, place=CUDAPlace(0), stop_gradient=True,
[[1.],
[1.],
[1.],
[1.],
[1.],
[1.],
[1.],
[1.],
[1.],
[1.]]),)
```

## Save a model's data
Expand Down