能力标签
TensorSharp
🛠
AI工具

TensorSharp

基于 C# · 开源免费,本地部署,数据完全自主可控
⭐ 100 Stars 🍴 5 Forks 💻 C# 📄 BSD-3-Clause 🏷 AI 8.0分
8.0AI 综合评分
LLMC#GGUinference
✦ AI Skill Hub 推荐

经 AI Skill Hub 精选评估,TensorSharp 获评「强烈推荐」。这款AI工具在功能完整性、社区活跃度和易用性方面表现出色,AI 评分 8.0 分,适合有一定技术背景的用户使用。

📚 深度解析

TensorSharp 是一款基于 C# 的开源工具,在 GitHub 上收获 0k+ Star,是LLM、C#、GGU、inference领域中的优质开源项目。开源工具的最大优势在于代码完全透明,你可以审计每一行代码的安全性,也可以根据自身需求进行二次开发和定制。

**为什么要使用开源工具而非商业 SaaS?**
对于个人开发者和有隐私需求的用户,本地部署的开源工具意味着数据不离本机,不受第三方服务商的数据政策约束。同时,开源工具通常没有使用次数限制和月度费用,一次安装即可长期使用,对于高频使用场景的总拥有成本(TCO)远低于订阅制商业工具。

**安装与环境准备**
TensorSharp 依赖 C# 运行环境。建议通过 pyenv(Python)或 nvm(Node.js)管理 C# 版本,避免全局环境污染。对于新手用户,推荐先创建虚拟环境(python -m venv venv && source venv/bin/activate),再安装依赖,这样即使出现问题也可以随时删除虚拟环境重新开始,不影响系统稳定性。

**社区与维护**
GitHub Issue 和 Discussion 是获取帮助的最快渠道。在提问前建议先检查 Closed Issues(已关闭的问题),大多数常见问题都已有解答。遇到 Bug 时,提供 pip list 的输出、完整错误堆栈和最小可复现示例,能显著提高开发者响应速度。AI Skill Hub 将持续追踪 TensorSharp 的版本更新,及时通知重要功能变化。

📋 工具概览

TensorSharp 是一款基于 C# 开发的开源工具,专注于 LLM、C#、GGU 等核心功能。作为 GitHub 开源项目,它拥有活跃的社区支持和持续的版本迭代,代码完全透明可审计,支持本地部署以保护数据隐私。无论是个人使用还是集成到企业工作流,都能提供稳定可靠的解决方案。

GitHub Stars
⭐ 100
开发语言
C#
支持平台
Windows / macOS / Linux
维护状态
轻量级项目,按需更新
开源协议
BSD-3-Clause
AI 综合评分
8.0 分
工具类型
AI工具
Forks
5

📖 中文文档

以下内容由 AI Skill Hub 根据项目信息自动整理,如需查看完整原始文档请访问底部「原始来源」。

TensorSharp 是一款基于 C# 开发的开源工具,专注于 LLM、C#、GGU 等核心功能。作为 GitHub 开源项目,它拥有活跃的社区支持和持续的版本迭代,代码完全透明可审计,支持本地部署以保护数据隐私。无论是个人使用还是集成到企业工作流,都能提供稳定可靠的解决方案。

📌 核心特色
  • 开源免费,支持本地部署,数据完全自主可控
  • 活跃的 GitHub 开源社区,持续迭代更新
  • 提供详细文档和使用示例,新手友好
  • 支持自定义配置,灵活适配不同使用环境
  • 可作为基础组件集成进现有技术栈或进行二次开发
🎯 主要使用场景
  • 本地部署运行,保护数据隐私,满足合规要求
  • 自定义集成到现有系统,扩展技术栈能力
  • 作为开源基础组件进行商业化二次开发
以下安装命令基于项目开发语言和类型自动生成,实际以官方 README 为准。
安装命令
# 克隆仓库
git clone https://github.com/zhongkaifu/TensorSharp
cd TensorSharp

# 查看安装说明
cat README.md

# 按 README 完成环境依赖安装后即可使用
📋 安装步骤说明
  1. 访问 GitHub 仓库页面
  2. 按照 README 文档完成依赖安装
  3. 根据系统环境完成初始化配置
  4. 参考官方示例或文档开始使用
  5. 遇到问题可在 GitHub Issues 中查找解答
