Repository navigation
Deploy the opt-in CUDA backend to the C# GGUF samples - #45
Merged
Merged
Conversation
build.ps1 -LlamaCuda set WinMLSamplesLlamaCuda only for the MSBuild restore and build of the C++ projects. The C# samples build through dotnet with their own arguments, so the four C# GGUF samples kept only the CPU backend while the build reported CPU and CUDA. The Runtime and Tasks build scripts now pass the property to the C# builds too, and hello-language-model-csharp, task-model-text-generation-csharp, task-chat-completion-csharp and task-text-generation-features-csharp reference Microsoft.Windows.AI.MachineLearning.LibLlama under it, as their C++ counterparts do. The GGUF guide and the Tasks README now say the switch covers the C# samples. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ca5b72cf-ae75-4384-9fc4-a6081b9fddea
Nick Eubanks (nieubank)
requested review from
adrastogi
and
a balanced review from Copilot
November 18, 2026 00:41
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues were identified for the opt-in CUDA support added to the four C# GGUF samples.
No open issues 🎉
What changed in this PR
Extends the existing opt-in CUDA backend deployment to the four C# GGUF samples in the Runtime and Tasks catalogs, keeping the CPU backend as the default.
Changes:
- Pass
WinMLSamplesLlamaCudato the C#dotnetbuilds in both catalogs. - Conditionally reference
Microsoft.Windows.AI.MachineLearning.LibLlamain all four C# GGUF projects. - Update documentation to state that
-LlamaCudasupports C++ and C#.
| File | Description |
|---|---|
Samples/Tasks/README.md |
Documents C# support for the CUDA switch. |
Samples/Tasks/model-backed/text-generation/csharp/task-model-text-generation-csharp.csproj |
Adds the conditional CUDA package reference. |
Samples/Tasks/model-backed/text-generation-features/csharp/task-text-generation-features-csharp.csproj |
Adds the conditional CUDA package reference. |
Samples/Tasks/language/chat-completion/csharp/task-chat-completion-csharp.csproj |
Adds the conditional CUDA package reference. |
Samples/Tasks/build.ps1 |
Forwards the CUDA property to C# builds. |
Samples/Runtime/language/hello-language-model/csharp/hello-language-model-csharp.csproj |
Adds the conditional CUDA package reference. |
Samples/Runtime/build.ps1 |
Forwards the CUDA property to C# builds. |
docs/Runtime/gguf-models.md |
Expands CUDA deployment guidance to include C#. |
Review effort: Balanced
adrastogi
approved these changes
Nov 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
build.ps1 -LlamaCudasetWinMLSamplesLlamaCudaonly for the MSBuild restore and build of the C++ projects. The C# samples build throughdotnetwith their own arguments, so the four C# GGUF samples kept only the CPU backend while the build reported CPU and CUDA.The Runtime and Tasks build scripts now pass the property to the C# builds too, and the four C# GGUF projects reference
Microsoft.Windows.AI.MachineLearning.LibLlamaunder it, as their C++ counterparts do. The GGUF guide and the Tasks README now say the switch covers C#. A build without-LlamaCudadoesn't change, and the CPU backend stays the default.Related issue
None. Follows #40, which added the opt-in CUDA backend to the C++ GGUF samples, and #41, which added two of the four C# GGUF samples.
Affected samples
Samples/Runtime/language/hello-language-model/csharpSamples/Tasks/model-backed/text-generation/csharpSamples/Tasks/language/chat-completion/csharpSamples/Tasks/model-backed/text-generation-features/csharpSamples/Runtime/build.ps1andSamples/Tasks/build.ps1, plusSamples/Tasks/README.mdanddocs/Runtime/gguf-models.mdChecklist
Samples/WindowsML-Samples.slnlocally with Visual Studio 2022 or Visual Studio 2026 (that solution isn't in the repo, so I built the Runtime and Tasks catalogs withbuild.ps1for ARM64 and x64, with no warnings).clang-format(ranSamples/format-code.ps1if available) (there's no C++ in this PR)README.md(the Tasks README and the GGUF guide)Testing notes
Built on
mainat3c6f5b2, which includes #44, against Microsoft.Windows.AI.MachineLearning 2.9.36-experimental and the LibLlama 0.7.0.107-experimental packages, on an ARM64 PC with an NVIDIA RTX Spark GPU, starting from empty output folders.Samples\Runtime\build.ps1 -Sample hello-language-model-csharp -Platform ARM64 -PackageOnlyLlamaBackends\cudaSamples\Tasks\build.ps1 -Sample all -Platform ARM64 -PackageOnlyLlamaBackends\cuda-LlamaCudaggml-cuda.dll,cublas64_13.dll,cublasLt64_13.dlland the backend manifest inLlamaBackends\cudaSamples\Runtime\build.ps1 -Sample all -Platform x64 -PackageOnly -LlamaCuda, and the same forSamples\Taskshello-language-model-csharp.exe --model qwen2.5-0.5b-instruct-q4_k_m.gguf --device gpuggml_cuda_init: found 1 CUDA devicesand answeredtask-model-text-generation-csharp.exe --llama qwen2.5-0.5b-instruct-q4_k_m.gguf "Name three primary colors." 32 --device gpuggml_cuda_init: found 1 CUDA devicesand named three primary colorsThe x64 C# samples weren't run on an NVIDIA GPU. They get the same backend files as the x64 C++ samples, which #40 validated on an RTX 4090.