|
|
|
@ -628,11 +628,18 @@ def fill_constant(shape, dtype, value, force_cpu=False, out=None):
|
|
|
|
|
out.stop_gradient = True
|
|
|
|
|
return out
|
|
|
|
|
|
|
|
|
|
helper = LayerHelper("fill_constant", **locals())
|
|
|
|
|
check_dtype(dtype, 'create data type',
|
|
|
|
|
check_dtype(dtype, 'dtype',
|
|
|
|
|
['bool', 'float16', 'float32', 'float64', 'int32', 'int64'],
|
|
|
|
|
'fill_constant')
|
|
|
|
|
check_type(shape, 'shape', (Variable, list, tuple), 'fill_constant')
|
|
|
|
|
if isinstance(shape, Variable):
|
|
|
|
|
check_variable_and_dtype(shape, 'shape', ['int32', 'int64'],
|
|
|
|
|
'fill_constant')
|
|
|
|
|
if out is not None:
|
|
|
|
|
check_variable_and_dtype(out, 'out', [convert_dtype(dtype)],
|
|
|
|
|
'fill_constant')
|
|
|
|
|
|
|
|
|
|
helper = LayerHelper("fill_constant", **locals())
|
|
|
|
|
inputs = utils._get_shape_tensor_inputs(
|
|
|
|
|
inputs=inputs,
|
|
|
|
|
helper=helper,
|
|
|
|
@ -642,12 +649,6 @@ def fill_constant(shape, dtype, value, force_cpu=False, out=None):
|
|
|
|
|
|
|
|
|
|
if out is None:
|
|
|
|
|
out = helper.create_variable_for_type_inference(dtype=dtype)
|
|
|
|
|
else:
|
|
|
|
|
check_dtype(
|
|
|
|
|
dtype, 'create data type',
|
|
|
|
|
convert_dtype(out.dtype), 'fill_constant',
|
|
|
|
|
'(The create data type in fill_constant must be the same with out data type.)'
|
|
|
|
|
)
|
|
|
|
|
attrs['dtype'] = out.dtype
|
|
|
|
|
helper.append_op(
|
|
|
|
|
type='fill_constant',
|
|
|
|
|