Skip to content
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

[DRAFT][onert-micro] Onert-micro training PoCv3 #13107

Closed

Conversation

BalyshevArtem
Copy link
Contributor

This draft introduces third version of the onert-micro training runtime. This is for one-stage training (without generating backprop graph part) and without weight divider.

for issue: #12873

ONE-DCO-1.0-Signed-off-by: Artem Balyshev [email protected]

@BalyshevArtem BalyshevArtem changed the title [DRAFT][onert-micro] Onert-micro training PoCv2 [DRAFT][onert-micro] Onert-micro training PoCv3 Jun 4, 2024

printf("MAE_ERROR TEST = %f\n", mae_result);
// Save training result
saveModel(output_trained_file_path, circle_model);
Copy link
Contributor

@chunseoklee chunseoklee Jun 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may be exposed via API(

NNFW_STATUS nnfw_train_export_circle(nnfw_session *session, const char *path);
). Thus, circle_model or model_ptr should be kept in some context.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, move this function insert OMTrainingInterpreter, right?

auto data = reinterpret_cast<float *>(interpreter.readOutputTensor(0));
// Temporary buffer to read input data from file using BATCH_SIZE
float training_input[BATCH_SIZE * INPUT_SIZE];
float training_target[BATCH_SIZE * OUTPUT_SIZE];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

label data for CCE is one hot encoding. You will feed int label data by converting into float ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think it is one of the preprocessing step. And we have (for cross-etropy task) as input already preprocessed one-hot encoded float data. Do you think it is better to move it into runtime?

// Averaged result
{
float *f_metric_val = reinterpret_cast<float *>(metric_val);
*f_metric_val /= test_size;
Copy link
Contributor

@Torrero Torrero Jun 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it reasonable to insert assert for checking test_size not equal zero?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, thank you, I will add assert here


for (uint32_t i = 0; i < flat_size; ++i)
{
result_value += std::pow((calculated_data[i] - target_data[i]), 2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here std::pow() can be replace by multiplication

@BalyshevArtem
Copy link
Contributor Author

@chunseoklee, I added checkpoints saving and loading api:

train_interpreter.saveCheckpoint(config, checkpoints_path);

train_interpreter.loadCheckpoint(config, checkpoints_path);

It it similar to #12997 (comment)

@BalyshevArtem
Copy link
Contributor Author

@chunseoklee, I added checkpoints saving and loading api:

train_interpreter.saveCheckpoint(config, checkpoints_path);

train_interpreter.loadCheckpoint(config, checkpoints_path);

It it similar to #12997 (comment)

To check format of the checkpoint file please see #13037 (comment)

cur_batch_size = std::max(1u, cur_batch_size);

config.training_context.batch_size = cur_batch_size;
config.training_context.num_step = i + 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIU, num_step for ADAM optimizer should not be reset by each epoch.

Suggested change
config.training_context.num_step = i + 1;
config.training_context.num_step++;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or

Suggested change
config.training_context.num_step = i + 1;
config.training_context.adam_step++;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, I will change it

@BalyshevArtem
Copy link
Contributor Author

@chunseoklee, can I start split this draft ad merging it?

@chunseoklee
Copy link
Contributor

@chunseoklee, can I start split this draft ad merging it?

Sure.

@chunseoklee
Copy link
Contributor

@BalyshevArtem I am trying to make onert-micro-dev module, which implement nnfw api on https://github.com/chunseoklee/ONE/commits/v3/. After drafting this, I am going to apply this to your TizenRT internal commit.

* Warning: before using trainSingleStep call: 1) importTrainModel; 2) setInput; 3) setTarget
*/
OMStatus OMTrainingRuntimeModule::trainSingleStep(const OMConfig &config)
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{
{
config.training_context.num_step++;

we need this for update num_step for ADAM.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, and to save this value in checkpoints files (if needed method will call)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean we need somewhere to keep this num_step value

* num_of_train_layers - number of trainable last layers (Note: 0 - all layers will be trained)
* optimizer - optimizer which onert-micro training will be used (Note: SGD - default one)
* loss - loss which onert-micro training will be used (Note: CROSS_ENTROPY - default one)
* lambda - used by all optimizers
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this learning rate ? then how about using lr or learning_rate ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, sure

Comment on lines +71 to +75
TEST_F(BostonHousingTaskTest, ADAM_MSE_P)
{
// Create BostonHousing data handler
BostonHousingTask<float> bostonTask;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added tests

Artem Balyshev added 5 commits June 17, 2024 12:38
This draft introduces second version of the onert-micro training runtime. This is for one-stage training (without generating backprop graph part). Also this draft introduces weight divider tool.

ONE-DCO-1.0-Signed-off-by: Artem Balyshev <[email protected]>
@BalyshevArtem
Copy link
Contributor Author

Everything is merged, close it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants