VOOZH about

URL: https://www.nuget.org/packages/Microsoft.ML.OnnxRuntimeGenAI/

⇱ NuGet Gallery | Microsoft.ML.OnnxRuntimeGenAI 0.14.1




Microsoft.ML.OnnxRuntimeGenAI 0.14.1

Prefix Reserved
dotnet add package Microsoft.ML.OnnxRuntimeGenAI --version 0.14.1
 
 
NuGet\Install-Package Microsoft.ML.OnnxRuntimeGenAI -Version 0.14.1
 
 
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="Microsoft.ML.OnnxRuntimeGenAI" Version="0.14.1" />
 
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Microsoft.ML.OnnxRuntimeGenAI" Version="0.14.1" />
 
Directory.Packages.props
<PackageReference Include="Microsoft.ML.OnnxRuntimeGenAI" />
 
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 Microsoft.ML.OnnxRuntimeGenAI --version 0.14.1
 
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Microsoft.ML.OnnxRuntimeGenAI, 0.14.1"
 
 
#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 Microsoft.ML.OnnxRuntimeGenAI@0.14.1
 
 
#: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=Microsoft.ML.OnnxRuntimeGenAI&version=0.14.1
 
Install as a Cake Addin
#tool nuget:?package=Microsoft.ML.OnnxRuntimeGenAI&version=0.14.1
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

About

Run Llama, Phi (language and multi modal!), DeepSeek, Gemma, Mistral with ONNX Runtime.

This API gives you an easy, flexible and performant way of running LLMs on device using .NET/C#.

It implements the generative AI loop for ONNX models, including pre and post processing, inference with ONNX Runtime, logits processing, search and sampling, and KV cache management.

Key Features

  • Language, vision, and audio pre and post processing
  • Inference using ONNX Runtime
  • Generation tuning with greedy, beam search and random sampling
  • KV cache management to optimize performance
  • Multi target execution (CPU, GPU, with NPU coming!)

Sample

// See https://aka.ms/new-console-template for more information
using Microsoft.ML.OnnxRuntimeGenAI;

using OgaHandle ogaHandle = new OgaHandle();

// Specify the location of your downloaded model.
// Many models are published on HuggingFace e.g. 
// https://huggingface.co/microsoft/Phi-3-mini-4k-instruct-onnx
string modelPath = "..."
Console.WriteLine("Model path: " + modelPath);

using Model model = new Model(modelPath);
using Tokenizer tokenizer = new Tokenizer(model);
using var tokenizerStream = tokenizer.CreateStream();

// Set your prompt here
string prompt = "public static bool IsPrime(int number)";
var sequences = tokenizer.Encode($"<|user|>{prompt}<|end|><|assistant|>");

using GeneratorParams generatorParams = new GeneratorParams(model);
generatorParams.SetSearchOption("max_length", 512);

using var generator = new Generator(model, generatorParams);
generator.AppendTokenSequences(sequences);
.
while (!generator.IsDone())
{
 generator.GenerateNextToken();
 Console.Write(tokenizerStream.Decode(generator.GetSequence(0)[^1]));
}

Generates the following output:

Here's a complete implementation of the `IsPrime` function in C# that checks if a given number is prime. The function includes basic input validation and comments for clarity.
using System;

namespace PrimeChecker
{
 public class PrimeChecker
 {
 /// <summary>
 /// Checks if the given number is prime.
 /// </summary>
 /// <param name="number">The number to check.</param>
 /// <returns>true if the number is prime; otherwise, false.</returns>
 public static bool IsPrime(int number)
 {
 // Input validation
 if (number < 2)
 {
 return false;
 }

 // 2 is the only even prime number
 if (number == 2)
 {
 return true;
 }

 // Exclude even numbers greater than 2
 if (number % 2 == 0)
 {
 return false;
 }

 // Check for factors up to the square root of the number
 int limit = (int)Math.Floor(Math.Sqrt(number));
 for (int i = 3; i <= limit; i += 2)
 {
 if (number % i == 0)
 {
 return false;
 }
 }

 return true;
 }

 static void Main(string[] args)
 {
 int number = 29;
 bool isPrime = PrimeChecker.IsPrime(number);

 Console.WriteLine($"Is {number} prime? {isPrime}");
 }
 }
}
This implementation checks if a number is prime by iterating only up to the square root of the number, which is an optimization over checking all numbers up to the number itself. It also excludes even numbers greater than 2, as they cannot be prime.

Source code repository

ONNX Runtime is an open source project. See:

Documentation

See ONNX Runtime GenAI Documentation

