-
Notifications
You must be signed in to change notification settings - Fork 151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[onert] Remove training info from nnfw_train_prepare #12383
Conversation
24812f9
to
d994bc9
Compare
try | ||
{ | ||
nnfw_train_info tinfo; | ||
if (info != nullptr) | ||
{ | ||
tinfo = *info; | ||
} | ||
|
||
auto convertLossType = [](const int &type) { | ||
if (type == NNFW_TRAIN_LOSS_MEAN_SQUARED_ERROR) | ||
return onert::ir::train::LossCode::MeanSquaredError; | ||
if (type == NNFW_TRAIN_LOSS_CATEGORICAL_CROSSENTROPY) | ||
return onert::ir::train::LossCode::CategoricalCrossentropy; | ||
else | ||
throw std::runtime_error("not supported loss type"); | ||
}; | ||
auto convertLossReductionType = [](const int &type) { | ||
if (type == NNFW_TRAIN_LOSS_REDUCTION_AUTO) | ||
return onert::ir::train::LossReductionType::Auto; | ||
else if (type == NNFW_TRAIN_LOSS_REDUCTION_SUM_OVER_BATCH_SIZE) | ||
return onert::ir::train::LossReductionType::SumOverBatchSize; | ||
else if (type == NNFW_TRAIN_LOSS_REDUCTION_SUM) | ||
return onert::ir::train::LossReductionType::Sum; | ||
else | ||
throw std::runtime_error("not supported loss reduction type"); | ||
}; | ||
onert::ir::train::LossInfo loss_info; | ||
loss_info.loss_code = convertLossType(tinfo.loss_info.loss); | ||
// TODO Consider the reduction type of model file | ||
loss_info.reduction_type = convertLossReductionType(tinfo.loss_info.reduction_type); | ||
|
||
auto convertOptType = [](const int &type) { | ||
if (type == NNFW_TRAIN_OPTIMIZER_SGD) | ||
return onert::ir::train::OptimizerCode::SGD; | ||
else if (type == NNFW_TRAIN_OPTIMIZER_ADAM) | ||
return onert::ir::train::OptimizerCode::Adam; | ||
else | ||
throw std::runtime_error("not supported optimizer type"); | ||
}; | ||
onert::ir::train::OptimizerInfo opt_info; | ||
opt_info.learning_rate = tinfo.learning_rate; | ||
opt_info.optim_code = convertOptType(tinfo.opt); | ||
|
||
onert::ir::train::TrainingInfo training_info; | ||
training_info.setBatchSize(tinfo.batch_size); | ||
training_info.setLossInfo(loss_info); | ||
training_info.setOptimizerInfo(opt_info); | ||
if (not _train_info->isValid()) | ||
throw std::runtime_error{"training info is not valid"}; | ||
|
||
auto compiler = | ||
onert::compiler::CompilerFactory::get().create(_nnpkg, _coptions, &training_info); | ||
onert::compiler::CompilerFactory::get().create(_nnpkg, _coptions, _train_info.get()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of using training info from the argument, use_train_info
in the session.
We expect training info in the session will be set by those API :
nnfw_load_model..
- set training info from model metadata.nnfw_train_set_traininfo
- users' manual set
67ee378
to
545d78e
Compare
This PR removes training info from 'nnfw_train_prepare' argument. It also makes 'nnfw_train_prepare' to use training info from session. ONE-DCO-1.0-Signed-off-by: SeungHui Youn <sseung.youn@samsung.com>
545d78e
to
17ba126
Compare
The ONE/runtime/onert/api/src/nnfw_api_internal.h Line 214 in 64b87a6
This PR obtains the address of _train_info and passes it to TrainingCompiler .
The ONE/runtime/onert/core/src/compiler/train/TrainingCompiler.cc Lines 50 to 51 in 64b87a6
The TrainingCompiler creates a TrainableExecutor using createTrainableExecutor .ONE/runtime/onert/core/src/compiler/train/TrainingCompiler.cc Lines 288 to 289 in 64b87a6
The createTrainableExecutor copies optimizer and loss information from _training_info .And it is no longer used. At first, I thought that you should use In addition, I leave a long comment, but what I want to say is "LGTM". Thank you :) |
This comment was marked as resolved.
This comment was marked as resolved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. It breaks API compatibility. Let's merge at once.
If split this into two PRs, it makes build error. |
Thank you a lot for checking detailed things :)
I agree. Also
I think this copy is redundant. ONE/runtime/onert/core/src/compiler/train/TrainingCompiler.h Lines 72 to 75 in 64b87a6
|
I agree this point :) |
Let me add some background about this, just in case. I added epoch to TrainingInfo, Because circle+ schema(training info flatbuffer schema) holds epoch information. (sorry for inner-link 🔗) Since there is no way to save a model file's info except saving in session._train_info, |
The epoch in circle+ schema is not necessary information. Because the epoch count is not related to the training model. We should remove the epoch info from circle+ schema. :) |
This PR removes training info from 'nnfw_train_prepare' argument.
It also makes 'nnfw_train_prepare' to use training info from session.
ONE-DCO-1.0-Signed-off-by: SeungHui Youn sseung.youn@samsung.com
related : #11692