经 AI Skill Hub 精选评估,TensorSharp 获评「强烈推荐」。这款AI工具在功能完整性、社区活跃度和易用性方面表现出色,AI 评分 8.0 分,适合有一定技术背景的用户使用。
TensorSharp 是一款基于 C# 开发的开源工具,专注于 LLM、C#、GGU 等核心功能。作为 GitHub 开源项目,它拥有活跃的社区支持和持续的版本迭代,代码完全透明可审计,支持本地部署以保护数据隐私。无论是个人使用还是集成到企业工作流,都能提供稳定可靠的解决方案。
TensorSharp 是一款基于 C# 开发的开源工具,专注于 LLM、C#、GGU 等核心功能。作为 GitHub 开源项目,它拥有活跃的社区支持和持续的版本迭代,代码完全透明可审计,支持本地部署以保护数据隐私。无论是个人使用还是集成到企业工作流,都能提供稳定可靠的解决方案。
# 克隆仓库 git clone https://github.com/zhongkaifu/TensorSharp cd TensorSharp # 查看安装说明 cat README.md # 按 README 完成环境依赖安装后即可使用
# 查看帮助 tensorsharp --help # 基本运行 tensorsharp [options] <input> # 详细使用说明请查阅文档 # https://github.com/zhongkaifu/TensorSharp
# tensorsharp 配置说明 # 查看配置选项 tensorsharp --config-example > config.yml # 常见配置项 # output_dir: ./output # log_level: info # workers: 4 # 环境变量(覆盖配置文件) export TENSORSHARP_CONFIG="/path/to/config.yml"
<p align="center"> <img src="imgs/banner_1.png" alt="TensorSharp logo" width="320"> </p>
Native .NET LLM inference engine for GGUF models — autoregressive LLMs and DiffusionGemma-style text-diffusion, plus Qwen-Image-Edit image editing and MiniMax-H3 video with native 32 kHz stereo audio (and Wan 2.1/2.2 for video alone). Ships a console app, a browser chat UI, and Ollama/OpenAI-compatible HTTP APIs. A pure-.NET engine that trades wins with the hand-tuned C++ llama.cpp on identical GGUF files and the same GPU. The optional TensorSharp.AgentHost layer adds Agent Skills and a bounded, in-process model-to-tool loop for sandboxed file and shell work.
llama.cpp on the workloads that matter: Gemma 4 E4B and 2-bit Qwen 3.6 35B-A3B MoE prefill 1.28× faster on CUDA with first tokens 1.27× sooner (multi-turn up to 1.49×); Gemma 4 12B decodes 1.21× faster on Vulkan (up to 1.32× on long context). → Benchmarks--backend cuda), the native ggml executor (--backend ggml_cuda / ggml_vulkan), and a 100% pure-C# CPU executor (--backend cpu, no native dependencies). Weights layer-split automatically across every visible GPU, so a model far larger than one card still runs; the server hosts it with per-sequence slots and continuous batching. → DeepSeek V4 card--tp N runs every layer on every GPU (heads column/row-parallel, every expert split row-wise; this native GLM path is local/single-process) and --cpu-moe keeps the routed experts — 92% of the checkpoint — in system RAM. The default layer split and --cpu-moe reproduce llama.cpp token-for-token on the same backend; --tp sums per-rank partials, so on a 2-bit MoE its last-bit difference reaches the top-8 router and the near-tied tokens can differ. Head-to-head on 3x RTX PRO 6000: pp2048 918.9 vs llama.cpp's 763.1 tok/s, tg64 43.7 vs 42.2. The advertised 1M context (~93 GiB of KV) is a ceiling rather than a promise — once the weights land the loader sizes the context to the VRAM actually free and logs its pick (342,272 tokens on the layer split, 646,400 with --n-cpu-moe 30); MAX_CONTEXT makes a specific length a hard requirement instead. → GLM cardGlmDsaModel as GLM-5.2. On 2× RTX PRO 6000 Blackwell (96 GB), GLM-5.3-Flash-UD-Q2_K_XL (101 GiB), layer split, both engines at n_ubatch 2048 and back to back: tg64 73.5 vs llama.cpp's 36.6 tok/s, with prefill within a few percent either way (pp2048 2014 vs 2070, pp16384 1692 vs 1690, pp32768 1446 vs 1483). Vision through mmproj-BF16.gguf (the GLM-OCR ViT): --image, multi-image and multi-turn image sessions. The layer split across every visible GPU remains the default when --tp is omitted; on GGML GPU backends, --tp N instead runs native local tensor parallelism with head-sharded KDA/MLA, per-rank KDA state and row-sharded routed-expert hidden dimensions. Rank partials reduce before the nonlinear Sinkhorn hyper-connections. --cpu-moe / --n-cpu-moe and per-sequence native slots also work; NextN/MTP speculation is not implemented yet. It now also runs on the 100% pure-C# --backend cpu path (text), though well behind the GGML backends there — ~5.7× off ggml_cpu on prefill and ~2.4× on decode, and its prefill logits sit at cosine 0.9567 against ggml_cpu, which is close but is not proven to be only 2-bit quantization sensitivity, so treat that path as a reference implementation to A/B against rather than bit-parity. → GLM card--tp N runs a layer split here, not tensor parallelism: on 2× A100-80GB, Qwen3.8-Flash-Next-UD-Q2_K_XL (73.4 GiB) lands 24.2 GB + 26.2 GB across the two cards with prefill ~1520–1550 t/s and decode ~56 tok/s either way, and greedy output byte-identical to the 1-GPU run — capacity, not speed. → Qwen 3.8 Flash Next card--n-cpu-moe 20) and Gemma 4 (separate gemma4-assistant draft GGUF, --draft-model); DeepSeek V4 adds DSpark block drafting (--draft-model), which proposes a whole block of tokens per step for 1.3–1.4× decode (up to 2.0× on multi-turn chat). A fourth algorithm needs no trained weights at all: --spec-type ngram matches the sequence's own suffix against the tokens it has already seen, works on every checkpoint, and measured 45.2 tok/s against 31.4 plain (1.44×) on Qwen3.5-9B (Q8_0, ggml_metal, M5 Pro) — a model that ships no draft head — with byte-identical output. In every case the draft proposes, the trunk verifies in one batched forward, and the output matches standard decode. Off by default; opt in with --spec on either host for the trunk-embedded heads, while naming a --draft-model enables speculation by itself. → Speculative decoding--tp N — on the direct cuda backend and on GGML CUDA / Vulkan — and extend across machines with peer-to-peer TCP clustering (--tp-node-id / --tp-peers). Megatron-LM column/row-parallel pattern with hierarchical AllReduce; MoE expert parallelism and per-rank GatedDeltaNet kernels on GGML. Fused per-rank execution makes --tp 2 decode 1.39× a single GPU on Gemma 4 E4B and 1.57× on Muse-Glimmer 30B (which also gains 1.34× prefill — the one model that beats a single GPU on both phases), and runs models that do not fit one card at all (Qwen 3.5-35B-A3B; Muse-Glimmer 30B Q8_0 at 28.2 GB on 24 GB cards). Architectures that shard no weights take the same --tp N as a layer split instead — each GPU holds a contiguous run of whole layers (Qwen 3.8 Flash Next and DeepSeek V4) — which buys capacity rather than speed. GLM 5.x also layer-splits by default, while --tp N selects its native local/single-process TP path on GGML GPU backends for both GLM-5.2 and GLM-5.3-Flash; and an architecture that supports neither now says so on stderr and runs on one GPU instead of silently leaving the others idle. Optional Redis-backed KV cache and Responses API store. → Tensor Parallelism--qwen-image-lora, applied as a runtime side-path over the untouched quantized weights) that takes the default 30 steps × CFG — 60 DiT forwards — down to 4. Beat stable-diffusion.cpp 1.19× on a warm 4-step edit. → Qwen-Image-Edit card--ref-image), clips (--ref-video, with --ref-video-audio for a clip's own soundtrack) and standalone audio (--ref-audio), each taking its own stretch of the shared timeline before the generated clip, so the person or product carries over while camera, background and composition come entirely from the prompt. All of it CFG-free at 4–8 steps against a 20-step default. Seven native ggml graphs — a 50-layer Qwen3-VL-32B text encoder with its 27-block vision tower and DeepStack taps, the packed-latent DiT with its learned AdaLN curve table and 3-axis float RoPE, a pure-transformer video VAE (36 blocks, no deconvolutions), and an alias-free BigVGAN audio VAE. Frame counts snap to a 17k+5 grid (5, 22, 39, 56, 73, 90 …) and any grid length decodes correctly — the video VAE runs 5 latent frames at a time with a 2-frame look-ahead and cross-fades the seams, while h3_attend pre-scales V by a power of two derived from the key count so that a long clip's unmasked bidirectional attention (8646 packed tokens at 107 frames, against 2364 at 22) stays finite in ggml's FP16 flash-attention accumulator; before that fix a 107-frame clip came back with every pixel black and the audio clamped. Runs 2.4× faster end-to-end than stable-diffusion.cpp at 256×256 and 1.7× at 640×384 on an M5 Pro (ggml_metal); on a 16 GB RTX 3080 Laptop (ggml_cuda) stable-diffusion.cpp takes the end-to-end win instead — 1.15× at 256×256, 1.07× at 640×384 — while TensorSharp stays ahead per denoise step (3.325 s vs 3.338 s), the gap being fixed setup cost of which ~3 s is H.264 encoding and .NET startup rather than inference. Every network verified against the reference: text encoder cos 0.999999, DiT cos 0.998, both VAEs cos 1.000000/0.99999. CLI (--image, --end-image, --ref-image, --video-mode, --no-audio; the soundtrack is written as a sidecar .wav next to the MP4), /api/video-generate, /v1/videos/generations, and two auto-downloading configs — config/minimax-h3-fl2va.json and config/minimax-h3-ref2va.json — that fetch all four networks (~33.5 GB; only the denoiser differs between the two) and load them one at a time, so peak VRAM is the largest of them rather than their sum. All of it also runs on the 100% pure-C# --backend cpu path — text→video, image→video, first/last frame and reference conditioning — which agrees closely with the native ggml route without being bit-identical to it. → MiniMax-H3 cardstable-diffusion.cpp on the identical workload. Step-distilled checkpoints are auto-detected from the DiT file name (Turbo / distill / Lightning / lightx2v / FastWan / …-4steps-…) and switch to that step count with guidance off — 4 DiT passes instead of the official recipe's 100, which took the same 1088×832×121-frame image-to-video from 3 h 30 m to 17 m 30 s on an M5 Pro. It is the single biggest speed lever in the repository and needs no flag, only a different --model file. Numerics verified against diffusers (DiT cos > 0.995, VAE encoders cos > 0.999, decode 59.9 dB / >35 dB PSNR). CLI (--image), /v1/videos/generations, and Web UI chat with image upload. → Wan cardSKILL.md of model-facing instructions plus the scripts, references and assets it needs — and select them per request with "skills": ["pdf"] on any chat API or --skill on the CLI. Selection scopes reach and preference; on tool-capable models only the one-line metadata costs context up front, and the model activates a skill by pulling SKILL.md and references through built-in skills_list / skills_read tools that TensorSharp executes itself, in process. An ordinary OpenAI client therefore never sees a built-in tool call it cannot service. The injected block is a pure function of the sorted selection, so the KV prefix cache keeps matching turn to turn; every model-named path is confined to that skill's own directory. Script execution stays off unless --skills-allow-exec is passed, and the default --skills-sandbox required then runs it under OS confinement or refuses it. Loads the published open-source skills unmodified. → Agent Skills--code-exec the model gets a patch-first coding surface: bounded read_file, exact-match edit_file, deliberate whole-file write_file, atomic multi-file apply_patch, and shell for tests and commands. A source-locatable failure returns a bounded excerpt and asks for the smallest repair before rerunning. Web/CLI chats retain one workspace; each OpenAI/Ollama HTTP request gets a private workspace across its internal repair rounds and deletes it afterward. Skill scripts share that workspace when code execution is enabled, otherwise they use per-call scratch. Commands start offline; --code-exec-allow-network grants unrestricted host IP networking and is separate from --skills-allow-network and host-performed package installation. Code execution is off by default and the default policy is sandbox-or-refuse: macOS uses Seatbelt and Linux needs bwrap 0.12.0+, with the documented shared-temp/local-IPC and detached-child caveats. Windows requires the explicit --code-exec-unconfined escape hatch, which intentionally leaves filesystem and network access unconfined. → Usage${variables} and { "path", "urls" } entries that fetch the model on first run. → config/README.md--backend cpu still needs no native library, but its matmuls run on a persistent worker pool instead of a fresh Parallel.For per matmul: ~15% prefill and ~2.8× decode on gemma-4-E4B-it-Q8_0, and the managed video/image paths share the same pool. It deliberately does not take every core — its workers spin, and the rest of the CPU path still uses the ThreadPool — with TS_CPU_THREADS / TS_CPU_POOL / TS_CPU_SPIN to tune it. It also binds quantized weights zero-copy from the GGUF mapping now, exactly as the GGML backends already did, instead of expanding them to F32 at load: GLM-5.3-Flash-UD-Q2_K_XL went from a load that never finished to ~48 s, and any model whose weights used to be copied benefits (TS_DIRECT_QUANT_WEIGHTS=0 restores the old behaviour for an A/B). → Backends · Env-var matrixChatProtocol — so adding one touches its own directory plus one registration line, and no architecture-name switch is left in the loader, planner, CLI or server. → Adding a model, a modality, or a chat formatPrefer a prebuilt application? The v3.3.0.0 release provides self-contained CLI and Server archives for Windows x64 (CPU/CUDA), Linux x64 (CPU/CUDA), and macOS arm64. TensorSharp.AgentHost was added after that tag, so build the current source to use the agentic capabilities documented above until a later release explicitly includes them.
Source builds target .NET 10. On a new development machine, install the full .NET 10 SDK—the .NET Runtime alone cannot build TensorSharp:
| Platform | Install the SDK |
|---|---|
| **Windows** | In PowerShell, run winget install Microsoft.DotNet.SDK.10, or use Microsoft's [.NET installation guide for Windows](https://learn.microsoft.com/en-us/dotnet/core/install/windows). |
| **macOS** | Use the [.NET 10 SDK installer](https://dotnet.microsoft.com/en-us/download/dotnet/10.0): choose **Arm64** for Apple silicon or **x64** for an Intel Mac. See Microsoft's [macOS instructions](https://learn.microsoft.com/en-us/dotnet/core/install/macos). |
| **Linux** | Follow Microsoft's [Linux distribution guide](https://learn.microsoft.com/en-us/dotnet/core/install/linux) to configure the correct package source for your distro and install its .NET 10 SDK package (commonly dotnet-sdk-10.0). |
Open a new terminal and verify that a 10.0.x SDK is listed:
dotnet --list-sdks
See the cross-platform .NET install overview or Development → Prerequisites for more detail.
Then get running in ~30 seconds on the verified native GGML fast path — Gemma 4 E4B. The other prerequisites are git, curl, CMake 3.20+ (the native GGML library is configured and built with it — on Windows, Visual Studio's "C++ CMake tools for Windows" component ships one and the build will find it), and the toolchain for your GPU backend (see Development → Prerequisites). The recommended public file is gemma-4-E4B-it-Q8_0.gguf (7.48 GiB); text-only inference needs no projector.
Windows + NVIDIA (PowerShell)
git clone https://github.com/zhongkaifu/TensorSharp.git; Set-Location TensorSharp
New-Item -ItemType Directory -Force models | Out-Null
curl.exe -L --fail "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
'Answer in one short sentence: what is TensorSharp?' | Set-Content prompt.txt
$env: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
macOS (Apple Silicon) — drop the CUDA env var and use --backend ggml_metal.
Linux + NVIDIA — prefix the dotnet run with TENSORSHARP_GGML_NATIVE_ENABLE_CUDA=ON and use --backend ggml_cuda.
AMD / Intel / NVIDIA Vulkan — set TENSORSHARP_GGML_NATIVE_ENABLE_VULKAN=ON and use --backend ggml_vulkan.
Linux (Ubuntu) + multiple NVIDIA GPUs — tensor parallelism
Tensor parallelism splits one model across N GPUs. It runs on the direct cuda backend and on the GGML CUDA / Vulkan backends (--backend ggml_cuda, ggml_vulkan). Qwen 3.8 Flash Next and DeepSeek V4 use the same flag for a layer split instead: one contiguous run of whole layers per GPU. GLM 5.x also layer-splits by default when the flag is omitted, while --tp N selects its native local tensor-parallel path on the GGML GPU backends. Install the CUDA toolkit first, then:
```bash
add-apt-repository ppa:dotnet/backports
apt update && apt install dotnet-sdk-10.0 git clone https://github.com/zhongkaifu/TensorSharp.git cd TensorSharp mkdir models wget "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 bash TensorSharp.GGML.Native/build-linux.sh dotnet build -c Release
A pure-.NET engine going toe-to-toe with the hand-tuned C++ llama.cpp on identical GGUF files, the same NVIDIA RTX 3080 Laptop GPU (16 GB), and one uniform OpenAI /v1/chat/completions surface — with both engines measured on their GGML CUDA and Vulkan builds. Numbers are the geomean speedup of TensorSharp over llama.cpp on the same backend (single-stream, greedy, MTP off); > 1.0× means TensorSharp is faster / lower-latency. Full per-scenario tables: docs/engine_comparison_report.md.
| Model | Backend | decode | prefill | TTFT |
|---|---|---|---|---|
| Gemma 4 E4B it (Q8_0, dense multimodal) | CUDA | 1.02× | **1.28×** | **1.27×** |
| Gemma 4 E4B it (Q8_0, dense multimodal) | Vulkan | 1.00× | 1.05× | 1.03× |
| Gemma 4 12B it (QAT UD-Q4_K_XL, dense) | CUDA | 1.04× | **1.17×** | **1.16×** |
| Gemma 4 12B it (QAT UD-Q4_K_XL, dense) | Vulkan | **1.21×** | 1.04× | 1.03× |
| Qwen 3.6 35B-A3B (UD-IQ2_XXS, MoE) | CUDA | 0.98× | **1.28×** | **1.27×** |
| Qwen 3.6 35B-A3B (UD-IQ2_XXS, MoE) | Vulkan | 0.87× | 1.04× | 1.03× |
| Qwen 3.6 27B (UD-IQ2_XXS, dense) | CUDA | **1.07×** | 0.96× | 0.95× |
| Qwen 3.6 27B (UD-IQ2_XXS, dense) | Vulkan | 1.02× | 0.85× | 0.84× |
TensorSharp pulls clearly ahead on CUDA prefill / first-token latency (multi-turn prefill wins on every model, up to 1.49×), holds decode parity-or-better on CUDA, and wins Vulkan decode on the dense 12B (up to 1.32× on long context) — even at 2-bit IQ2_XXS quantization. The remaining sub-1.0× cells are active optimization targets. The harness also covers tool-calling, structured-output, image-edit (vs stable-diffusion.cpp), MTP on/off, and parallel-request scenarios you can run yourself via benchmarks/engine_comparison. Every cell is in the full report.
Models too large for that 16 GB rig carry their own head-to-head in their card, measured the same way (both engines, same GGUF, same machine, back to back): GLM-5.2 744B-A40B on 3x RTX PRO 6000 — TensorSharp leads prefill from ~1k prompt tokens up (pp2048 1.20×, pp4096 1.21×) and decode by 1.04×, with llama.cpp a few percent ahead on short prefills.
TensorSharp 是一个专为 C# 开发设计的本地推理引擎,旨在高效运行 GGUF 格式的语言模型。它不仅支持自回归 LLM,还涵盖了 DiffusionGemma 风格的文本扩散模型。项目提供了功能丰富的控制台应用程序(Console App)和基于 Web 的聊天机器人界面,并内置了兼容 Ollama 和 OpenAI 标准的 HTTP API,方便开发者快速集成到现有工作流中。
TensorSharp 具备顶级的推理性能��架构支持。它实现了类似 vLLM 的 Continuous batching 与 paged KV cache 技术,通过迭代级调度器显著提升吞吐量;支持 MTP / NextN 推测解码技术,加速 Qwen 3.6 和 Gemma 4 的单次解码速度。此外,它原生支持 Gemma 4、Qwen 3 系列等多种架构,并具备强大的多模态推理能力(支持图像、视频、音频输入)以及结构化的 Thinking / reasoning 模式。
在使用 TensorSharp 之前,请确保您的开发环境已安装 .NET 10 SDK 以及 git。为了获得最佳的硬件加速性能,建议配置相应的 GPU 工具链:NVIDIA 用户需安装 CUDA Toolkit 12.x;Apple Silicon 用户需安装 Xcode command-line tools 以启用 Metal 加速。此外,构建过程会自动从 GitHub 克隆 ggml 源码,因此需要稳定的网络访问权限。
您可以直接通过源码构建整个解决方案。首先克隆仓库,然后在终端执行 `dotnet build TensorSharp.slnx` 进行完整编译。如果仅需构建特定的应用程序,可以进入对应的项目目录进行编译。构建完成后,CLI 二进制文件将位于 `TensorSharp.Cli/bin/...`,而 Server 端程序则位于 `TensorSharp.Server/bin/...`。
TensorSharp 提供了极速的上手体验,从模型下载到实现流式回复仅需约 30 ��。首先请确保已准备好 .NET 10 SDK 和必要的 GPU 工具链(如 CUDA 或 Metal)。完成源码克隆与编译后,即可通过命令行工具启动模型。对于需要 Web 界面的用户,可以直接运行 Server 端程序,通过浏览器进行交互式对话。
您可以根据需求对 Server 端进行全局配置。通过调整采样参数(Sampling parameters),开发者可以精细化控制模型输出的随机性与创造力。所有的服务器级默认参数均可在配置文件中进行统一管理,确保在不同的推理场景下都能获得预期的生成效果。
TensorSharp 内置了高性能的 HTTP 服务,启动后可通过 http://localhost:5000 进行访问。该服务不仅提供 Web 界面,还完全兼容 Ollama 和 OpenAI 的 API 标准,这意味着您可以无缝地将 TensorSharp 替换到现有的 AI 应用生态中,实现低成本的本地化部署与迁移。
为了提高模块化程度,TensorSharp 采用了基于 NuGet Package 的分层架构设计。开发者可以根据实际需求,仅依赖所需的特定层,而无需引入整个项目。核心层 `TensorSharp.Core` 负责处理 Tensor 原语、算子(Ops)、分配器(Allocators)及存储(Storage)等底层逻辑,确保了高性能与轻量化并存。
高性能的C#推理引擎,支持本地运行LLM
AI Skill Hub 为第三方内容聚合平台,本页面信息基于公开数据整理,不对工具功能和质量作任何法律背书。
建议在沙箱或测试环境中充分验证后,再部署至生产环境,并做好必要的安全评估。
✅ BSD 3-Clause — 宽松协议,可商用修改分发,禁止使用原作者名称进行背书宣传。
AI Skill Hub 点评:TensorSharp 的核心功能完整,质量优秀。对于AI 技术爱好者来说,这是一个值得纳入个人工具库的选择。建议先在非生产环境试用,再逐步推广。
| 原始名称 | TensorSharp |
| 原始描述 | 开源AI工具:A C# inference engine for running large language models (LLMs) locally using GGU。⭐100 · C# |
| Topics | LLMC#GGUinference |
| GitHub | https://github.com/zhongkaifu/TensorSharp |
| License | BSD-3-Clause |
| 语言 | C# |
收录时间:2026-06-17 · 更新时间:2026-06-20 · License:BSD-3-Clause · AI Skill Hub 不对第三方内容的准确性作法律背书。