| 120 | |
| 121 | template <typename T, typename MT, typename Context, bool IsMultiPrecision> |
| 122 | void ComputeImpl(const Context& dev_ctx, |
| 123 | const DenseTensor& param, |
| 124 | const DenseTensor& grad, |
| 125 | const DenseTensor& lr, |
| 126 | const DenseTensor& mom1, |
| 127 | const DenseTensor& mom2, |
| 128 | const DenseTensor& beta1_pow, |
| 129 | const DenseTensor& beta2_pow, |
| 130 | const optional<DenseTensor>& master_param_opt, |
| 131 | const optional<DenseTensor>& skip_update_opt, |
| 132 | float weight_decay_f, |
| 133 | float beta1_f, |
| 134 | float beta2_f, |
| 135 | float epsilon_f, |
| 136 | bool always_adapt, |
| 137 | bool multi_precision UNUSED, |
| 138 | DenseTensor* param_out, |
| 139 | DenseTensor* mom1_out, |
| 140 | DenseTensor* mom2_out, |
| 141 | DenseTensor* beta1_pow_out, |
| 142 | DenseTensor* beta2_pow_out, |
| 143 | DenseTensor* master_param_out) { |
| 144 | if (!IsMultiPrecision) { |
| 145 | constexpr auto kIsSameType = std::is_same<T, MT>::value; |
| 146 | PADDLE_ENFORCE_EQ( |
| 147 | kIsSameType, |
| 148 | true, |
| 149 | common::errors::InvalidArgument( |
| 150 | "When multi_precision=False, T and MT must be the same type.")); |
| 151 | } |
| 152 | |
| 153 | const auto* master_param = |
| 154 | IsMultiPrecision ? master_param_opt.get_ptr() : nullptr; |
| 155 | const auto* skip_update = skip_update_opt.get_ptr(); |
| 156 | const bool* skip_update_flag = skip_update && skip_update->IsInitialized() |
| 157 | ? skip_update->data<bool>() |
| 158 | : nullptr; |
| 159 | if (skip_update_flag && |
| 160 | skip_update->place().GetType() == AllocationType::CPU && |
| 161 | (*skip_update_flag)) { |
| 162 | return; |
| 163 | } |
| 164 | |
| 165 | auto weight_decay = static_cast<MT>(weight_decay_f); |
| 166 | auto beta1 = static_cast<MT>(beta1_f); |
| 167 | auto beta2 = static_cast<MT>(beta2_f); |
| 168 | auto epsilon = static_cast<MT>(epsilon_f); |
| 169 | auto numel = param.numel(); |
| 170 | funcs::ForRange<Context> for_range(dev_ctx, numel); |
| 171 | DenseTensor trust_ratio_div; |
| 172 | trust_ratio_div.Resize(param.dims()); |
| 173 | auto* trust_ratio_div_ptr = dev_ctx.template Alloc<MT>(&trust_ratio_div); |
| 174 | |
| 175 | const void* param_ptr = param.data(); |
| 176 | const void* master_param_ptr = master_param ? master_param->data() : nullptr; |
| 177 | void* param_out_ptr = dev_ctx.template Alloc<T>(param_out); |
| 178 | void* master_param_out_ptr = |
| 179 | master_param_out ? dev_ctx.template Alloc<MT>(master_param_out) : nullptr; |
nothing calls this directly
no test coverage detected