From 8ef020c1164dcc0d6a8e676b1e0a23c6be4477ed Mon Sep 17 00:00:00 2001 From: niuliling123 <51102941+niuliling123@users.noreply.github.com> Date: Wed, 22 Mar 2023 14:28:52 +0800 Subject: [PATCH] Fix type error in adagrad_kernel (#51790) --- paddle/phi/kernels/gpu/adagrad_kernel.cu | 4 ++-- python/paddle/fluid/optimizer.py | 6 +++++- python/paddle/optimizer/adagrad.py | 6 +++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/paddle/phi/kernels/gpu/adagrad_kernel.cu b/paddle/phi/kernels/gpu/adagrad_kernel.cu index 14046ed4491..1ce78b7e0f6 100644 --- a/paddle/phi/kernels/gpu/adagrad_kernel.cu +++ b/paddle/phi/kernels/gpu/adagrad_kernel.cu @@ -37,7 +37,7 @@ __global__ void AdagradGPUKernel(const T* param, MT* master_param_out, int num) { auto idx = blockDim.x * blockIdx.x + threadIdx.x; - MT lr_data = static_cast(lr[0]); + MT lr_data = static_cast(lr[0]); for (int i = idx; i < num; i += blockDim.x * gridDim.x) { MT grad_data = static_cast(grad[i]); @@ -47,7 +47,7 @@ __global__ void AdagradGPUKernel(const T* param, MT param_out_data = in - (lr_data * grad_data) / (sqrt(moment_out_data) + epsilon); - param_out[i] = static_cast(param_out_data); + param_out[i] = static_cast(param_out_data); if (master_param_out) { master_param_out[i] = param_out_data; diff --git a/python/paddle/fluid/optimizer.py b/python/paddle/fluid/optimizer.py index d835a3fbfcf..ded8883ffdb 100755 --- a/python/paddle/fluid/optimizer.py +++ b/python/paddle/fluid/optimizer.py @@ -2081,7 +2081,11 @@ class AdagradOptimizer(Optimizer): for p in parameters: if self._multi_precision and self._is_dtype_fp16_or_bf16(p.dtype): master_p = self._create_master_weight(p) - self._add_accumulator(self._moment_acc_str, master_p) + self._add_accumulator( + self._moment_acc_str, + master_p, + fill_value=self.initial_accumulator_value, + ) continue if ( self._is_dtype_fp16_or_bf16(p.dtype) diff --git a/python/paddle/optimizer/adagrad.py b/python/paddle/optimizer/adagrad.py index 3d2935c7407..c19b3116de3 100644 --- a/python/paddle/optimizer/adagrad.py +++ b/python/paddle/optimizer/adagrad.py @@ -146,7 +146,11 @@ class Adagrad(Optimizer): continue if self._multi_precision and self._is_dtype_fp16_or_bf16(p.dtype): master_p = self._create_master_weight(p) - self._add_accumulator(self._moment_acc_str, master_p) + self._add_accumulator( + self._moment_acc_str, + master_p, + fill_value=self.initial_accumulator_value, + ) self._already_create_accumulater.add(p.name) continue if ( -- GitLab