Onnxify.ModelGenerator 0.0.0.14

There is a newer version of this package available.
See the version list below for details.
dotnet add package Onnxify.ModelGenerator --version 0.0.0.14
                    
NuGet\Install-Package Onnxify.ModelGenerator -Version 0.0.0.14
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Onnxify.ModelGenerator" Version="0.0.0.14">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Onnxify.ModelGenerator" Version="0.0.0.14" />
                    
Directory.Packages.props
<PackageReference Include="Onnxify.ModelGenerator">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Onnxify.ModelGenerator --version 0.0.0.14
                    
#r "nuget: Onnxify.ModelGenerator, 0.0.0.14"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Onnxify.ModelGenerator@0.0.0.14
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Onnxify.ModelGenerator&version=0.0.0.14
                    
Install as a Cake Addin
#tool nuget:?package=Onnxify.ModelGenerator&version=0.0.0.14
                    
Install as a Cake Tool

Onnxify.ModelGenerator

Onnxify.ModelGenerator is a Roslyn source generator that turns .onnx files in your project into typed Microsoft.ML.OnnxRuntime wrapper classes.

Install

dotnet add package Onnxify.ModelGenerator

In a real consumer project you will typically also reference Onnxify and Microsoft.ML.OnnxRuntime, because the generated code uses Onnxify metadata types and executes through ONNX Runtime.

When To Use It

Use Onnxify.ModelGenerator when you already have an ONNX model and want:

  • strongly typed wrapper classes instead of hand-written InferenceSession plumbing
  • generated input and output contracts based on the real ONNX signature
  • fewer hard-coded input and output names in application code
  • a small, reusable inference surface for app or service code

Use the main Onnxify package instead when your goal is to build, inspect, or edit ONNX graphs directly.

What It Provides

  • Detect .onnx files added to the consuming project through the OnnxModel MSBuild item.
  • Generate typed input and output contracts from the model signature.
  • Emit a thin InferenceSession wrapper with Run(...) overloads for Microsoft.ML.OnnxRuntime.
  • Surface model input and output metadata in generated code for runtime inspection.
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net10.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Onnxify" Version="0.0.0.11" />
    <PackageReference Include="Onnxify.ModelGenerator" Version="0.0.0.11" />
    <PackageReference Include="Microsoft.ML.OnnxRuntime" Version="1.23.2" />
  </ItemGroup>

  <ItemGroup>
    <OnnxModel Include="Models\sample-classifier.onnx" />
  </ItemGroup>
</Project>

The packaged .targets file forwards OnnxModel items to Roslyn as additional files and keeps the model copied to the output directory by default.

Naming Overrides

If you want a custom namespace or class name, set metadata on the OnnxModel item:

<ItemGroup>
  <OnnxModel Include="Models\sample-classifier.onnx"
             OnnxifyModelNamespace="MyApp.Models"
             OnnxifyModelClassName="SampleClassifier" />
</ItemGroup>

This generates a wrapper named SampleClassifierModel in namespace MyApp.Models.

Runtime Example

Assuming the ONNX model exposes an input named input_ids and an output named logits:

using Microsoft.ML.OnnxRuntime.Tensors;
using MyApp.Models;

var model = new SampleClassifierModel();

var inputIds = new DenseTensor<long>(
    values: new long[] { 101, 2023, 2003, 1037, 3231, 102 },
    dimensions: new[] { 1, 6 }
);

using var outputs = model.Run(inputIds);
Tensor<float> logits = outputs.Logits;

You can also use the generated input contract object:

using Microsoft.ML.OnnxRuntime.Tensors;
using MyApp.Models;

var model = new SampleClassifierModel();

var inputs = new SampleClassifierModelInputs
{
    InputIds = new DenseTensor<long>(
        values: new long[] { 101, 7592, 2088, 102 },
        dimensions: new[] { 1, 4 }
    )
};

using var outputs = model.Run(inputs);
Tensor<float> logits = outputs.Logits;

Notes

  • The default constructor loads the model from DefaultModelPath, which resolves relative to the application output folder.
  • Optional ONNX inputs become nullable tensor properties and nullable tensor parameters in generated Run(...) overloads.
  • Models that use external tensor data still require their sibling external-data files at deployment time.
  • If you need to wire ONNX files manually, the generator ultimately reads Roslyn additional files, but the recommended project-facing entry point is OnnxModel.

Repository

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.1 41 5/20/2026
0.1.0 86 5/18/2026
0.0.0.15 89 5/18/2026
0.0.0.14 88 5/17/2026
0.0.0.13 86 5/14/2026

## 0.0.0.14

- Added `Microsoft.ML.OnnxRuntime.Float16` support for generated wrappers over ONNX `float16` tensor inputs and outputs.
- Added `Microsoft.ML.OnnxRuntime.BFloat16` support for generated wrappers over ONNX `bfloat16` tensor inputs and outputs.

## 0.0.0.8

- Initial release