未验证 提交 3c0bd3af 编写于 作者: W wanghuancoder 提交者: GitHub

use full directly if device is CPU and in dygraph, for optimizer (#48189)

上级 b0eec317
......@@ -730,6 +730,18 @@ class Optimizer:
)
if device is None:
device = self._get_device_for_param(param.name)
if in_dygraph_mode() and (
device == 'cpu' or isinstance(device, core.CPUPlace)
):
_C_ops.full_(
var,
var.shape,
str(float(fill_value)),
var.dtype,
core.CPUPlace(),
)
else:
with device_guard(device):
self.helper.set_variable_initializer(
var, initializer=Constant(value=float(fill_value))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册