![]() |
VOOZH | about |
dotnet add package WACS.WASI.NN.LlamaSharp --version 0.2.4
NuGet\Install-Package WACS.WASI.NN.LlamaSharp -Version 0.2.4
<PackageReference Include="WACS.WASI.NN.LlamaSharp" Version="0.2.4" />
<PackageVersion Include="WACS.WASI.NN.LlamaSharp" Version="0.2.4" />Directory.Packages.props
<PackageReference Include="WACS.WASI.NN.LlamaSharp" />Project file
paket add WACS.WASI.NN.LlamaSharp --version 0.2.4
#r "nuget: WACS.WASI.NN.LlamaSharp, 0.2.4"
#:package WACS.WASI.NN.LlamaSharp@0.2.4
#addin nuget:?package=WACS.WASI.NN.LlamaSharp&version=0.2.4Install as a Cake Addin
#tool nuget:?package=WACS.WASI.NN.LlamaSharp&version=0.2.4Install as a Cake Tool
GGUF / llama.cpp backend for WACS.WASI.NN.
Implements IBackend for graph-encoding.ggml against
LLamaSharp; GPU runtimes pluggable via
LlamaSharp's backend NuGets (CPU default; CUDA / Vulkan / MacMetal swaps with no source
change).
Follows the WasmEdge wasi-nn GGUF convention:
wasi:nn/graph.load-by-name(name) — multi-GB
GGUFs aren't passed through the canonical-ABI byte-loader pathdotnet add package WACS.WASI.NN.LlamaSharp
The package's bin ships its NuGet transitives + RID-specific native libs (via
<EnableDynamicLoading>true</EnableDynamicLoading>), so Assembly.LoadFrom resolves
everything from the LoadFromContext probe — no manual deps staging.
LlamaSharp isn't bundled with WACS.Cli by default (unlike OnnxRuntime — the natives
are too chunky to ride along). Pass the explicit path to the backend's bin:
mkdir -p ./models
huggingface-cli download Qwen/Qwen2.5-0.5B-Instruct-GGUF \
qwen2.5-0.5b-instruct-q4_k_m.gguf --local-dir ./models
export WACS_WASINN_GGUF_DIR="$(pwd)/models"
# After dotnet build of this project's repo:
LLAMA=$(realpath Wacs.WASI/Wacs.WASI.NN/Wacs.WASI.NN.LlamaSharp/bin/Release/net8.0/Wacs.WASI.NN.LlamaSharp.dll)
wacs run my-llm.component.wasm --wasip2 --bind "$LLAMA"
--bind auto-pulls the WASI.NN typed surface + DI sibling onto host-packages when the
identity starts with Wacs.WASI.NN.. The Preview 2 DI scope's auto-wire registers the
backend in BOTH Backends[GGML] AND LoadByNameBackend; guests calling
wasi:nn/graph.load-by-name(...) direct-link cleanly.
For wasi-p1 WITX guests (e.g. Rust wasi-nn = "0.6" compiled for wasm32-wasip1),
drop --wasip2 and pass the model name via -e since Preview 1 doesn't auto-forward
host env vars:
wacs run my-witx-guest.wasm --bind "$LLAMA" \
-e MODEL_NAME=qwen2.5-0.5b-instruct-q4_k_m
WACS_WASINN_GGUF_DIR is read by the bindable on the .NET host side (via
Environment.GetEnvironmentVariable), so a plain shell export for it is enough on
either ABI path.
The full chain (with under-the-hood walkthrough) lives at
docs/COMPONENT_CHAINING.md#gguf-inference-example-llamasharp-backend.
Interpreter / one-line:
using Wacs.Core.Runtime;
using Wacs.WASI.NN;
using Wacs.WASI.NN.LlamaSharp;
using Wacs.WASI.NN.Types;
var registry = new Dictionary<string, string>
{
["qwen2.5-0.5b"] = "/path/to/qwen2.5-0.5b-instruct-q4_k_m.gguf",
};
var backend = LlamaSharpBackend.FromPaths(registry);
var runtime = new WasmRuntime();
runtime.UseWasiNN(b =>
{
b.AddBackend(GraphEncoding.GGML, backend);
b.Configuration.LoadByNameBackend = backend; // route load-by-name
});
For the transpiler-direct-link / DI flow, just --bind <path> — the Preview 2 DI scope
auto-discovers and wires.
Replace LLamaSharp.Backend.Cpu in the project's csproj with one of:
LLamaSharp.Backend.Cuda12 — NVIDIALLamaSharp.Backend.Vulkan — cross-vendor GPULLamaSharp.Backend.MacMetal — Apple SiliconThen rebuild. The EnableDynamicLoading bin layout copies whichever backend NuGet's
natives are pulled — no source change.
LlamaSharpBackend : IBackend — implements LoadGraphByName(name, target) for
registry-resolved GGUF files. The byte-loader path
(LoadGraph(builders, target)) traps with UnsupportedOperation by design — see
class docs for whyLlamaSharpBackend.FromPaths(IDictionary<string,string>) — convenience static
factory for the simple "drop GGUFs in a directory" embedder flowWasiNNLlamaSharpBindable : IBindable — parameterless adapter for --bind. Reads
WACS_WASINN_GGUF_DIR, scans *.gguf, registers each under its filename-sans-extension| Use case | Package |
|---|---|
GGUF / llama.cpp generative LLMs (load-by-name flow) |
WACS.WASI.NN.LlamaSharp (this) |
| Standard ONNX inference | WACS.WASI.NN.OnnxRuntime |
| ONNX with ML.NET pipeline integration | WACS.WASI.NN.MLNet |
docs/WASI_NN_USAGE.md —
unified usage guide (CLI flags, env vars, programmatic embedding, worked examples)docs/COMPONENT_CHAINING.md
— runtime requirements + GGUF example + chaining modelWacs.WASI/Wacs.WASI.NN/README.md
— backend matrix + package layoutApache-2.0
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. 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. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.