Repository navigation
Add the opt-in llama.cpp CUDA backend to the 2.9 GGUF samples - #40
Conversation
f213c2a to
6e9df0c
Compare
There was a problem hiding this comment.
🟡 Changes recommended
The verifier can accept unsupported cuBLAS versions and a missing core wheel, allowing unusable CUDA environments to pass.
2 open issues
What changed in this PR
Adds an opt-in llama.cpp CUDA backend for NVIDIA GPUs to the Windows ML GGUF samples, while keeping CPU-only deployment as the default. It builds on the existing upstream API sample and centrally pinned 2.9 packages.
Changes:
- Adds
-LlamaCudato three catalog build scripts and conditional package references to ten GGUF projects. - Extends Python environment verification to cover optional llama.cpp wheels and cuBLAS presence.
- Documents CUDA setup, cuBLAS sources, licensing responsibilities, and custom-backend alternatives.
| File | Description |
|---|---|
| Tools/llama/README.md | Distinguishes packaged CUDA from custom backends. |
| Tools/llama/Build-LlamaBackend.ps1 | Updates help text for packaged CUDA availability. |
| Samples/Tasks/scripts/verify_python_environment.py | Checks optional wheel versions and cuBLAS presence. |
| Samples/Tasks/README.md | Documents CUDA build and Python options. |
| Samples/Tasks/model-backed/README.md | Adds Python CUDA installation guidance. |
| Samples/Tasks/model-backed/llama-text-generation/task-llama-text-generation.vcxproj | Conditionally references the CUDA package. |
| Samples/Tasks/model-backed/llama-text-generation/README.md | Explains packaged CUDA GPU support. |
| Samples/Tasks/localpackages/README.md | Lists the CUDA build switch. |
| Samples/Tasks/language/text-generation/task-text-generation.vcxproj | Conditionally references the CUDA package. |
| Samples/Tasks/language/chat-completion/task-chat-completion.vcxproj | Conditionally references the CUDA package. |
| Samples/Tasks/composition/speech-to-text-generation/task-speech-to-text-generation.vcxproj | Conditionally references the CUDA package. |
| Samples/Tasks/build.ps1 | Adds CUDA opt-in arguments and status output. |
| Samples/Server/README.md | Explains CUDA deployment and GPU execution. |
| Samples/Server/localpackages/README.md | Lists the CUDA build switch. |
| Samples/Server/host/in-process/server-in-process.vcxproj | Conditionally references the CUDA package. |
| Samples/Server/host/executable/server-executable.vcxproj | Conditionally references the CUDA package. |
| Samples/Server/host/executable/README.md | Documents optional CUDA host deployment. |
| Samples/Server/build.ps1 | Adds CUDA opt-in arguments and status output. |
| Samples/Runtime/localpackages/README.md | Lists local CUDA packages and wheel setup. |
| Samples/Runtime/language/speech-to-language-model/speech-to-language-model.vcxproj | Conditionally references the CUDA package. |
| Samples/Runtime/language/llm-chat/README.md | Points Python users to the CUDA wheel. |
| Samples/Runtime/language/llm-chat/llm-chat.vcxproj | Conditionally references the CUDA package. |
| Samples/Runtime/language/hello-language-model/README.md | Points Python users to the CUDA wheel. |
| Samples/Runtime/language/hello-language-model/hello-language-model.vcxproj | Conditionally references the CUDA package. |
| Samples/Runtime/interop/llama-upstream-api/README.md | Explains CUDA deployment and package matching. |
| Samples/Runtime/interop/llama-upstream-api/llama-upstream-api.vcxproj | Conditionally references the CUDA package. |
| Samples/Runtime/build.ps1 | Adds the CUDA switch, help, and build arguments. |
| Samples/Directory.Packages.props | Adds LibLlama using the existing shared version. |
| docs/Runtime/tutorials/07-gguf-language-models.md | Adds CUDA opt-in instructions. |
| docs/Runtime/python-samples.md | Links NVIDIA GPU setup guidance. |
| docs/Runtime/overview.md | Introduces optional CUDA packages and wheels. |
| docs/Runtime/gguf-models.md | Details CUDA setup, cuBLAS sources, licensing, and cleanup. |
Review effort: Balanced
|
Copilot Fix the code for all comments in this review thread. When a review comment includes a suggested change, apply the suggestion exactly. Do not make changes beyond what is described in the linked review thread. |
Addressed both review comments in |
e435643 to
2d72608
Compare
2d72608 to
126ad30
Compare
build.ps1 -LlamaCuda in Samples\Runtime, Samples\Tasks and Samples\Server sets WinMLSamplesLlamaCuda, and the ten GGUF projects then also reference Microsoft.Windows.AI.MachineLearning.LibLlama, which brings the LibLlama.Cuda.win-x64 and LibLlama.Cuda.win-arm64 packages of the Windows ML 2.9 experimental release. Without the switch they reference only LibLlama.Core, as before, so the CPU backend stays the default. The CUDA backend needs NVIDIA cuBLAS, which the packages don't include. The docs describe the three sources the build copies it from, and nothing in the samples sets WinMLLlamaCudaAcceptNvidiaLicense. docs\Runtime\gguf-models.md gets an NVIDIA CUDA section for C++ and Python, and the other docs and sample READMEs point to it. Tools\llama now describes the backend tool for other ggml families or a CUDA backend you build yourself, and verify_python_environment.py checks the CUDA wheels and that nvidia-cublas is installed with them. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ca5b72cf-ae75-4384-9fc4-a6081b9fddea
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
a6a655c compared nvidia-cublas with the CUDA wheel's == pin, which rejects the later cuBLAS 13 releases that Windows ML loads, such as 13.8.0.4. The verifier now reads that pin and accepts it or a later release with the same major version, without the packaging module. The core wheel check is unchanged, and the Tasks README says what the script checks. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ca5b72cf-ae75-4384-9fc4-a6081b9fddea
126ad30 to
3594189
Compare
defe789
into
release/2.9-experimental

