MoisesHer commented on a change in pull request #16893: Multi-tensor LAMB URL: https://github.com/apache/incubator-mxnet/pull/16893#discussion_r352948392
########## File path: src/operator/contrib/multi_lamb.cu ########## @@ -0,0 +1,254 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/*! + * Copyright (c) 2019 by Contributors + * \file multi_lamb.cu + * \brief vectorized lamb coefficient computed from sums of squared weights and grads + * \author Moises Hernandez + */ + +#include "./multi_lamb-inl.h" + +namespace mxnet { +namespace op { + +#define BLOCK_SIZE_LAMB 512 +#define ILP_LAMB 4 + +template<bool has_mixed_precision, typename MPDType, typename DType> +__global__ void kernel_step1(const MultiLAMBKernelParam<DType, MPDType> kernel_params, + const float learning_rate, + const float beta1, const float beta2, + const MPDType beta3, const MPDType beta4, + const float epsilon, + const float wd, + const float clip_gradient, + const bool bias_correction, + const float rescale_grad, + int* block_to_tensor, + int* block_to_chunk) { + const int tensorID = block_to_tensor[blockIdx.x]; + const int chunckID = block_to_chunk[blockIdx.x]; + const int startPos = chunckID * kernel_params.chunk_size + threadIdx.x; + const int stopPos = chunckID * kernel_params.chunk_size + kernel_params.chunk_size; + + MPDType biascorrection1, biascorrection2; + if (bias_correction) { + biascorrection1 = 1.0f - std::pow(beta1, kernel_params.step_count[tensorID]); + biascorrection2 = 1.0f - std::pow(beta2, kernel_params.step_count[tensorID]); + } else { + biascorrection1 = 1.0f; + biascorrection2 = 1.0f; + } + + MPDType r_weight[ILP_LAMB]; + MPDType r_grad[ILP_LAMB]; + MPDType r_mean[ILP_LAMB]; + MPDType r_var[ILP_LAMB]; + MPDType r_g[ILP_LAMB]; + + for (size_t i=startPos; i < stopPos && i < kernel_params.sizes[tensorID]; + i+= blockDim.x*ILP_LAMB) { +#pragma unroll + for (int ii = 0; ii < ILP_LAMB; ii++) { + int load_pos = i + ii*blockDim.x; + if (load_pos < stopPos && load_pos < kernel_params.sizes[tensorID]) { Review comment: done, thanks ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
