From cdab3a44b6a2c2866c2cac4ccdf32544631f654c Mon Sep 17 00:00:00 2001 From: ShenLiang <1422485404@qq.com> Date: Tue, 20 Dec 2022 10:55:41 +0800 Subject: [PATCH] Fix nullptr to TestFuseGemmEpilogueReluBWDFP* (#48997) (#49090) Co-authored-by: Ming-Xu Huang --- .../operators/fused/fused_gemm_epilogue_op.cc | 5 ++--- .../operators/fused/fused_gemm_epilogue_op.cu | 21 ++++++++++++------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/paddle/fluid/operators/fused/fused_gemm_epilogue_op.cc b/paddle/fluid/operators/fused/fused_gemm_epilogue_op.cc index f9366bace33..c0978bca656 100644 --- a/paddle/fluid/operators/fused/fused_gemm_epilogue_op.cc +++ b/paddle/fluid/operators/fused/fused_gemm_epilogue_op.cc @@ -139,9 +139,8 @@ class FusedGemmEpilogueOp : public framework::OperatorWithKernel { } ctx->SetOutputDim("Out", phi::make_ddim(out_dims)); - // Note (Ming Huang): Reserve space of relu is a bit-mask, - // which cannot pass nan_and_inf checking if shape is set. - if (activation == "gelu" && ctx->HasOutput("ReserveSpace")) { + + if (ctx->HasOutput("ReserveSpace")) { ctx->SetOutputDim("ReserveSpace", phi::make_ddim(out_dims)); } } diff --git a/paddle/fluid/operators/fused/fused_gemm_epilogue_op.cu b/paddle/fluid/operators/fused/fused_gemm_epilogue_op.cu index 07870faff73..1c8f966f2aa 100644 --- a/paddle/fluid/operators/fused/fused_gemm_epilogue_op.cu +++ b/paddle/fluid/operators/fused/fused_gemm_epilogue_op.cu @@ -107,15 +107,21 @@ class FusedGemmEpilogueKernel : public framework::OpKernel { sizeof(bias_data))); if (enable_auxiliary && activation != "none") { - size_t reserve_space_size = 0; + // Note (Ming Huang): The initialization of ReseveSpace is happened in the + // dev_ctx.Alloc. Therefore, we set real date type up here. if (activation == "relu") { - // Count in bits. - reserve_space_size = phi::product(out->dims()) / 8; + paddle::experimental::DataType rs_type = + paddle::experimental::DataType::BOOL; + size_t reserve_space_size = + phi::product(reserve_space->dims()) * SizeOf(rs_type); + dev_ctx.Alloc(reserve_space, rs_type, reserve_space_size); } else { - reserve_space_size = phi::product(out->dims()) * sizeof(T); + size_t reserve_space_size = + phi::product(reserve_space->dims()) * sizeof(T); + dev_ctx.Alloc(reserve_space, reserve_space_size); } - dev_ctx.Alloc(reserve_space, out->type(), reserve_space_size); - void* aux_data = reinterpret_cast(reserve_space->data()); + + void* aux_data = reserve_space->data(); PADDLE_ENFORCE_GPU_SUCCESS( platform::dynload::cublasLtMatmulDescSetAttribute( @@ -185,7 +191,6 @@ class FusedGemmEpilogueKernel : public framework::OpKernel { stream, workspace->ptr(), workspace_size); - PADDLE_ENFORCE_GPU_SUCCESS( platform::dynload::cublasLtMatmul(lt_handle, operation_desc, @@ -478,7 +483,7 @@ class FusedGemmEpilogueGradKernel : public framework::OpKernel { sizeof(epiloque_func_for_dx))); if (activation_grad != "none") { - auto* aux_data = reserve_space->data(); + auto* aux_data = reserve_space->data(); PADDLE_ENFORCE_GPU_SUCCESS( platform::dynload::cublasLtMatmulDescSetAttribute( dx_operation_desc, -- GitLab