Product Versions Compatible and additional computed target framework versions.
.NET net5.0 net5.0 was computed.  net5.0-windows net5.0-windows was computed.  net6.0 net6.0 was computed.  net6.0-android net6.0-android was computed.  net6.0-ios net6.0-ios was computed.  net6.0-maccatalyst net6.0-maccatalyst was computed.  net6.0-macos net6.0-macos was computed.  net6.0-tvos net6.0-tvos was computed.  net6.0-windows net6.0-windows was computed.  net7.0 net7.0 was computed.  net7.0-android net7.0-android was computed.  net7.0-ios net7.0-ios was computed.  net7.0-maccatalyst net7.0-maccatalyst was computed.  net7.0-macos net7.0-macos was computed.  net7.0-tvos net7.0-tvos was computed.  net7.0-windows net7.0-windows was computed.  net8.0 net8.0 is compatible.  net8.0-android net8.0-android was computed.  net8.0-browser net8.0-browser was computed.  net8.0-ios net8.0-ios was computed.  net8.0-maccatalyst net8.0-maccatalyst was computed.  net8.0-macos net8.0-macos was computed.  net8.0-tvos net8.0-tvos was computed.  net8.0-windows net8.0-windows was computed.  net9.0 net9.0 was computed.  net9.0-android net9.0-android was computed.  net9.0-android31.0 net9.0-android31.0 is compatible.  net9.0-browser net9.0-browser was computed.  net9.0-ios net9.0-ios was computed.  net9.0-ios15.4 net9.0-ios15.4 is compatible.  net9.0-maccatalyst net9.0-maccatalyst was computed.  net9.0-maccatalyst14.0 net9.0-maccatalyst14.0 is compatible.  net9.0-macos net9.0-macos was computed.  net9.0-tvos net9.0-tvos was computed.  net9.0-windows net9.0-windows was computed.  net10.0 net10.0 was computed.  net10.0-android net10.0-android was computed.  net10.0-browser net10.0-browser was computed.  net10.0-ios net10.0-ios was computed.  net10.0-maccatalyst net10.0-maccatalyst was computed.  net10.0-macos net10.0-macos was computed.  net10.0-tvos net10.0-tvos was computed.  net10.0-windows net10.0-windows was computed. 
.NET Core netcoreapp2.0 netcoreapp2.0 was computed.  netcoreapp2.1 netcoreapp2.1 was computed.  netcoreapp2.2 netcoreapp2.2 was computed.  netcoreapp3.0 netcoreapp3.0 was computed.  netcoreapp3.1 netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 netstandard2.0 is compatible.  netstandard2.1 netstandard2.1 was computed. 
.NET Framework net461 net461 was computed.  net462 net462 was computed.  net463 net463 was computed.  net47 net47 was computed.  net471 net471 was computed.  net472 net472 was computed.  net48 net48 was computed.  net481 net481 was computed. 
MonoAndroid monoandroid monoandroid was computed. 
MonoMac monomac monomac was computed. 
MonoTouch monotouch monotouch was computed. 
native native native is compatible. 
Tizen tizen40 tizen40 was computed.  tizen60 tizen60 was computed. 
Xamarin.iOS xamarinios xamarinios was computed. 
Xamarin.Mac xamarinmac xamarinmac was computed. 
Xamarin.TVOS xamarintvos xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (13)

Showing the top 5 NuGet packages that depend on Microsoft.ML.OnnxRuntimeGenAI:

Package Downloads
Microsoft.SemanticKernel.Connectors.Onnx

Semantic Kernel connectors for the ONNX runtime. Contains clients for text embedding generation.

Microsoft.KernelMemory.AI.Onnx

Provide access to ONNX LLM models in Kernel Memory to generate text

LMSupply.Generator

A .NET library for local LLM text generation using ONNX Runtime GenAI. Supports streaming, chat templates, and automatic hardware detection with CUDA/DirectML GPU acceleration.

feiyun0112.SemanticKernel.Connectors.OnnxRuntimeGenAI.CPU

Semantic Kernel connector for Microsoft.ML.OnnxRuntimeGenAI.

Richasy.AgentKernel.Connectors.Onnx

Agent Kernel connectors for Onnx.

GitHub repositories (6)

Showing the top 6 popular GitHub repositories that depend on Microsoft.ML.OnnxRuntimeGenAI:

Repository Stars
microsoft/semantic-kernel
Integrate cutting-edge LLM technology quickly and easily into your apps
microsoft/kernel-memory
Research project. A Memory solution for users, teams, and applications.
axzxs2001/Asp.NetCoreExperiment
原来所有项目都移动到**OleVersion**目录下进行保留。新的案例装以.net 5.0为主,一部分对以前案例进行升级,一部分将以前的工作经验总结出来,以供大家参考!
rwjdk/MicrosoftAgentFrameworkSamples
Samples demonstrating the Microsoft Agent Framework in C#
Build5Nines/SharpVector
Lightweight, In-memory, Semantic Search, Text Vector Database to embed in any .NET Application
kelnishi/WACS
Pure C# WebAssembly toolchain for .NET - interpreter, AOT transpiler, NativeAOT builder, and component-model bindgen
Version Downloads Last Updated
0.14.1 2,287 6/2/2026
0.14.0 1,525 5/26/2026
0.13.2 4,865 5/1/2026
0.13.1 7,679 4/7/2026
0.13.0 701 4/5/2026
0.12.2 9,585 3/4/2026
0.12.1 2,137 2/24/2026
0.12.0 1,851 2/13/2026
0.11.4 103,453 12/12/2025
0.11.3 1,187 12/8/2025
0.11.2 7,936 11/18/2025
0.11.1 842 11/16/2025
0.11.0 835 11/14/2025
0.10.0 100,034 10/10/2025
0.9.2 27,851 9/16/2025
0.9.1 5,703 9/9/2025
0.9.0 9,062 8/6/2025
0.8.3 71,778 6/30/2025
0.8.2 6,713 6/5/2025
0.8.1 10,306 5/30/2025
Loading failed

Release Def:
Branch: refs/heads/rel-0.14.1
Commit: a30f479af016cb098688726831a9acbb8d19f0b2