Skip to content

add bf16 for some ops in static mode #51582

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

Merged
merged 8 commits into from
Apr 9, 2023
Merged
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
1 change: 1 addition & 0 deletions paddle/phi/kernels/gpu/matmul_grad_kernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ PD_REGISTER_KERNEL(matmul_with_flatten_grad,
phi::MatmulWithFlattenGradKernel,
float,
double,
phi::dtype::bfloat16,
phi::dtype::float16) {}

PD_REGISTER_KERNEL(matmul_with_flatten_double_grad,
Expand Down
1 change: 1 addition & 0 deletions paddle/phi/kernels/gpu/matmul_kernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ PD_REGISTER_KERNEL(matmul_with_flatten,
phi::MatmulWithFlattenKernel,
float,
double,
phi::dtype::bfloat16,
phi::dtype::float16) {}
3 changes: 2 additions & 1 deletion python/paddle/fluid/layers/layer_function_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def func(x, name=None):

if op_type not in ["abs", "exp", "square"]:
check_variable_and_dtype(
x, 'x', ['float16', 'float32', 'float64'], op_type
x, 'x', ['float16', 'float32', 'float64', 'uint16'], op_type
)
else:
# abs exp square ops support dtype(int32, int64, float16, float32, float64)
Expand All @@ -293,6 +293,7 @@ def func(x, name=None):
'float64',
'complex64',
'complex128',
'uint16',
],
op_type,
)
Expand Down
12 changes: 9 additions & 3 deletions python/paddle/static/amp/amp_nn.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def check_finite_and_unscale(x, scale, name=None, float_status=None):
check_variable_and_dtype(
e,
"x",
['float16', 'float32', 'float64'],
['float16', 'float32', 'float64', 'uint16'],
'check_finite_and_unscale',
)

Expand Down Expand Up @@ -133,9 +133,15 @@ def update_loss_scaling(
check_type(x, 'x', (tuple, list), 'update_loss_scaling')
for e in x:
check_variable_and_dtype(
e, "x", ['float16', 'float32', 'float64'], 'update_loss_scaling'
e,
"x",
['float16', 'float32', 'float64', 'uint16'],
'update_loss_scaling',
)
if e.dtype == core.VarDesc.VarType.FP16:
if (
e.dtype == core.VarDesc.VarType.FP16
or e.dtype == core.VarDesc.VarType.BF16
):
assert (
prev_loss_scaling.dtype == core.VarDesc.VarType.FP32
), "The dtype of prev_loss_scaling should be float32 when the dtype of x is float16."
Expand Down
1 change: 1 addition & 0 deletions python/paddle/tensor/layer_function_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ def func(x, name=None):
'float64',
'complex64',
'complex128',
'uint16',
],
op_type,
)
Expand Down