Skip to content

[Training] Using C++ to train ONNX models #23170

Open
@tzsz0

Description

@tzsz0

Describe the issue

Hello,
technically this also includes [Documentation] and [Building]. This just feels the closest.
I'd like to train a ONNX model in my C++ application. For this use case I have encountered multiple examples that seem to do the job. The closest is: MNIST example from the repo . However, the main issue here is that those namespaces/declarations are not usable when using the precompiled archive from the release-page. I downloaded the most recent version 1.20.1.
As far as I am aware, only the onnxruntime_c_api.h and onnxruntime_cxx_api.h are intended for direct use there.

Using those APIs, I have encountered the following documentation: Doxygen doc. The thing about this code sample is that it also doesn't work. There is no header onnxruntime_training_api.h and the following code is returning a nullptr.

    OrtApi const * ortapi = OrtGetApiBase()->GetApi(ORT_API_VERSION);

    OrtTrainingApi const * trainapi = ortapi->GetTrainingApi(ORT_API_VERSION);

    std::cout << (trainapi == nullptr ? "unavailable" : "available") << std::endl;

According to the documentation in the headerfile, this means that the training API is not available in this build.

Now I am left a bit confused because I don't know how I should start training process. Maybe I overlooked some documentation? Most of it is in Python, so it does not really apply to my case.
Primarily I don't understand:

  • Which API should I use? The one from the precompiled binaries or the one that uses the project's internals (namespace onnxruntime)?
  • If I should use GetTrainingApi(), how do I enable it? Do I need to recompile ONNXRuntime?
  • What is the best way to include onnxruntime in a C++ project that uses training?

To reproduce

  • Download the latest precompiled release (here v.1.20.1) of onnxruntime
  • Extract it
  • Link it with the above code

Urgency

The project mentioned before is part of my final/thesis project for university. That makes it not super urgent but I need to get done in the next few months.

ONNX Runtime Installation

Released Package

ONNX Runtime Version or Commit ID

v1.20.1

PyTorch Version

Didn't get that far

Execution Provider

Other / Unknown

Execution Provider Library Version

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    staleissues that have not been addressed in a while; categorized by a bottrainingissues related to ONNX Runtime training; typically submitted using template

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions