Microsoft.ML.OnnxRuntimeGenAI.Foundry
0.19.0
Prefix Reserved
dotnet add package Microsoft.ML.OnnxRuntimeGenAI.Foundry --version 0.19.0
NuGet\Install-Package Microsoft.ML.OnnxRuntimeGenAI.Foundry -Version 0.19.0
<PackageReference Include="Microsoft.ML.OnnxRuntimeGenAI.Foundry" Version="0.19.0" />
<PackageVersion Include="Microsoft.ML.OnnxRuntimeGenAI.Foundry" Version="0.19.0" />
<PackageReference Include="Microsoft.ML.OnnxRuntimeGenAI.Foundry" />
paket add Microsoft.ML.OnnxRuntimeGenAI.Foundry --version 0.19.0
#r "nuget: Microsoft.ML.OnnxRuntimeGenAI.Foundry, 0.19.0"
#:package Microsoft.ML.OnnxRuntimeGenAI.Foundry@0.19.0
#addin nuget:?package=Microsoft.ML.OnnxRuntimeGenAI.Foundry&version=0.19.0
#tool nuget:?package=Microsoft.ML.OnnxRuntimeGenAI.Foundry&version=0.19.0
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
ONNX Runtime dependency
GenAI NuGet packages do not bundle ONNX Runtime binaries. ONNX Runtime is
supplied by separate runtime packages. The WinML NuGet depends on
Microsoft.Windows.AI.MachineLearning for its runtime.
Linux ARM64 CUDA
The CUDA NuGet contains the Linux ARM64 GenAI core and CUDA add-on under
runtimes/linux-arm64/native, but does not bundle ONNX Runtime libraries.
Linux ARM64 consumers must provide a compatible ONNX Runtime GPU 1.30.0 native
installation separately, along with a CUDA 13.1 runtime and a compatible NVIDIA
driver. Other RIDs continue to obtain ONNX Runtime from the NuGet dependency.
The .Foundry package carries the Linux ARM64 CUDA GenAI core, but deliberately
excludes the CUDA shim and ONNX Runtime libraries, as it does for Linux x64.
Its Linux ARM64 consumer must provide a compatible ONNX Runtime GPU 1.30.0
native installation separately.
0.19.0 migration note
The Linux ARM64 CUDA NuGet no longer includes ONNX Runtime binaries.
Applications must obtain a compatible ONNX Runtime GPU 1.30.0 native
installation separately. The GenAI core and CUDA add-on remain in the package.
The WinML Python wheel now depends on the standard onnxruntime Python package
instead of bundling WinML SDK runtime DLLs.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. 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 was computed. 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. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| native | native is compatible. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETCoreApp 0.0
- Microsoft.ML.OnnxRuntimeGenAI.Managed (>= 0.19.0)
-
.NETFramework 0.0
- Microsoft.ML.OnnxRuntimeGenAI.Managed (>= 0.19.0)
-
.NETStandard 0.0
- Microsoft.ML.OnnxRuntimeGenAI.Managed (>= 0.19.0)
-
net9.0-android31.0
- Microsoft.ML.OnnxRuntimeGenAI.Managed (>= 0.19.0)
-
net9.0-ios15.4
- Microsoft.ML.OnnxRuntimeGenAI.Managed (>= 0.19.0)
-
net9.0-maccatalyst14.0
- Microsoft.ML.OnnxRuntimeGenAI.Managed (>= 0.19.0)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on Microsoft.ML.OnnxRuntimeGenAI.Foundry:
| Package | Downloads |
|---|---|
|
Microsoft.AI.Foundry.Local.Core
Microsoft Foundry Local Core native library - Native AOT compiled multi-platform AI inference library |
|
|
Microsoft.AI.Foundry.Local.Core.WinML
Microsoft Foundry Local Core WinML native library - Native AOT compiled Windows AI inference library with WinML support |
|
|
Microsoft.AI.Foundry.Local.Runtime
Native runtime libraries for the Microsoft AI Foundry Local SDK. Contains platform-specific foundry_local binaries for Windows (x64, ARM64), Linux (x64, ARM64 CPU-only), and macOS (ARM64). |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.19.0 | 605 | 11/4/2026 |
| 0.18.0 | 29,319 | 10/14/2026 |
| 0.17.1 | 28,962 | 9/29/2026 |
| 0.17.0 | 2,216 | 9/25/2026 |
| 0.16.0 | 1,784 | 9/13/2026 |
| 0.15.2 | 106,678 | 8/6/2026 |
| 0.15.1 | 1,558 | 8/2/2026 |
| 0.15.0 | 273 | 7/29/2026 |
| 0.14.1 | 529,754 | 6/2/2026 |
| 0.14.0 | 31,365 | 5/26/2026 |
| 0.13.2 | 49,100 | 5/1/2026 |
| 0.13.1 | 28,274 | 4/7/2026 |
| 0.13.0 | 1,993 | 4/5/2026 |
| 0.12.2 | 10,222 | 3/4/2026 |
| 0.12.1 | 727 | 2/24/2026 |
| 0.12.0 | 521 | 2/13/2026 |
| 0.11.4 | 2,861 | 12/12/2025 |
| 0.11.3 | 619 | 12/8/2025 |
| 0.11.2 | 29,372 | 11/18/2025 |
| 0.11.0 | 523 | 11/14/2025 |
Release Def:
Branch: refs/heads/rel-0.19.0
Commit: d01b2441a72d4e3223415b9b08474c6e65fbc028