Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add float16 for assign_value #56170

Closed
wants to merge 6 commits into from
Closed
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
2 changes: 1 addition & 1 deletion paddle/phi/api/yaml/static_ops.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
backward : assign_grad

- op : assign_value
args : (int[] shape, DataType dtype, int[] bool_values = {}, float[] fp32_values = {}, int[] int32_values = {}, int64_t[] int64_values = {})
args : (int[] shape, DataType dtype, int[] bool_values = {}, float[] fp16_values = {}, float[] fp32_values = {}, int[] int32_values = {}, int64_t[] int64_values = {})
output : Tensor(out)
infer_meta :
func : AssignValueInferMeta
Expand Down
1 change: 1 addition & 0 deletions paddle/phi/kernels/assign_kernel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ PD_REGISTER_KERNEL(assign_value,
ALL_LAYOUT,
phi::AssignValueKernel,
bool,
phi::dtype::float16,
int,
float,
int8_t,
Expand Down
3 changes: 3 additions & 0 deletions paddle/phi/ops/compat/assign_value_sig.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ KernelSignature AssignValueOpArgumentMapping(
} else if (dtype == /*INT64*/ 3) {
return KernelSignature(
"assign_value", {}, {"shape", "dtype", "int64_values"}, {"Out"});
} else if (dtype == /*FLOAT16*/ 4) {
return KernelSignature(
"assign_value", {}, {"shape", "dtype", "fp16_values"}, {"Out"});
Liyulingyue marked this conversation as resolved.
Show resolved Hide resolved
} else {
return KernelSignature("unregistered", {}, {}, {});
}
Expand Down
8 changes: 8 additions & 0 deletions python/paddle/distributed/passes/auto_parallel_fp16.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,14 @@ def cast_block(self, block):
if op.type in __amp_skip_ops__:
idx += 1
continue
# The "dtype" attr "values" attr of assign_value should correspond.
# But origin program only has "fp32_values", so here we should set
# "fp16_values" attr.
elif op.type == "assign_value":
dtype = op.attr("dtype")
# 4 means fp16
if dtype == 4:
op._set_attr("fp16_values", op.attr("fp32_values"))
elif is_forward_op(op):
if self._is_fp16_op(op.desc.original_id()) is False:
num_cast_ops = self._insert_forward_cast_ops(
Expand Down