Onnxify 0.1.0

dotnet add package Onnxify --version 0.1.0
                    
NuGet\Install-Package Onnxify -Version 0.1.0
                    
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" Version="0.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Onnxify" Version="0.1.0" />
                    
Directory.Packages.props
<PackageReference Include="Onnxify" />
                    
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 --version 0.1.0
                    
#r "nuget: Onnxify, 0.1.0"
                    
#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@0.1.0
                    
#: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&version=0.1.0
                    
Install as a Cake Addin
#tool nuget:?package=Onnxify&version=0.1.0
                    
Install as a Cake Tool

Onnxify

Onnxify is for programmatic ONNX model work in .NET: open an existing .onnx, inspect the graph, modify it, save it back, or build a model from scratch in C#.

Install

dotnet add package Onnxify

Why This Package Exists

ONNX is often used as a model interchange format, but in .NET there is usually an awkward gap between two extremes:

  • an inference runtime can execute a model, but usually does very little to help you rewrite it;
  • the protobuf layer lets you do almost anything, but it is too low-level for day-to-day engineering work.

Onnxify is meant to fill exactly that space. The package exists for cases where an ONNX model is not just an artifact you "run and forget", but something you need to read, understand, version, patch, and generate programmatically.

In practice, it helps with scenarios like these:

  • open an existing ONNX model and quickly understand its inputs, outputs, initializers, and nodes;
  • patch a graph in C# without dropping down into raw protobuf manipulation;
  • generate ONNX as the output of your own tool, exporter, converter, or build pipeline;
  • keep graph structure, value types, shapes, and opset versions in normal .NET code instead of manual protobuf plumbing.

In short, Onnxify is for teams that need control, transparency, and editability around ONNX in .NET.

What The Package Provides

  • OnnxModel.FromFile(...) and Save(...) for reading and writing .onnx files.
  • OnnxModel.Create(...) for creating a new model from scratch.
  • OnnxGraph for working with inputs, outputs, intermediate values, initializers, and nodes.
  • Typed value and tensor descriptions through OnnxValue, OnnxTensor<T>, and OnnxTensorType.
  • Explicit operator construction through AddNode(...) and typed operator wrappers when they are available.
  • ValidateCompatibility(...) for structural compatibility checks.

Quick Start

  • If you want the first copy-paste example to run as-is, start with Build A Small ONNX Model Manually.
  • If you already have a .onnx file and want to inspect it, use Open A Model And Inspect The Graph.

Example: Open A Model And Inspect The Graph

This snippet assumes you already have an ONNX file on disk. Replace "model.onnx" with the path to a real model in your project or local workspace.

using System.Linq;
using Onnxify;

var model = OnnxModel.FromFile("model.onnx");

Console.WriteLine($"Producer: {model.ProducerName}");
Console.WriteLine($"IR version: {model.IrVersion}");
Console.WriteLine($"Opsets: {string.Join(", ", model.OpsetImport.Select(x => $"{x.Domain}:{x.Version}"))}");
Console.WriteLine($"Inputs: {model.Graph.Inputs.Count}");
Console.WriteLine($"Outputs: {model.Graph.Outputs.Count}");
Console.WriteLine($"Nodes: {model.Graph.Nodes.Count}");

foreach (var input in model.Graph.Inputs)
{
    Console.WriteLine($"Input: {input.Name} -> {input}");
}

var weights = model.Graph.Initializers
    .OfType<OnnxTensor<float>>()
    .FirstOrDefault(x => x.Name == "weights");

if (weights is not null)
{
    Console.WriteLine($"Weights shape: [{string.Join(", ", weights.Shape)}]");
    Console.WriteLine($"Preview: {weights}");
}

This is useful when a model comes from somewhere else and the first step is understanding it before changing anything.

Example: Build A Small ONNX Model Manually

using Onnxify;

var model = OnnxModel.Create(new OnnxModelCreationOptions
{
    ProducerName = "demo",
    Opset = 18,
});

var graph = model.Graph;
graph.Name = "bias_add";

var input = graph.AddInput(
    name: "input",
    type: OnnxTensorType.Create<float>(["batch", 4])
);

var bias = graph.AddTensor(
    name: "bias",
    shape: [4],
    value: [0.1f, 0.2f, 0.3f, 0.4f]
);

var hidden = graph.Add(
    name: "add_bias",
    options: new AddInputOptions
    {
        A = input,
        B = bias,
    }
);

var outputEdge = graph.AddEdge("output");

graph.Identity(
    name: "publish_output",
    options: new IdentityInputOutputOptions
    {
        Input = hidden,
        Output = outputEdge,
    }
);

graph.AddOutput(
    name: "output",
    type: OnnxTensorType.Create<float>(["batch", 4])
);

model.AddMetadataProps("author", "onnxify-demo");
model.Save("bias_add.onnx", overwrite: true);

This approach is useful when the ONNX model is generated by your own code instead of being exported from an external framework. It is also the best first smoke test if you want to verify that the package is installed and working in a new project.

Recommendations

  • Use OnnxModel.FromFile(...) when you are adapting an existing ONNX model and want to make targeted changes without working directly with protobuf APIs.
  • Use OnnxModel.Create(...) when the ONNX graph is the end product of your own generator, exporter, or toolchain.
  • Set Opset explicitly, and use SetOpsetImport(...) when needed, if you are working beyond the default ai.onnx domain or targeting a specific runtime.
  • Run ValidateCompatibility(...) before publishing or handing models off to other systems, especially when graphs are generated or modified automatically.
  • If the source model uses external tensor data, configure DataLocation and DataReader. The current Onnxify serialization flow writes tensors back as embedded data by default.
  • Use the base Onnxify package when your main need is direct control over the ONNX graph itself. If the task is more specialized, look at the neighboring packages:
  • Onnxify.TorchSharp for exporting TorchSharp models into a controllable ONNX graph.
  • Onnxify.ModelGenerator for generating typed wrappers from an existing .onnx.
  • Microsoft.ML.OnnxRuntime if you only need inference and not model editing.

Repository

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Onnxify:

Package Downloads
Onnxify.TorchSharp

TorchSharp-to-ONNX export layer for translating TorchSharp modules and model structure into explicit Onnxify graph operations.

Onnxify.ProjectGenerator

Code generation library that turns an existing ONNX model into a C# project or program that reconstructs the model through the Onnxify API.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.0 67 5/18/2026
0.0.0.15 66 5/18/2026
0.0.0.14 84 5/17/2026
0.0.0.13 92 5/14/2026

## 0.0.0.1

- Initial release