From c775bc69d02d2d3b4eae6c1b9862d57cecb8bba0 Mon Sep 17 00:00:00 2001 From: Aganlengzi Date: Sat, 19 Nov 2022 11:43:31 +0800 Subject: [PATCH] [CustomPlace] fix amp (#48090) * [CustomPlace] fix amp * [CustomPlace] fix amp * fix ut because of too long time matmul fp16 --- paddle/fluid/eager/amp_auto_cast.h | 3 ++- paddle/fluid/eager/eager_amp_auto_cast.h | 3 ++- .../fluid/tests/custom_runtime/test_custom_cpu_to_static.py | 6 +++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/paddle/fluid/eager/amp_auto_cast.h b/paddle/fluid/eager/amp_auto_cast.h index 5110f6f883..a16dd95396 100644 --- a/paddle/fluid/eager/amp_auto_cast.h +++ b/paddle/fluid/eager/amp_auto_cast.h @@ -29,7 +29,8 @@ static inline bool NeedCast(const paddle::experimental::Tensor& tensor, paddle::platform::is_xpu_place(place) || paddle::platform::is_mlu_place(place) || paddle::platform::is_npu_place(place) || - paddle::platform::is_npu_pinned_place(place)) { + paddle::platform::is_npu_pinned_place(place) || + paddle::platform::is_custom_place(place)) { // CudaPinndePlace is added for varbase created by dataloader if ((data_type == paddle::experimental::DataType::FLOAT32 || data_type == paddle::experimental::DataType::FLOAT16 || diff --git a/paddle/fluid/eager/eager_amp_auto_cast.h b/paddle/fluid/eager/eager_amp_auto_cast.h index 42961b84bc..22748e31cf 100644 --- a/paddle/fluid/eager/eager_amp_auto_cast.h +++ b/paddle/fluid/eager/eager_amp_auto_cast.h @@ -27,7 +27,8 @@ static inline bool NeedCast(const paddle::experimental::Tensor& tensor, paddle::platform::is_xpu_place(place) || paddle::platform::is_mlu_place(place) || paddle::platform::is_npu_place(place) || - paddle::platform::is_npu_pinned_place(place)) { + paddle::platform::is_npu_pinned_place(place) || + paddle::platform::is_custom_place(place)) { // CudaPinndePlace is added for varbase created by dataloader if ((data_type == paddle::experimental::DataType::FLOAT32 || data_type == paddle::experimental::DataType::FLOAT16 || diff --git a/python/paddle/fluid/tests/custom_runtime/test_custom_cpu_to_static.py b/python/paddle/fluid/tests/custom_runtime/test_custom_cpu_to_static.py index a1b485b3f5..6ce9cb4576 100644 --- a/python/paddle/fluid/tests/custom_runtime/test_custom_cpu_to_static.py +++ b/python/paddle/fluid/tests/custom_runtime/test_custom_cpu_to_static.py @@ -54,7 +54,11 @@ def train_func_ampo1(epoch_id, train_loader, model, cost, optimizer, scaler): for batch_id, (images, labels) in enumerate(train_loader()): # forward with paddle.amp.auto_cast( - custom_black_list={"flatten_contiguous_range", "greater_than"}, + custom_black_list={ + "flatten_contiguous_range", + "greater_than", + "matmul_v2", + }, level='O1', ): outputs = model(images) -- GitLab