A native .NET LLM inference engine for GGUF models. TensorSharp provides a console application, a web-based chatbot interface, and Ollama/OpenAI-compatible HTTP APIs for programmatic access. It supports Windows/MacOS/Linux with full GPU capability
Native .NET LLM inference engine for GGUF models, including autoregressive LLMs and DiffusionGemma-style text-diffusion models. TensorSharp provides a console application, a web-based chatbot interface, and Ollama/OpenAI-compatible HTTP APIs for programmatic access.
Zero to a streaming reply in about 30 seconds (after the model download).
1. Prerequisites — .NET 10 SDK, git, and (optionally) a GPU toolchain: NVIDIA → CUDA Toolkit 12.x; Apple Silicon → Xcode command-line tools (Metal is built in). Full list in Prerequisites.
2. Clone & build — the native GGML library is compiled automatically on the first build.
git clone https://github.com/zhongkaifu/TensorSharp.git cd TensorSharp dotnet build TensorSharp.slnx -c Release
3. Download a model — a small, well-tested starting point is Gemma-4-E4B (Q8_0) from ggml-org/gemma-4-E4B-it-GGUF. More options in Verified Models.
4. Run it — choose the --backend for your hardware (see Pick a Backend):
# One-shot generation echo "Explain mixture-of-experts in one sentence." > prompt.txt ./TensorSharp.Cli --model gemma-4-E4B-it-Q8_0.gguf --input prompt.txt --backend ggml_metal # macOS ./TensorSharp.Cli --model gemma-4-E4B-it-Q8_0.gguf --input prompt.txt --backend ggml_cuda # Windows/Linux + NVIDIA ./TensorSharp.Cli --model gemma-4-E4B-it-Q8_0.gguf --input prompt.txt --backend cpu # portable / debugging # Interactive chat (REPL) ./TensorSharp.Cli --model gemma-4-E4B-it-Q8_0.gguf -i --backend ggml_metal
Prefer a browser UI plus HTTP APIs? Start the server instead:
./TensorSharp.Server --model gemma-4-E4B-it-Q8_0.gguf --backend ggml_metal # open http://localhost:5000 — also serves Ollama- and OpenAI-compatible endpoints
The CLI binary lands in TensorSharp.Cli/bin/... and the server in TensorSharp.Server/bin/... after the build. Full options: CLI usage · Server usage.
Not sure which backend to use? Start here. Every backend falls back to CPU for any op it does not yet implement, so output stays correct on all of them.
| Your hardware | Recommended backend | Flag | Notes |
|---|---|---|---|
| Apple Silicon (Mac) | GGML Metal | --backend ggml_metal |
Default on macOS. --backend mlx is an alternative Apple-Silicon GPU path. |
| Windows / Linux + NVIDIA GPU | GGML CUDA | --backend ggml_cuda |
Most-tested NVIDIA path. --backend cuda is the direct PTX/cuBLAS backend for experimentation. |
| Windows / Linux + AMD / Intel / NVIDIA GPU | GGML Vulkan | --backend ggml_vulkan |
Vendor-neutral GPU path via ggml-vulkan (cooperative-matrix accelerated where the driver supports it). Built automatically when the machine has a Vulkan runtime; --no-vulkan opts out. |
| No GPU / portability / debugging | Pure C# CPU | --backend cpu |
No native dependencies. For faster CPU inference use --backend ggml_cpu (native kernels). |
See Compute Backends for the full description of every backend and what each one accelerates.
These architectures are implemented and exercised by the test/benchmark matrix. Pick a quantization that fits your hardware (e.g. Q4_K_M for low memory, Q8_0 for higher quality). More sizes and multimodal projector files are in Model Downloads.
| Family | Example model (GGUF) | Image / Video / Audio | Thinking | Tools | Card |
|---|---|---|---|---|---|
| Gemma 4 | gemma-4-E4B-it (also 31B, 26B-A4B MoE) | ✅ / ✅ / ✅ | ✅ | ✅ | gemma4.md |
| Qwen 3.5 / 3.6 | Qwen3.5-9B (also 35B-A3B MoE) | ✅ / — / — | ✅ | ✅ | qwen35.md |
| Qwen 3 | Qwen3-4B | — / — / — | ✅ | ✅ | qwen3.md |
| GPT OSS | gpt-oss-20b (MoE) | — / — / — | ✅ | ✅ | gptoss.md |
| Nemotron-H | Nemotron-H-8B (also 47B, Omni) | ✅ (Omni) / — / — | ✅ | ✅ | nemotron.md |
| Mistral 3 | Mistral-Small-3.1-24B | ✅ / — / — | — | — | mistral3.md |
| Gemma 3 | gemma-3-4b-it | ✅ / — / — | — | — | gemma3.md |
| DiffusionGemma | diffusion-gemma GGUFs | — / — / — | — | — | diffusiongemma.md |
| Qwen-Image-Edit | qwen-image-edit GGUFs (MMDiT + VAE + Qwen2.5-VL) | 🖼️ image→image | — | — | qwenimage.md |
llama.cpp on the workloads that matter: the Gemma 4 26B-A4B MoE prefills 1.32× faster and lands first tokens 1.30× sooner (geomean; up to 1.70× / 1.65× per scenario), Gemma 4 12B wins or ties every decode scenario (geomean 1.17×), streamed tool-call turns decode up to 2.37× faster, and structured-output (JSON) decode on Gemma 4 E4B streams 7.7× faster (405 vs 52 tok/s). → Head-to-head vs llama.cppgemma4-assistant draft GGUF). The draft proposes several tokens per step and the trunk verifies them in one batched forward, with the request's own sampler driving both. Opt in with --mtp-spec (+ --mtp-draft-model for Gemma 4). → Speculative decodingEverything below is detailed reference. New here? The five sections above are all you need to get running.