1 /** 2 * Copyright 2021-2023 Huawei Technologies Co., Ltd 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 #include "src/litert/cxx_api/converters.h" 17 #include "include/train/train_cfg.h" 18 #include "include/api/cfg.h" 19 #include "src/common/log_adapter.h" 20 21 namespace mindspore { A2L_ConvertConfig(const TrainCfg * a_train_cfg,lite::TrainCfg * l_train_cfg)22Status A2L_ConvertConfig(const TrainCfg *a_train_cfg, lite::TrainCfg *l_train_cfg) { 23 if ((a_train_cfg == nullptr) || (l_train_cfg == nullptr)) { 24 MS_LOG(ERROR) << "Invalid train_cfg pointers"; 25 return kLiteNullptr; 26 } 27 28 std::vector<std::string> a_loss_name = a_train_cfg->GetLossName(); 29 l_train_cfg->loss_name_.assign(a_loss_name.begin(), a_loss_name.end()); 30 l_train_cfg->mix_precision_cfg_.dynamic_loss_scale_ = a_train_cfg->mix_precision_cfg_.loss_scale_; 31 l_train_cfg->mix_precision_cfg_.loss_scale_ = a_train_cfg->mix_precision_cfg_.loss_scale_; 32 l_train_cfg->mix_precision_cfg_.keep_batchnorm_fp32_ = (a_train_cfg->optimization_level_ != kO3); 33 l_train_cfg->mix_precision_cfg_.num_of_not_nan_iter_th_ = a_train_cfg->mix_precision_cfg_.num_of_not_nan_iter_th_; 34 l_train_cfg->accumulate_gradients_ = a_train_cfg->accumulate_gradients_; 35 return kSuccess; 36 } 37 } // namespace mindspore 38