Class CheckpointState
Holds the state of the training session. This class holds the entire training session state that includes model parameters, their gradients, optimizer parameters, and user properties. The TrainingSession leverages the CheckpointState by accessing and updating the contained training state.
note
Note that the training session created with a checkpoint state uses this state to store the entire training state (including model parameters, its gradients, the optimizer states and the properties). The TrainingSession does not hold a copy of the CheckpointState and as a result, it is required that the checkpoint state outlives the lifetime of the training session.
Inheritance
Implements
Inherited Members
Namespace: Microsoft.ML.OnnxRuntime
Assembly: Microsoft.ML.OnnxRuntime.dll
Syntax
public class CheckpointState : SafeHandle, IDisposable
Properties
| Improve this Doc View SourceIsInvalid
Overrides SafeHandle.IsInvalid
Declaration
public override bool IsInvalid { get; }
Property Value
Type | Description |
---|---|
Boolean | returns true if handle is equal to Zero |
Overrides
Methods
| Improve this Doc View SourceAddProperty(String, Int64)
Adds or updates the given int property to/in the checkpoint state.
Runtime properties such as epoch, training step, best score, and others can be added to the checkpoint state by the user by calling this function with the corresponding property name and value. The given property name must be unique to be able to successfully add the property.
Declaration
public void AddProperty(string propertyName, long propertyValue)
Parameters
Type | Name | Description |
---|---|---|
String | propertyName | Name of the property being added or updated. |
Int64 | propertyValue | Property value associated with the given name. |
AddProperty(String, Single)
Adds or updates the given float property to/in the checkpoint state.
Runtime properties such as epoch, training step, best score, and others can be added to the checkpoint state by the user by calling this function with the corresponding property name and value. The given property name must be unique to be able to successfully add the property.
Declaration
public void AddProperty(string propertyName, float propertyValue)
Parameters
Type | Name | Description |
---|---|---|
String | propertyName | Name of the property being added or updated. |
Single | propertyValue | Property value associated with the given name. |
AddProperty(String, String)
Adds or updates the given string property to/in the checkpoint state.
Runtime properties such as epoch, training step, best score, and others can be added to the checkpoint state by the user by calling this function with the corresponding property name and value. The given property name must be unique to be able to successfully add the property.
Declaration
public void AddProperty(string propertyName, string propertyValue)
Parameters
Type | Name | Description |
---|---|---|
String | propertyName | Name of the property being added or updated. |
String | propertyValue | Property value associated with the given name. |
GetParameter(String)
Gets the data associated with the model parameter from the checkpoint state for the given parameter name.
This function retrieves the model parameter data from the checkpoint state for the given parameter name. The parameter is copied over to the provided OrtValue. The training session must be already created with the checkpoint state that contains the parameter being retrieved. The parameter must exist in the checkpoint state to be able to retrieve it successfully.
Declaration
public OrtValue GetParameter(string parameterName)
Parameters
Type | Name | Description |
---|---|---|
String | parameterName | Name of the parameter being updated. |
Returns
Type | Description |
---|---|
OrtValue | The parameter data that is retrieved from the checkpoint state. |
GetProperty(String)
Gets the property value associated with the given name from the checkpoint state.
Gets the property value from an existing entry in the checkpoint state. The property must exist in the checkpoint state to be able to retrieve it successfully.
Declaration
public object GetProperty(string propertyName)
Parameters
Type | Name | Description |
---|---|---|
String | propertyName | Name of the property being retrieved. |
Returns
Type | Description |
---|---|
Object | Property value associated with the given property name. |
LoadCheckpoint(String)
Load a checkpoint state from a directory on disk into checkpoint_state.
This function will parse a checkpoint directory, pull relevant files and load the training state into the checkpoint_state. This checkpoint state can then be used to create the training session by instantiating the TrainingSession. By doing so, the training session will begin or resume training from the given checkpoint state.
Declaration
public static CheckpointState LoadCheckpoint(string checkpointPath)
Parameters
Type | Name | Description |
---|---|---|
String | checkpointPath | Absolute path to the checkpoint directory. |
Returns
Type | Description |
---|---|
CheckpointState | CheckpointState object which holds the state of the training session parameters. |
ReleaseHandle()
Overrides SafeHandle.ReleaseHandle() to properly dispose of the native instance of CheckpointState
Declaration
protected override bool ReleaseHandle()
Returns
Type | Description |
---|---|
Boolean | always returns true |
Overrides
SaveCheckpoint(CheckpointState, String, Boolean)
Save the given state to a checkpoint directory on disk.
This function serializes the provided checkpoint state to a directory on disk. This checkpoint can later be loaded by invoking CheckpointState.LoadCheckpoint to begin or resume training from this snapshot of the state.
Declaration
public static void SaveCheckpoint(CheckpointState state, string checkpointPath, bool includeOptimizerState = false)
Parameters
Type | Name | Description |
---|---|---|
CheckpointState | state | The checkpoint state to save. |
String | checkpointPath | Absolute path to the checkpoint directory. |
Boolean | includeOptimizerState | Flag to indicate whether to save the optimizer state or not. |
UpdateParameter(String, OrtValue)
Updates the data associated with the model parameter in the checkpoint state for the given parameter name.
This function updates a model parameter in the checkpoint state with the given parameter data. The training session must be already created with the checkpoint state that contains the parameter being updated. The given parameter is copied over to the registered device for the training session. The parameter must exist in the checkpoint state to be able to update it successfully.
Declaration
public void UpdateParameter(string parameterName, OrtValue parameter)
Parameters
Type | Name | Description |
---|---|---|
String | parameterName | Name of the parameter being updated. |
OrtValue | parameter | The parameter data that should replace the existing parameter data. |