onnxruntime/onnxruntime/core/flatbuffers/checkpoint_version.h
Baiju Meswani 10ba1e270c
Minimal Build for On-Device Training (#16326)
🛠️ __Changes in this pull request:__

This pull request introduces two significant changes to the project:

- Changing on device training checkpoint format: The current
implementation stores the on device training checkpoint as a sequence of
tensors in multiple files inside a checkpoint folder, which can be
inefficient in terms of storage and performance. In this PR, I have
modified the checkpoint format to utilize the flatbuffer table to save
the checkpoint to a single file, providing a more compact and efficient
representation. The changes around this are twofold:
- Add the checkpoint flatbuffer schema that will generate the necessary
checkpoint source files.
- Update the checkpoint saving and loading functionality to use the new
format.

- Adding support for onnxruntime minimal build: To support scenarios
where binary size is a constraint, I made changes to ensure that the
training build can work well with the minimal build.

🔍 __Open Issues:__
- In order to extract the optimizer type, the existing implementation
re-loaded the onnx optimizer model and parsed it. This is no longer
possible, since the model format can either be onnx or ort. One idea is
to do the same for ort format optimizer model. This needs some
investigation.
- Changes to the offline tooling to generate ort format training
artifacts.
- End-to-end training example showcasing the use of the minimal training
build.
- Add support for export model for inferencing in a minimal build.
2023-06-22 12:27:23 -07:00

27 lines
1.1 KiB
C++

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#pragma once
namespace onnxruntime {
// The versions below highlight the checkpoint format version history.
// Everytime the checkpoint format changes, the version should be incremented
// and the changes should be documented here and in the
// onnxruntime/core/flatbuffers/schema/README.md file.
// Version 1: Introduces the On-Device Training Checkpoint format
// The format includes support for the ModuleState (stores the module parameters), OptimizerGroups
// (stores the optimizer states), and PropertyBag
// (stores custom user properties with support for int64, float and strings).
constexpr const int kCheckpointVersion = 1;
/**
* @brief Check if the given checkpoint version is supported in this build
* @param checkpoint_version The checkpoint version to check
* @return true if the checkpoint version is supported, false otherwise
*/
inline constexpr bool IsCheckpointVersionSupported(const int checkpoint_version) {
return kCheckpointVersion == checkpoint_version;
}
} // namespace onnxruntime