| 197 | // Half/BFloat16 gradient state-only update path. |
| 198 | template <typename ds_grad_precision_t, typename ds_state_precision_t> |
| 199 | void Reflow_Adam_Optimizer::Step_8_State_HalfGrad(float* _params_fp32, |
| 200 | ds_grad_precision_t* grads_half, |
| 201 | ds_state_precision_t* _exp_avg, |
| 202 | ds_state_precision_t* _exp_avg_sq, |
| 203 | size_t _param_size, |
| 204 | float combined_scale) |
| 205 | { |
| 206 | size_t rounded_size = 0; |
| 207 | #if defined(__AVX512__) or defined(__AVX256__) |
| 208 | Step_AVX_HalfGrad<8, ds_grad_precision_t, ds_state_precision_t, float, false>( |
| 209 | &rounded_size, |
| 210 | _params_fp32, |
| 211 | grads_half, |
| 212 | _exp_avg, |
| 213 | _exp_avg_sq, |
| 214 | _param_size, |
| 215 | static_cast<float*>(nullptr), |
| 216 | combined_scale); |
| 217 | // Narrow the SIMD span before handling the remaining scalar tail. |
| 218 | if (_param_size > rounded_size) { |
| 219 | size_t tail_rounded_size = 0; |
| 220 | Step_AVX_HalfGrad<4, ds_grad_precision_t, ds_state_precision_t, float, false>( |
| 221 | &tail_rounded_size, |
| 222 | _params_fp32 + rounded_size, |
| 223 | grads_half + rounded_size, |
| 224 | _exp_avg + rounded_size, |
| 225 | _exp_avg_sq + rounded_size, |
| 226 | _param_size - rounded_size, |
| 227 | static_cast<float*>(nullptr), |
| 228 | combined_scale); |
| 229 | rounded_size += tail_rounded_size; |
| 230 | } |
| 231 | if (_param_size > rounded_size) { |
| 232 | size_t tail_rounded_size = 0; |
| 233 | Step_AVX_HalfGrad<1, ds_grad_precision_t, ds_state_precision_t, float, false>( |
| 234 | &tail_rounded_size, |
| 235 | _params_fp32 + rounded_size, |
| 236 | grads_half + rounded_size, |
| 237 | _exp_avg + rounded_size, |
| 238 | _exp_avg_sq + rounded_size, |
| 239 | _param_size - rounded_size, |
| 240 | static_cast<float*>(nullptr), |
| 241 | combined_scale); |
| 242 | rounded_size += tail_rounded_size; |
| 243 | } |
| 244 | #endif |
| 245 | if (_param_size > rounded_size) { |
| 246 | float betta1_minus1 = 1 - _betta1; |
| 247 | float betta2_minus1 = 1 - _betta2; |
| 248 | float unscale_factor = 1.0f / combined_scale; |
| 249 | float step_size = -1.0f * _alpha / _bias_correction1; |
| 250 | float w_decay = -1.0f * _alpha * _weight_decay; |
| 251 | |
| 252 | for (size_t t = rounded_size; t < _param_size; t += TILE) { |
| 253 | size_t copy_size = TILE; |
| 254 | if ((t + TILE) > _param_size) copy_size = _param_size - t; |
| 255 | size_t offset = copy_size + t; |
| 256 | ReflowCPUAffinity affinity; |