以下用法示例由 AI Skill Hub 整理,涵盖最常见的使用场景。
常用命令 / 代码示例
# 查看帮助
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"
📑 README 深度解析 真实文档 完整度 49/100 查看 GitHub 原文 →
以下内容由系统直接从 GitHub README 解析整理,保留代码块、表格与列表结构。

TensorSharp

<p align="center"> <img src="imgs/banner_1.png" alt="TensorSharp logo" width="320"> </p>

English | 中文

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.

Highlights

  • ⚡ Trades wins with llama.cpp — from pure .NET. On identical GGUF files and the same GPU, TensorSharp matches or beats 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
  • 🚀 Continuous batching & paged KV cache. vLLM-style paged KV pool with block-hash prefix sharing and an iteration-level scheduler, on by default in the server. The pool's bytes are host-resident, so it buys memory efficiency and prefix reuse rather than throughput that scales with concurrency. → deep dive
  • 🧬 DeepSeek V4 Flash (284B MoE) with three whole-model executors. The compressed-sparse-attention 1M-context architecture runs on a direct-CUDA engine (--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
  • 🧠 GLM-5.2 (744B-A40B MoE) with tensor parallelism and CPU MoE offload. Multi-head Latent Attention plus a DeepSeek Sparse Attention "lightning indexer" that picks which 2048 cached tokens each query may attend to. --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 card
  • 🧠 GLM-5.3-Flash (320B MoE) decodes 2.0× llama.cpp. The hybrid successor — 288 routed experts, KDA linear attention on 34 of 45 trunk layers, NoPE MLA + DSA on the other 11 with a pooled indexer (top-k 2048 over 4-cell pools, then expanded to their members), Sinkhorn hyper-connections ×4 — loads through the same native executor and the same GlmDsaModel 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
  • ⚡ Qwen 3.8 Flash Next — the whole token as one graph. A hybrid MoE: GatedDeltaNet recurrent layers on 36 of 48 layers interleaved with full-attention layers (some behind Qwen Sparse Attention's indexer), a PLE n-gram embedding block, ×4 hyper-connection streams and 512 experts with 10 used. Embedding, in-graph PLE, all 48 layers, the final mixer and the LM head run as (almost) one captured graph per token, from a shape-keyed cache; vision rides the Qwen3.5-VL tower with (T,H,W) IMRoPE, including multi-image and multi-turn image sessions with KV reuse across turns (extend-only — the GDN recurrence cannot rewind). --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
  • 🔮 Speculative decoding — four algorithms over one draft-verify runtime. Multi-token-prediction draft heads accelerate solo decode on Qwen 3.6 (NextN block embedded in the trunk — use an MTP-retaining GGUF such as unsloth/Qwen3.6-35B-A3B-MTP-GGUF; the base repo ships the same file names with the block stripped), GLM 5.2 (its NextN block ships in the stock checkpoint — ~1.3× decode, 94% draft acceptance, on 2× RTX PRO 6000 with --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
  • 🔗 Tensor parallelism & distributed clustering. Split a model across multiple GPUs with --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-Edit image editing. Prompt + input image → edited image, driving a 60-block MMDiT with a Qwen-Image VAE and Qwen2.5-VL-7B text encoder. CUDA-graph-captured DiT, FlowMatch-Euler true-CFG denoise, live Web UI previews, and a Lightning distillation LoRA fast path (--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
  • 🎬🔊 MiniMax-H3 joint audio-video generation. Prompt → video with a native 32 kHz stereo soundtrack, generated together rather than dubbed on: one 19.3B diffusion transformer denoises a packed video+audio latent in a single token sequence, up to 15 s at 24 fps. Text-to-video, image-to-video (the photo becomes the first frame and the prompt drives the motion), first/last-frame morphing, and reference-to-video on the separate Ref2VA checkpoint — up to nine references in any mix of stills (--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 card
  • 🎬 Wan 2.1 / 2.2 video generation — video only (text → video and image → video). The video-only alternative to MiniMax-H3, and the home of the repository's single biggest speed lever. Prompt → H.264 MP4; on the Wan 2.2 models (TI2V-5B, I2V-A14B) an uploaded image becomes the video's first frame while the prompt drives motion, camera and scene changes. One resident-weight ggml graph per denoise step (CUDA-graph-captured, flash attention, per-token-timestep modulation for TI2V i2v), causal 3D video VAE encode+decode each as a single graph, A14B's two 14B experts hot-swapped at the timestep boundary, stagewise VRAM handoff — TI2V-5B generates 81-frame 480p image-to-video on a 16 GB GPU in under 8 min, and Wan 2.1 runs 6.0× faster end-to-end than stable-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 card
  • 🌫️ DiffusionGemma text diffusion. Block-wise EntropyBound denoising over a Gemma-4-derived MoE backbone, with CLI flags and a Web UI denoising preview stream. → DiffusionGemma card
  • 🖼️ Multimodal. Image / video / audio (Gemma 4); image input for Qwen 3.5-family, Mistral 3, Nemotron-H Omni, and Muse-Glimmer; PDF documents via CLI and Web UI. → Multimodal
  • 🛠️ Tool calling & thinking mode. Multi-turn tool calls and structured chain-of-thought across Qwen 3.5/3.6-family, Gemma 4, GPT OSS, Nemotron-H, Muse-Glimmer (ATEM markup), and DeepSeek V4 (DSML markup). → Features
  • 🧩 Agent Skills. Point the CLI or the server at a folder of skills — a SKILL.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
  • 🖥️ Sandboxed code execution. With --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
  • 🔌 Ollama- & OpenAI-compatible APIs plus a browser chat UI — drop-in for existing tooling. → HTTP APIs
  • 📄 Config files with auto-download. Put CLI/Server options in a reusable JSON file with ${variables} and { "path", "urls" } entries that fetch the model on first run. → config/README.md
  • 🧮 Native quantized compute. Q4_K_M / Q8_0 / MXFP4 / IQ2_XXS / IQ2_S / IQ3_S / IQ3_XXS / IQ4_XS and more run in matmul without dequantizing to FP32. Runs on GGML Metal / CUDA / Vulkan, a direct CUDA/cuBLAS backend, MLX (Apple Silicon), and a pure-C# CPU path — all with CPU fallbacks. On MLX the IQ decode kernels amortize the codebook and scale loads across a whole sub-block instead of re-reading them per weight, which took a mixed-IQ 30B from 3.6 to 14.3 tok/s on an M5 Pro (67% of the fused ggml-metal graph, output byte-identical). → Backends
  • 🧵 The 100% pure-C# CPU backend now uses many cores. --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 matrix
  • 🧩 Plug-in architecture. A model family, a modality and a chat format are each one table entry — an architecture descriptor, a capability interface, a ChatProtocol — 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 format

Quick Start

Prefer 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:

PlatformInstall 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

On older Ubuntu releases the .NET 10 SDK comes from the backports PPA:

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

Head-to-head vs llama.cpp (engine comparison)

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.

ModelBackenddecodeprefillTTFT
Gemma 4 E4B it (Q8_0, dense multimodal)CUDA1.02×**1.28×****1.27×**
Gemma 4 E4B it (Q8_0, dense multimodal)Vulkan1.00×1.05×1.03×
Gemma 4 12B it (QAT UD-Q4_K_XL, dense)CUDA1.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)CUDA0.98×**1.28×****1.27×**
Qwen 3.6 35B-A3B (UD-IQ2_XXS, MoE)Vulkan0.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)Vulkan1.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.

🇨🇳 中文文档镜像 AI 翻译 2026-06-18
英文原文章节由系统翻译为中文摘要,便于快速理解。完整原文见上方 "📑 README 深度解析"。
📌 简介

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 源码,因此需要稳定的网络访问权限。

🛠 安装步骤(Docker/pip/源码)

您可以直接通过源码构建整个解决方案。首先克隆仓库,然后在终端执行 `dotnet build TensorSharp.slnx` 进行完整编译。如果仅需构建特定的应用程序,可以进入对应的项目目录进行编译。构建完成后,CLI 二进制文件将位于 `TensorSharp.Cli/bin/...`,而 Server 端程序则位于 `TensorSharp.Server/bin/...`。

🚀 使用教程

TensorSharp 提供了极速的上手体验,从模型下载到实现流式回复仅需约 30 ��。首先请确保已准备好 .NET 10 SDK 和必要的 GPU 工具链(如 CUDA 或 Metal)。完成源码克隆与编译后,即可通过命令行工具启动模型。对于需要 Web 界面的用户,可以直接运行 Server 端程序,通过浏览器进行交互式对话。

⚙️ 配置说明(含 MCP / env)

您可以根据需求对 Server 端进行全局配置。通过调整采样参数(Sampling parameters),开发者可以精细化控制模型输出的随机性与创造力。所有的服务器级默认参数均可在配置文件中进行统一管理,确保在不同的推理场景下都能获得预期的生成效果。

🔌 API 说明

TensorSharp 内置了高性能的 HTTP 服务,启动后可通过 http://localhost:5000 进行访问。该服务不仅提供 Web 界面,还完全兼容 Ollama 和 OpenAI 的 API 标准,这意味着您可以无缝地将 TensorSharp 替换到现有的 AI 应用生态中,实现低成本的本地化部署与迁移。

🔄 工作流/模块

为了提高模块化程度,TensorSharp 采用了基于 NuGet Package 的分层架构设计。开发者可以根据实际需求,仅依赖所需的特定层,而无需引入整个项目。核心层 `TensorSharp.Core` 负责处理 Tensor 原语、算子(Ops)、分配器(Allocators)及存储(Storage)等底层逻辑,确保了高性能与轻量化并存。

🎯 aiskill88 AI 点评 A 级 2026-06-17

高性能的C#推理引擎,支持本地运行LLM

📚 实用指南(长尾问题)
适合谁
  • 需要 TensorSharp 解决具体问题的开发者与运营人员
最佳实践
  • 先在测试环境跑通最小用例,再接入生产数据
常见错误
  • API key 直接提交到 git 仓库(请用 .env 并加入 .gitignore)
部署方案
  • 云端托管:可放在 Vercel / Railway / Fly.io 等 PaaS 平台
相关搜索
TensorSharp 中文教程TensorSharp 安装报错怎么办TensorSharp 与同类工具对比TensorSharp 最佳实践TensorSharp 适合谁用

⚡ 核心功能

👥 适合谁
  • 需要 TensorSharp 解决具体问题的开发者与运营人员
⭐ 最佳实践
  • 先在测试环境跑通最小用例,再接入生产数据
⚠️ 常见错误
  • API key 直接提交到 git 仓库(请用 .env 并加入 .gitignore)

👥 适合人群

AI 技术爱好者研究人员和学生开发者和工程师技术创业者

🎯 使用场景

  • 本地部署运行,保护数据隐私,满足合规要求
  • 自定义集成到现有系统,扩展技术栈能力
  • 作为开源基础组件进行商业化二次开发

⚖️ 优点与不足

✅ 优点
  • +BSD-3-Clause 协议,可免费商用
  • +完全开源免费,无授权费用
  • +本地部署,数据完全自主可控
  • +开发者社区支持,遇问题可查可问
⚠️ 不足
  • 安装和初始配置可能需要一定技术基础
  • 功能完整性通常不如成熟商业产品
  • 技术支持主要依赖开源社区,响应速度不稳定
⚠️ 使用须知

AI Skill Hub 为第三方内容聚合平台,本页面信息基于公开数据整理,不对工具功能和质量作任何法律背书。

建议在沙箱或测试环境中充分验证后,再部署至生产环境,并做好必要的安全评估。

📄 License 说明

✅ BSD 3-Clause — 宽松协议,可商用修改分发,禁止使用原作者名称进行背书宣传。

🔗 相关工具推荐

📚 相关教程推荐
📰 相关 AI 新闻
🍿 AI 圈相关吃瓜
🗺️ 相关解决方案
🧩 你可能还需要
基于当前 Skill 的能力图谱,自动补全的工具组合

❓ 常见问题 FAQ

TensorSharp 是一款C#开发的AI辅助工具。开源AI工具:A C# inference engine for running large language models (LLMs) locally using GGU。⭐100 · C# 主要应用场景包括:本地部署大型语言模型。
💡 AI Skill Hub 点评

AI Skill Hub 点评:TensorSharp 的核心功能完整,质量优秀。对于AI 技术爱好者来说,这是一个值得纳入个人工具库的选择。建议先在非生产环境试用,再逐步推广。

📚 深入学习 TensorSharp
查看分步骤安装教程和完整使用指南,快速上手这款工具
🌐 原始信息
原始名称 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#
🔗 原始来源
🐙 GitHub 仓库  https://github.com/zhongkaifu/TensorSharp 🌐 官方网站  https://tensorsharp.ai

收录时间:2026-06-17 · 更新时间:2026-06-20 · License:BSD-3-Clause · AI Skill Hub 不对第三方内容的准确性作法律背书。

📺 订阅 AI Skill Hub Daily Telegram 频道
每天 8 条精选 AI Skill、MCP、Agent 与自动化工具推送
加入频道 →