未验证 提交 facf6020 编写于 作者: H Hui Zhang 提交者: GitHub

[BUGFIX] Add return self for nn.Layer(#36609)

* Layer.to reutrn self

* add device required
上级 9f3613f3
...@@ -1512,11 +1512,12 @@ class Layer(core.Layer): ...@@ -1512,11 +1512,12 @@ class Layer(core.Layer):
asynchronous with respect to the host. Otherwise, the argument has no effect. If None, the blocking is set True. Default: None. asynchronous with respect to the host. Otherwise, the argument has no effect. If None, the blocking is set True. Default: None.
Returns: Returns:
None self
Examples: Examples:
.. code-block:: python .. code-block:: python
# required: gpu
import paddle import paddle
linear=paddle.nn.Linear(2, 2) linear=paddle.nn.Linear(2, 2)
...@@ -1547,7 +1548,7 @@ class Layer(core.Layer): ...@@ -1547,7 +1548,7 @@ class Layer(core.Layer):
''' '''
if device is None and dtype is None and blocking is None: if device is None and dtype is None and blocking is None:
return return self
if device is not None: if device is not None:
if isinstance(device, str): if isinstance(device, str):
...@@ -1595,6 +1596,7 @@ class Layer(core.Layer): ...@@ -1595,6 +1596,7 @@ class Layer(core.Layer):
self._apply(transform, device, dtype, blocking) self._apply(transform, device, dtype, blocking)
self._dtype = dtype self._dtype = dtype
return self
# [aliases] Compatible with old method names # [aliases] Compatible with old method names
set_dict = set_state_dict set_dict = set_state_dict
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册