• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2021 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/cxx_api/converters.h"
17 #include <cstddef>
18 #include <string>
19 #include <vector>
20 #include <memory>
21 #include "include/train/train_cfg.h"
22 #include "include/api/cfg.h"
23 #include "src/runtime/inner_allocator.h"
24 #include "src/common/log_adapter.h"
25 
26 namespace mindspore {
A2L_ConvertConfig(const TrainCfg * a_train_cfg,lite::TrainCfg * l_train_cfg)27 Status A2L_ConvertConfig(const TrainCfg *a_train_cfg, lite::TrainCfg *l_train_cfg) {
28   if ((a_train_cfg == nullptr) || (l_train_cfg == nullptr)) {
29     MS_LOG(ERROR) << "Invalid train_cfg pointers";
30     return kLiteNullptr;
31   }
32 
33   l_train_cfg->loss_name_ = a_train_cfg->loss_name_;
34   l_train_cfg->mix_precision_cfg_.dynamic_loss_scale_ = a_train_cfg->mix_precision_cfg_.loss_scale_;
35   l_train_cfg->mix_precision_cfg_.loss_scale_ = a_train_cfg->mix_precision_cfg_.loss_scale_;
36   l_train_cfg->mix_precision_cfg_.keep_batchnorm_fp32_ = (a_train_cfg->optimization_level_ != kO3);
37   l_train_cfg->mix_precision_cfg_.num_of_not_nan_iter_th_ = a_train_cfg->mix_precision_cfg_.num_of_not_nan_iter_th_;
38   l_train_cfg->mix_precision_cfg_.is_raw_mix_precision_ = a_train_cfg->mix_precision_cfg_.is_raw_mix_precision_;
39   l_train_cfg->accumulate_gradients_ = a_train_cfg->accumulate_gradients_;
40   return kSuccess;
41 }
42 }  // namespace mindspore
43