Skip to content

Commit

Permalink
[onert] Introduce trainable_ops attribute to circle_traininfo schema (#…
Browse files Browse the repository at this point in the history
…13000)

This commit introduces trainable_ops attribute to circle_traininfo
schema to support Transfer learning.

ONE-DCO-1.0-Signed-off-by: Jiyoung Yun <jy910.yun@samsung.com>
  • Loading branch information
jyoungyun committed May 16, 2024
1 parent f99e491 commit 63e81d0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
1 change: 1 addition & 0 deletions runtime/libs/circle-schema/include/circle_traininfo.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ table ModelTraining {
epochs: int;
batch_size: int;
loss_reduction_type : LossReductionType;
trainable_ops : [int];
}

root_type ModelTraining;
38 changes: 34 additions & 4 deletions runtime/libs/circle-schema/include/circle_traininfo_generated.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// command: flatc -c --gen-onefile circle_traininfo.fbs
// automatically generated by the FlatBuffers compiler, do not modify
// command: flatc -c circle_traininfo.fbs

#ifndef FLATBUFFERS_GENERATED_CIRCLETRAININFO_CIRCLE_H_
#define FLATBUFFERS_GENERATED_CIRCLETRAININFO_CIRCLE_H_
Expand Down Expand Up @@ -494,7 +494,8 @@ struct ModelTraining FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table
VT_LOSSFN_OPT = 16,
VT_EPOCHS = 18,
VT_BATCH_SIZE = 20,
VT_LOSS_REDUCTION_TYPE = 22
VT_LOSS_REDUCTION_TYPE = 22,
VT_TRAINABLE_OPS = 24
};
uint32_t version() const { return GetField<uint32_t>(VT_VERSION, 0); }
circle::Optimizer optimizer() const
Expand Down Expand Up @@ -554,6 +555,10 @@ struct ModelTraining FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table
{
return static_cast<circle::LossReductionType>(GetField<int8_t>(VT_LOSS_REDUCTION_TYPE, 0));
}
const ::flatbuffers::Vector<int32_t> *trainable_ops() const
{
return GetPointer<const ::flatbuffers::Vector<int32_t> *>(VT_TRAINABLE_OPS);
}
bool Verify(::flatbuffers::Verifier &verifier) const
{
return VerifyTableStart(verifier) && VerifyField<uint32_t>(verifier, VT_VERSION, 4) &&
Expand All @@ -567,7 +572,9 @@ struct ModelTraining FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table
VerifyLossFnOptions(verifier, lossfn_opt(), lossfn_opt_type()) &&
VerifyField<int32_t>(verifier, VT_EPOCHS, 4) &&
VerifyField<int32_t>(verifier, VT_BATCH_SIZE, 4) &&
VerifyField<int8_t>(verifier, VT_LOSS_REDUCTION_TYPE, 1) && verifier.EndTable();
VerifyField<int8_t>(verifier, VT_LOSS_REDUCTION_TYPE, 1) &&
VerifyOffset(verifier, VT_TRAINABLE_OPS) && verifier.VerifyVector(trainable_ops()) &&
verifier.EndTable();
}
};

Expand Down Expand Up @@ -649,6 +656,10 @@ struct ModelTrainingBuilder
fbb_.AddElement<int8_t>(ModelTraining::VT_LOSS_REDUCTION_TYPE,
static_cast<int8_t>(loss_reduction_type), 0);
}
void add_trainable_ops(::flatbuffers::Offset<::flatbuffers::Vector<int32_t>> trainable_ops)
{
fbb_.AddOffset(ModelTraining::VT_TRAINABLE_OPS, trainable_ops);
}
explicit ModelTrainingBuilder(::flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb)
{
start_ = fbb_.StartTable();
Expand All @@ -669,9 +680,11 @@ inline ::flatbuffers::Offset<ModelTraining> CreateModelTraining(
circle::LossFn lossfn = circle::LossFn_SPARSE_CATEGORICAL_CROSSENTROPY,
circle::LossFnOptions lossfn_opt_type = circle::LossFnOptions_NONE,
::flatbuffers::Offset<void> lossfn_opt = 0, int32_t epochs = 0, int32_t batch_size = 0,
circle::LossReductionType loss_reduction_type = circle::LossReductionType_SumOverBatchSize)
circle::LossReductionType loss_reduction_type = circle::LossReductionType_SumOverBatchSize,
::flatbuffers::Offset<::flatbuffers::Vector<int32_t>> trainable_ops = 0)
{
ModelTrainingBuilder builder_(_fbb);
builder_.add_trainable_ops(trainable_ops);
builder_.add_batch_size(batch_size);
builder_.add_epochs(epochs);
builder_.add_lossfn_opt(lossfn_opt);
Expand All @@ -685,6 +698,23 @@ inline ::flatbuffers::Offset<ModelTraining> CreateModelTraining(
return builder_.Finish();
}

inline ::flatbuffers::Offset<ModelTraining> CreateModelTrainingDirect(
::flatbuffers::FlatBufferBuilder &_fbb, uint32_t version = 0,
circle::Optimizer optimizer = circle::Optimizer_SGD,
circle::OptimizerOptions optimizer_opt_type = circle::OptimizerOptions_NONE,
::flatbuffers::Offset<void> optimizer_opt = 0,
circle::LossFn lossfn = circle::LossFn_SPARSE_CATEGORICAL_CROSSENTROPY,
circle::LossFnOptions lossfn_opt_type = circle::LossFnOptions_NONE,
::flatbuffers::Offset<void> lossfn_opt = 0, int32_t epochs = 0, int32_t batch_size = 0,
circle::LossReductionType loss_reduction_type = circle::LossReductionType_SumOverBatchSize,
const std::vector<int32_t> *trainable_ops = nullptr)
{
auto trainable_ops__ = trainable_ops ? _fbb.CreateVector<int32_t>(*trainable_ops) : 0;
return circle::CreateModelTraining(_fbb, version, optimizer, optimizer_opt_type, optimizer_opt,
lossfn, lossfn_opt_type, lossfn_opt, epochs, batch_size,
loss_reduction_type, trainable_ops__);
}

inline bool VerifyOptimizerOptions(::flatbuffers::Verifier &verifier, const void *obj,
OptimizerOptions type)
{
Expand Down

0 comments on commit 63e81d0

Please sign in to comment.