Summary
Adds the llama.cpp CUDA backend for NVIDIA GPUs to the GGUF samples as an explicit opt-in. The Windows ML 2.9 experimental release includes the backend in the
Microsoft.Windows.AI.MachineLearning.LibLlama.Cuda.win-x64andMicrosoft.Windows.AI.MachineLearning.LibLlama.Cuda.win-arm64packages, whichMicrosoft.Windows.AI.MachineLearning.LibLlamabrings in, and in thewindowsml-llama-cudawheel. The samples keep the CPU backend as the default, so a build on a PC without an NVIDIA GPU doesn't change.build.ps1 -LlamaCudainSamples\Runtime,Samples\TasksandSamples\ServersetsWinMLSamplesLlamaCuda, and the ten GGUF projects then also referenceMicrosoft.Windows.AI.MachineLearning.LibLlama. Without the switch they reference onlyLibLlama.Core, as before. The ten include Add a Runtime sample that calls llama.cpp's API directly #30's llama-upstream-api sample and the Task llama-text-generation sample.WinMLLlamaCudaRedistDirectory, then from the CUDA Toolkit thatCUDA_PATHnames, then from NVIDIA's download once the developer accepts the NVIDIA CUDA Toolkit EULA by settingWinMLLlamaCudaAcceptNvidiaLicense. No project or script in this repo sets that property. Without cuBLAS the build warns withWINMLLLAMA0001, and the samples still run on the CPU.docs/Runtime/gguf-models.mdgets an NVIDIA CUDA section that covers the C++ opt-in, the cuBLAS sources, the license responsibility and the Python wheel. The tutorial, overview, Python guide, sample READMEs andlocalpackagesREADMEs point to it.Tools/llamanow describes the backend tool for other ggml families, or for a CUDA backend you build yourself.verify_python_environment.pychecks that installedwindowsml-llamaandwindowsml-llama-cudawheels matchwindowsml. With the CUDA wheel it also requireswindowsml-llama-coreand annvidia-cublasrelease that Windows ML loads, the one the CUDA wheel pins or a later release with the same major version.This PR is stacked on #30 and merges after it.
-LlamaCudarestores these packages from the 2.9.36-experimental release, so it needs them on nuget.org and PyPI.Microsoft.Windows.AI.MachineLearning.LibLlama.Cuda.win-x64,Microsoft.Windows.AI.MachineLearning.LibLlama.Cuda.win-arm64andMicrosoft.Windows.AI.MachineLearning.LibLlama0.7.0.107-experimentalwindowsml-llama-cudaandwindowsml-llama2.9.36a0They depend on the 2.9.36-experimental Runtime and LibLlama.Core 0.7.0.107-experimental packages and the matching wheels that #36 pins. The pins in
Samples/Directory.Packages.propsalready match, so nothing here changes once they're live. The default build and the CPU path need nothing new.Related issue
None.
Affected samples
Samples/Runtime,Samples/TasksandSamples/Server, including theirbuild.ps1scripts, the ten GGUF projects, READMEs andlocalpackagesREADMEsSamples/Directory.Packages.propsSamples/Tasks/scripts/verify_python_environment.pyTools/llamadocs/RuntimeChecklist
Samples/WindowsML-Samples.slnlocally with Visual Studio 2022 or Visual Studio 2026 (the samples build per catalog, so I built the Runtime, Tasks and Server catalogs withbuild.ps1and Visual Studio 2026, Release, for ARM64 and x64, with and without-LlamaCuda).clang-format(ranSamples/format-code.ps1if available) (no C++ source changes)README.mdTesting notes
Tested with the 2.9.36-experimental release packages, the unpublished ones staged in
localpackages, andqwen2.5-0.5b-instruct-q4_k_m.gguf.-LlamaCuda, no output has aLlamaBackends\cudafolder. With it, all ten GGUF outputs got the package'sggml-cuda.dlland the CUDA Toolkit 13.4 cuBLAS for their platform.WinMLLlamaCudaRedistDirectorytook precedence overCUDA_PATH, and the NVIDIA download withWinMLLlamaCudaAcceptNvidiaLicenseset in the environment for one local build verified and cached the pinned archive, then reused the cache. With no source, the build warned withWINMLLLAMA0001, a GPU request failed with0x80070032, and the CPU still worked.windowsml-llama-cudainstallednvidia-cublas13.7.0.27 on ARM64 and x64, andverify_python_environment.py --require-llamapassed. Withoutnvidia-cublas,import windowsml.runtimewarned once with the fix, a GPU request failed with the same reason, the CPU still worked, and the verify script now fails. A later cuBLAS 13 that Windows ML accepts, 13.8.0.4, passes.After review, the verifier requires
windowsml-llama-corewith the CUDA wheel and checks thenvidia-cublasversion. In a scratch environment with the 2.9.36a0 wheels and stand-innvidia-cublasmetadata, 13.7.0.27, 13.8.0.4 and 13.10.0.20 pass, 13.5.0 and 14.0.0 fail, and removingwindowsml-llama-corefails, where the previous script passed all of those. The real CUDA environment passes with--require-llama.-LlamaCudahad 0 warnings and 0 errors on ARM64 and x64, every GGUF output got the CUDA backend and cuBLAS, and the ARM64 Debug hello-language-model initialized CUDA on the RTX Spark device and gave the expected answer.-LlamaCudabuilds of hello-language-model and the Task llama-text-generation sample ran on the CPU and gave the expected answers. llama.cpp printed oneggml_cuda_init: failed to initialize CUDAline, and a GPU request failed withERROR_NOT_SUPPORTED, where the Task sample suggests--device cpu.-LlamaCudabuilt for ARM64 and x64 with no warnings. On the RTX Spark device, the CG EP sample compiled and classified the test image, and llama-upstream-api listed the CUDA device and answered the prompt.Not covered yet is restore from nuget.org and PyPI, which waits on publishing.