Represent a runtime instance of an ONNX training session, which contains a model that can be trained, and, optionally, an eval and optimizer model.

interface TrainingSession {
    evalInputNames: readonly string[];
    evalOutputNames: readonly string[];
    trainingInputNames: readonly string[];
    trainingOutputNames: readonly string[];
    getContiguousParameters(trainableOnly): Promise<Tensor>;
    getParametersSize(trainableOnly): Promise<number>;
    lazyResetGrad(): Promise<void>;
    loadParametersBuffer(buffer, trainableOnly): Promise<void>;
    release(): Promise<void>;
    runEvalStep(feeds, options?): Promise<OnnxValueMapType>;
    runEvalStep(feeds, fetches, options?): Promise<OnnxValueMapType>;
    runOptimizerStep(options?): Promise<void>;
    runTrainStep(feeds, options?): Promise<OnnxValueMapType>;
    runTrainStep(feeds, fetches, options?): Promise<OnnxValueMapType>;
}

Properties

evalInputNames: readonly string[]

Get input names of the loaded eval model. Is an empty array if no eval model is loaded.

evalOutputNames: readonly string[]

Get output names of the loaded eval model. Is an empty array if no eval model is loaded.

trainingInputNames: readonly string[]

Get input names of the loaded training model.

trainingOutputNames: readonly string[]

Get output names of the loaded training model.

Methods

  • Copies the model parameters to a contiguous buffer. Usually used in the context of Federated Learning. Currently, only supporting models with parameters of type Float32.

    Parameters

    • trainableOnly: boolean

      When set to true, only trainable parameters are copied. Trainable parameters are parameters for which requires_grad is set to true. Default value is true.

    Returns Promise<Tensor>

    A promise that resolves to a Float32 OnnxValue of the requested parameters.

  • Retrieves the size of all parameters for the training state. Calculates the total number of primitive (datatype of the parameters) elements of all the parameters in the training state.

    Parameters

    • trainableOnly: boolean

      When set to true, the size is calculated for trainable params only. Default value is true.

    Returns Promise<number>

  • Lazily resets the gradients of all trainable parameters to zero. Should happen after the invocation of runOptimizerStep.

    Returns Promise<void>

  • Copies parameter values from the given buffer to the training state. Currently, only supporting models with parameters of type Float32.

    Parameters

    • buffer: Uint8Array

      A Uint8Array representation of Float32 parameters.

    • trainableOnly: boolean

      True if trainable parameters only to be modified, false otherwise. Default value is true.

    Returns Promise<void>

  • Release the inference session and the underlying resources.

    Returns Promise<void>

  • Run a single eval step with the given inputs and options using the eval model.

    Parameters

    • feeds: OnnxValueMapType

      Representation of the model input.

    • Optional options: RunOptions

      Optional. A set of options that controls the behavior of model eval step.

    Returns Promise<OnnxValueMapType>

    A promise that resolves to a map, which uses output names as keys and OnnxValue as corresponding values.

  • Run a single eval step with the given inputs and options using the eval model.

    Parameters

    • feeds: OnnxValueMapType

      Representation of the model input.

    • fetches: FetchesType

      Representation of the model output. detail.

    • Optional options: RunOptions

      Optional. A set of options that controls the behavior of model eval step.

    Returns Promise<OnnxValueMapType>

    A promise that resolves to a map, which uses output names as keys and OnnxValue as corresponding values.

  • Runs a single optimizer step, which performs weight updates for the trainable parameters using the optimizer model.

    Parameters

    • Optional options: RunOptions

      Optional. A set of options that controls the behavior of model optimizing.

    Returns Promise<void>

  • Run TrainStep asynchronously with the given feeds and options.

    Parameters

    • feeds: OnnxValueMapType

      Representation of the model input. See type description of InferenceSession.InputType for detail.

    • Optional options: RunOptions

      Optional. A set of options that controls the behavior of model training.

    Returns Promise<OnnxValueMapType>

    A promise that resolves to a map, which uses output names as keys and OnnxValue as corresponding values.

  • Run a single train step with the given inputs and options.

    Parameters

    • feeds: OnnxValueMapType

      Representation of the model input.

    • fetches: FetchesType

      Representation of the model output. detail.

    • Optional options: RunOptions

      Optional. A set of options that controls the behavior of model training.

    Returns Promise<OnnxValueMapType>

    A promise that resolves to a map, which uses output names as keys and OnnxValue as corresponding values.

Generated using TypeDoc