Getting Started

From a source checkout to a verified CLI reply or local API. The quick start runs Gemma 4 E4B on a native GGML backend; a managed CPU path (no CMake or GPU toolchain) remains available when you cannot build native code.

📘

Following the Gemma 4 E4B path? From Tensors to Tokens turns this quick start into a guided, from-scratch explanation of the engine behind every step. Explore the TensorSharp book →

1 · Prerequisites

Install the .NET 10 SDK

TensorSharp targets net10.0, so a source build requires the full .NET 10 SDK—installing only the .NET Runtime or ASP.NET Core Runtime is not enough. The SDK includes the runtimes needed to run the CLI and server. Start with Microsoft's cross-platform .NET installation guide, then use the instructions for your operating system:

PlatformInstall the SDKOfficial instructions
WindowsOpen PowerShell or Command Prompt and run winget install Microsoft.DotNet.SDK.10.Install .NET on Windows
macOSDownload the .NET 10 SDK installer for your processor: Arm64 for Apple Silicon or x64 for an Intel Mac.Install .NET on macOS
LinuxFollow the page for your distribution, configure its package feed if directed, and install dotnet-sdk-10.0. On Ubuntu, after completing the repository setup for your release: sudo apt-get update, then sudo apt-get install -y dotnet-sdk-10.0.Choose a Linux distribution (for example, Ubuntu)

Open a new terminal after installation and confirm that a 10.0.x SDK is listed:

dotnet --list-sdks

Other prerequisites

Per-platform toolchains (only for GPU acceleration)

PlatformNeeded forInstall
macOS (Metal)ggml_metal / mlxCMake 3.20+ and Xcode command-line tools. MLX additionally builds libmlxc.
Windowsggml_cuda / cudaCMake 3.20+, Visual Studio 2022 C++ build tools, NVIDIA driver + CUDA Toolkit 12.x (with cuBLAS).
Linuxggml_cuda / cudaCMake 3.20+, NVIDIA driver + CUDA Toolkit 12.x (with cuBLAS).
Windows / Linux (any Vulkan GPU)ggml_vulkanEnabled automatically when the machine has a Vulkan runtime (loader installed); opt out with --no-vulkan (or TENSORSHARP_GGML_NATIVE_ENABLE_VULKAN=OFF). Windows auto-provisions a portable Vulkan toolchain when no SDK is installed; on Linux install e.g. libvulkan-dev glslc spirv-headers. Needs a Vulkan 1.3 driver at run time.
Any (CPU only)cpuNothing beyond the .NET SDK. ggml_cpu is faster but is a native build.

2 · Clone and choose a build path

git clone https://github.com/zhongkaifu/TensorSharp.git
cd TensorSharp

Managed-CPU path (no native toolchain)

To skip every native build, pass both skip properties and use the managed cpu backend. The first run restores and builds the managed projects automatically.

-p:TensorSharpSkipGgmlNative=true -p:TensorSharpSkipMlxNative=true -- --backend cpu

Full native / GPU path

Build the whole solution when you want GGML CPU, Metal, CUDA, Vulkan, or MLX. The first build compiles the native bridge and can take several minutes; subsequent builds are incremental.

dotnet build TensorSharp.slnx -c Release

Or build just one application:

# Console application
dotnet build TensorSharp.Cli/TensorSharp.Cli.csproj -c Release

# Web application
dotnet build TensorSharp.Server/TensorSharp.Server.csproj -c Release

The CLI binary lands in TensorSharp.Cli/bin/... and the server in TensorSharp.Server/bin/.... For a CUDA- or Vulkan-enabled native build, manual native builds, or MLX, see Building the native libraries.

📦

Current release status: v3.0.5.0 has no uploaded CLI/server archives, so build from source today. The repository contains a Release Binaries workflow, but do not invent an archive URL—use one only when it is visibly listed on the Releases page.

3 · Download a model

For the quick start, download the recommended benchmark-verified gemma-4-E4B-it-Q8_0.gguf file (7.48 GiB) from the public ggml-org/gemma-4-E4B-it-GGUF repository. The lower-memory gemma-4-E4B-it-Q4_K_M.gguf lives in the same repository, and the Models page lists other options.

curl --create-dirs --fail -L "https://huggingface.co/ggml-org/gemma-4-E4B-it-GGUF/resolve/main/gemma-4-E4B-it-Q8_0.gguf?download=true" -o models/gemma-4-E4B-it-Q8_0.gguf
🧩

For multimodal models, download the matching projector (mmproj) and pass its exact path with --mmproj. The server does not auto-detect a projector, and CLI auto-detection recognizes only a few legacy filenames; explicit paths are reliable.

Gemma 4 E4B backend and platform notes

The first-run commands below are for Linux + NVIDIA. On Windows + NVIDIA, set $env:TENSORSHARP_GGML_NATIVE_ENABLE_CUDA='ON' in PowerShell, then run the same commands without the Bash assignment prefix. On Apple Silicon, omit the CUDA environment assignment and use ggml_metal. For Vulkan on Windows/Linux, set TENSORSHARP_GGML_NATIVE_ENABLE_VULKAN=ON (PowerShell: $env:TENSORSHARP_GGML_NATIVE_ENABLE_VULKAN='ON') and use ggml_vulkan. Without a GPU, use ggml_cpu (native CPU kernels). Text needs no projector. For image, video, or audio, download mmproj-gemma-4-E4B-it-Q8_0.gguf from the same repository and add --mmproj models/mmproj-gemma-4-E4B-it-Q8_0.gguf.

4 · First run

The one-shot prompt comes from a file via --input; --prompt is reserved for Qwen-Image-Edit. The CLI defaults to ggml_cpu, greedy decoding, and 100 generated tokens. The environment assignment enables the CUDA native build; the first run compiles it and can take several minutes, later runs are incremental.

Option A — one-shot generation (CLI)

echo "What is TensorSharp? Answer briefly." > prompt.txt
TENSORSHARP_GGML_NATIVE_ENABLE_CUDA=ON dotnet run --project TensorSharp.Cli -c Release -p:TensorSharpSkipMlxNative=true -- --model models/gemma-4-E4B-it-Q8_0.gguf --input prompt.txt --max-tokens 128 --backend ggml_cuda

Option B — interactive chat (REPL)

dotnet run --project TensorSharp.Cli -c Release --no-build -- --model models/gemma-4-E4B-it-Q8_0.gguf -i --max-tokens 128 --backend ggml_cuda

Type messages turn-by-turn; drive the session with slash commands like /reset, /think on, or /image photo.png.

Option C — browser UI + HTTP APIs (server)

TENSORSHARP_GGML_NATIVE_ENABLE_CUDA=ON dotnet run --project TensorSharp.Server -c Release -p:TensorSharpSkipMlxNative=true -- --model models/gemma-4-E4B-it-Q8_0.gguf --backend ggml_cuda --max-tokens 128
# open http://localhost:5000/index.html

The health response is at http://localhost:5000/; the browser chat is at /index.html. The Ollama- and OpenAI-compatible endpoints use the same fixed port.

Skip the long command lines. Put your options in a JSON file and pass --config config/server-basic.json (or config/cli-basic.json). A config entry can even auto-download the model on first run, so a fresh machine needs no manual download step. The repository's config/ folder ships ready-to-run examples. → Configuration file

Where to go next

🖥️

Pick a backend

Match --backend to your hardware.

⌨️

CLI reference

All flags, the REPL, and batch workflows.

🔌

HTTP API

Call the server from curl, Python, or SDKs.

🧠

Models

What's supported and where to download.