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

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

上级 b0eec317
...@@ -730,10 +730,22 @@ class Optimizer: ...@@ -730,10 +730,22 @@ class Optimizer:
) )
if device is None: if device is None:
device = self._get_device_for_param(param.name) device = self._get_device_for_param(param.name)
with device_guard(device):
self.helper.set_variable_initializer( if in_dygraph_mode() and (
var, initializer=Constant(value=float(fill_value)) 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))
)
if framework._non_static_mode(): if framework._non_static_mode():
if len(self._accumulators_holder) > 0: if len(self._accumulators_holder) > 0:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册