支持的模型

TensorSharp 加载 GGUF 格式的模型,并从文件的 general.architecture 元数据自动识别架构。选择适合你硬件的量化(低内存用 Q4_K_M,更高质量用 Q8_0)。

📘

Gemma 4 E4B 是《From Tensors to Tokens》采用的示例模型。配套图书提供从张量基础到多模态推理的连贯构建过程;本页则提供最新下载与能力细节。了解本书 →

支持的架构

架构GGUF 架构键示例模型多模态思考工具MTP 推测
Gemma 4gemma4gemma-4-E4B、12B、31B、26B-A4B (MoE)图像、视频、音频是(独立草稿)
Gemma 3gemma3gemma-3-4b图像
Qwen 3qwen3Qwen3-4B仅文本
Qwen 3.5 / 3.6qwen35qwen35moeqwen3nextQwen3.5-9B、Qwen3.5/3.6-35B-A3B (MoE)图像3.6 支持(内嵌 NextN——仅限保留 NextN 块的 GGUF,例如 -MTP- 仓库)
GPT OSSgptossgpt-ossgpt-oss-20b (MoE)仅文本是(始终)
Nemotron-Hnemotron_hnemotron_h_moeNemotron-H-8B、47B、Nemotron 3 Nano Omni图像(Omni)
Mistral 3mistral3Mistral-Small-3.1-24B-Instruct图像
DiffusionGemmadiffusion-gemmadiffusion_gemmadiffusion-gemma 文本扩散 GGUF仅文本
Qwen-Image-Editqwen_imageqwen-imageqwen-image-edit MMDiT(+ VAE 与 Qwen2.5-VL 伴随文件)图像编辑(图像+文本 → 图像)

各模型的详细架构卡(前向图、组件、参数,以及 TensorSharp 如何优化 prefill/decode)位于仓库的 docs/models/ 下。

模型下载(GGUF)

架构模型下载
Gemma 4gemma-4-E4B-itggml-org/gemma-4-E4B-it-GGUF;已验证 E4B Q8_0 原生 GGML 规格推荐使用公开文件 gemma-4-E4B-it-Q8_0.gguf;多模态投影器为同仓库的 mmproj-gemma-4-E4B-it-Q8_0.gguf
Gemma 4gemma-4-12B-it(QAT)unsloth/gemma-4-12B-it-qat-GGUF;同仓库 mmproj-BF16.ggufmtp-gemma-4-12B-it.gguf
Gemma 4gemma-4-31B-itggml-org/gemma-4-31B-it-GGUF
Gemma 4gemma-4-26B-A4B-it (MoE)ggml-org/gemma-4-26B-A4B-it-GGUF
Gemma 4gemma-4-26B-A4B-it(MoE,QAT)unsloth/gemma-4-26B-A4B-it-qat-GGUF;同仓库 mmproj-BF16.gguf 与 MTP draft;另有 AtomicChat assistant
Gemma 3gemma-3-4b-it非 gated ggml-org 仓库Q4_K_M 约 2.32 GiB,mmproj 为 mmproj-model-f16.ggufGoogle QAT 仓库需要登录并接受许可证
Gemma 3gemma-3-4b-it(官方 QAT)google/gemma-3-4b-it-qat-q4_0-ggufmmproj-model-f16-4B.gguf;⚠️ 需要 Hugging Face 登录并接受 Google Gemma 许可证
Qwen 3Qwen3-4BQwen/Qwen3-4B-GGUFQwen3-4B-Q4_K_M.gguf 约 2.33 GiB
Qwen 3.5 / 3.6Qwen3.5-9Bunsloth/Qwen3.5-9B-GGUF
Qwen 3.5 / 3.6Qwen3.5-35B-A3B (MoE)ggml-org/Qwen3.5-35B-A3B-GGUF
Qwen 3.6Qwen3.6-35B-A3B NextN MTPunsloth/Qwen3.6-35B-A3B-MTP-GGUFUD-Q4_K_M 约 21.11 GiB。基础仓库 GGUF 会剥离 NextN 块
GPT OSSgpt-oss-20b (MoE)ggml-org/gpt-oss-20b-GGUF
Nemotron-HNemotron-H-8B-Reasoning-128Kbartowski/nvidia_Nemotron-H-8B-…
Nemotron-HNemotron-H-47B-Reasoning-128Kbartowski/nvidia_Nemotron-H-47B-…
Nemotron-HNemotron 3 Nano Omni 30B-A3B(图像)unsloth/NVIDIA-Nemotron-3-Nano-Omni-…;图像输入需要同仓库 mmproj-BF16.gguf;未附真实音频推理所需的 Parakeet mmproj
Mistral 3Mistral-Small-3.1-24B-Instructbartowski/mistralai_Mistral-Small-3.1-24B-…;Q4_K_M 约 13.35 GiB;同仓库 Pixtral mmproj
DiffusionGemmadiffusiongemma-26B-A4B-itunsloth/diffusiongemma-26B-A4B-it-GGUF;Q4_K_M 约 15.65 GiB
Qwen-Image-Edit2511 MMDiT(--modelunsloth/Qwen-Image-Edit-2511-GGUFqwen-image-edit-2511-Q4_K_M.gguf 约 12.34 GiB
Qwen-Image-EditQwen-Image VAE(必需)QuantStack/Qwen-Image-Edit-GGUF 中的 VAE/Qwen_Image-VAE.safetensors;通过 --qwen-image-vae 指定
Qwen-Image-EditQwen2.5-VL-7B 文本编码器(必需)unsloth/Qwen2.5-VL-7B-Instruct-GGUF;可选视觉投影器为同仓库 mmproj-BF16.gguf
Qwen-Image-EditLightning LoRA(可选,4/8 步)lightx2v/Qwen-Image-Edit-2511-Lightning;如 Qwen-Image-Edit-2511-Lightning-4steps-V1.0-bf16.safetensors
🧩

多模态模型需要投影器(mmproj)文件。请下载匹配文件并显式传入 --mmproj;服务端不会自动检测,CLI 也只识别少数旧文件名。

下载并运行

运行构建命令前,请先按平台安装并验证 .NET 10 SDK。第一个代码块是已验证的 Gemma 4 E4B 快速上手。所有代码块都使用 Hugging Face CLI(pip install -U huggingface_hub);其后的各家族代码块假定已完成完整源码构建。从仓库根目录运行;先把问题写入 prompt.txt,并按硬件把 ggml_cuda 换成 ggml_metalggml_vulkanggml_cpu

约 30 秒快速上手:Gemma 4 E4B Q8_0(原生 GGML)

复制并运行这些命令约需 30 秒;7.48 GiB 的模型下载与首次 restore/构建耗时更长,取决于网络与机器。仓库基准已经验证 TensorSharp 的 E4B Q8_0 家族与执行路径;链接的公开 ggml-org 仓库是推荐下载源。下面的代码块面向 Linux + NVIDIA:

hf download ggml-org/gemma-4-E4B-it-GGUF gemma-4-E4B-it-Q8_0.gguf --local-dir models
TENSORSHARP_GGML_NATIVE_ENABLE_CUDA=ON dotnet build TensorSharp.slnx -c Release -p:TensorSharpSkipMlxNative=true
echo "请说明本地推理的价值。" > prompt.txt

# 纯文本不需要 mmproj。
dotnet run --project TensorSharp.Cli -c Release --no-build -- --model models/gemma-4-E4B-it-Q8_0.gguf \
    --input prompt.txt --max-tokens 300 --backend ggml_cuda
dotnet run --project TensorSharp.Server -c Release --no-build -- --model models/gemma-4-E4B-it-Q8_0.gguf \
    --backend ggml_cuda

Apple Silicon 请省略 CUDA 环境变量并使用 ggml_metal;受支持的 Windows/Linux Vulkan GPU 请改为请求 TENSORSHARP_GGML_NATIVE_ENABLE_VULKAN=ON 并使用 ggml_vulkan。图像、视频或音频输入还需运行 hf download ggml-org/gemma-4-E4B-it-GGUF mmproj-gemma-4-E4B-it-Q8_0.gguf --local-dir models,并传入 --mmproj models/mmproj-gemma-4-E4B-it-Q8_0.gguf。服务端的浏览器界面位于 http://localhost:5000/index.html。Windows PowerShell 与完整平台语法见快速开始

Gemma 3(文本 + 图像)

hf download ggml-org/gemma-3-4b-it-GGUF gemma-3-4b-it-Q4_K_M.gguf --local-dir models
hf download ggml-org/gemma-3-4b-it-GGUF mmproj-model-f16.gguf --local-dir models

dotnet TensorSharp.Cli/bin/TensorSharp.Cli.dll --model models/gemma-3-4b-it-Q4_K_M.gguf --mmproj models/mmproj-model-f16.gguf --input prompt.txt --max-tokens 300 --backend ggml_cuda
dotnet TensorSharp.Server/bin/TensorSharp.Server.dll --model models/gemma-3-4b-it-Q4_K_M.gguf --mmproj models/mmproj-model-f16.gguf --backend ggml_cuda

Qwen 3(文本、思维链、工具)

hf download Qwen/Qwen3-4B-GGUF Qwen3-4B-Q4_K_M.gguf --local-dir models

dotnet TensorSharp.Cli/bin/TensorSharp.Cli.dll --model models/Qwen3-4B-Q4_K_M.gguf --input prompt.txt --think --max-tokens 400 --backend ggml_cuda
dotnet TensorSharp.Server/bin/TensorSharp.Server.dll --model models/Qwen3-4B-Q4_K_M.gguf --backend ggml_cuda

Qwen 3.5 / 3.6(文本 + 图像、思维链、工具;3.6 支持 NextN MTP)

hf download unsloth/Qwen3.5-9B-GGUF Qwen3.5-9B-UD-Q4_K_XL.gguf --local-dir models
hf download unsloth/Qwen3.5-9B-GGUF mmproj-F16.gguf --local-dir models

dotnet TensorSharp.Cli/bin/TensorSharp.Cli.dll --model models/Qwen3.5-9B-UD-Q4_K_XL.gguf --mmproj models/mmproj-F16.gguf \
    --image photo.png --max-tokens 300 --backend ggml_cuda
dotnet TensorSharp.Server/bin/TensorSharp.Server.dll --model models/Qwen3.5-9B-UD-Q4_K_XL.gguf --mmproj models/mmproj-F16.gguf --backend ggml_cuda

Qwen 3.6 NextN 必须从保留该块的 -MTP- 仓库下载,并在服务端加入 --mtp-spec;基础仓库 GGUF 会剥离 NextN 块并回退到标准解码:

hf download unsloth/Qwen3.6-35B-A3B-MTP-GGUF Qwen3.6-35B-A3B-UD-Q4_K_M.gguf --local-dir models

dotnet TensorSharp.Server/bin/TensorSharp.Server.dll --model models/Qwen3.6-35B-A3B-UD-Q4_K_M.gguf --backend ggml_cuda --mtp-spec

GPT OSS(文本、始终思考、工具)

hf download ggml-org/gpt-oss-20b-GGUF gpt-oss-20b-mxfp4.gguf --local-dir models

dotnet TensorSharp.Cli/bin/TensorSharp.Cli.dll --model models/gpt-oss-20b-mxfp4.gguf --input prompt.txt --max-tokens 400 --backend ggml_cuda
dotnet TensorSharp.Server/bin/TensorSharp.Server.dll --model models/gpt-oss-20b-mxfp4.gguf --backend ggml_cuda

Nemotron-H(文本;Omni 分发支持图像)

hf download bartowski/nvidia_Nemotron-H-8B-Reasoning-128K-GGUF nvidia_Nemotron-H-8B-Reasoning-128K-Q4_K_M.gguf --local-dir models

dotnet TensorSharp.Cli/bin/TensorSharp.Cli.dll --model models/nvidia_Nemotron-H-8B-Reasoning-128K-Q4_K_M.gguf --input prompt.txt \
    --think --max-tokens 400 --backend ggml_cuda
dotnet TensorSharp.Server/bin/TensorSharp.Server.dll --model models/nvidia_Nemotron-H-8B-Reasoning-128K-Q4_K_M.gguf --backend ggml_cuda

图像输入请改用上表 Nemotron 3 Nano Omni GGUF 与 mmproj-BF16.gguf。当前 GGUF 分发未附真实音频推理所需的 Parakeet audio mmproj。

Mistral 3(文本 + 图像)

hf download bartowski/mistralai_Mistral-Small-3.1-24B-Instruct-2503-GGUF mistralai_Mistral-Small-3.1-24B-Instruct-2503-Q4_K_M.gguf --local-dir models
hf download bartowski/mistralai_Mistral-Small-3.1-24B-Instruct-2503-GGUF mmproj-mistralai_Mistral-Small-3.1-24B-Instruct-2503-f16.gguf --local-dir models

dotnet TensorSharp.Cli/bin/TensorSharp.Cli.dll --model models/mistralai_Mistral-Small-3.1-24B-Instruct-2503-Q4_K_M.gguf \
    --mmproj models/mmproj-mistralai_Mistral-Small-3.1-24B-Instruct-2503-f16.gguf \
    --image photo.png --max-tokens 300 --backend ggml_cuda
dotnet TensorSharp.Server/bin/TensorSharp.Server.dll --model models/mistralai_Mistral-Small-3.1-24B-Instruct-2503-Q4_K_M.gguf \
    --mmproj models/mmproj-mistralai_Mistral-Small-3.1-24B-Instruct-2503-f16.gguf --backend ggml_cuda

DiffusionGemma(分块文本扩散)

hf download unsloth/diffusiongemma-26B-A4B-it-GGUF diffusiongemma-26B-A4B-it-Q4_K_M.gguf --local-dir models

dotnet TensorSharp.Cli/bin/TensorSharp.Cli.dll --model models/diffusiongemma-26B-A4B-it-Q4_K_M.gguf --input prompt.txt \
    --max-tokens 256 --diffusion-steps 48 --diffusion-seed 0 --backend ggml_cuda
dotnet TensorSharp.Server/bin/TensorSharp.Server.dll --model models/diffusiongemma-26B-A4B-it-Q4_K_M.gguf --backend ggml_cuda

Qwen-Image-Edit(图像 + 提示词 → 编辑后的图像)

hf download unsloth/Qwen-Image-Edit-2511-GGUF qwen-image-edit-2511-Q4_K_M.gguf --local-dir models
hf download QuantStack/Qwen-Image-Edit-GGUF VAE/Qwen_Image-VAE.safetensors --local-dir models
hf download unsloth/Qwen2.5-VL-7B-Instruct-GGUF Qwen2.5-VL-7B-Instruct-Q4_K_M.gguf --local-dir models
hf download unsloth/Qwen2.5-VL-7B-Instruct-GGUF mmproj-BF16.gguf --local-dir models
hf download lightx2v/Qwen-Image-Edit-2511-Lightning Qwen-Image-Edit-2511-Lightning-4steps-V1.0-bf16.safetensors --local-dir models

dotnet TensorSharp.Cli/bin/TensorSharp.Cli.dll --model models/qwen-image-edit-2511-Q4_K_M.gguf --image input.png \
    --prompt "把天空改成壮丽的日落。" --output edited.png \
    --qwen-image-vae models/VAE/Qwen_Image-VAE.safetensors \
    --qwen-image-vl models/Qwen2.5-VL-7B-Instruct-Q4_K_M.gguf \
    --qwen-image-mmproj models/mmproj-BF16.gguf \
    --qwen-image-lora models/Qwen-Image-Edit-2511-Lightning-4steps-V1.0-bf16.safetensors \
    --backend ggml_cuda
dotnet TensorSharp.Server/bin/TensorSharp.Server.dll --model models/qwen-image-edit-2511-Q4_K_M.gguf \
    --qwen-image-vae models/VAE/Qwen_Image-VAE.safetensors \
    --qwen-image-vl models/Qwen2.5-VL-7B-Instruct-Q4_K_M.gguf \
    --qwen-image-mmproj models/mmproj-BF16.gguf \
    --qwen-image-lora models/Qwen-Image-Edit-2511-Lightning-4steps-V1.0-bf16.safetensors \
    --backend ggml_cuda

多模态支持

家族输入说明
Gemma 4图像 · 视频 · 音频图像 PNG/JPEG/HEIC;视频 MP4(经 OpenCV 以 1 fps 采样);音频 WAV 16 kHz 单声道 / MP3 / OGG。E4B 投影器:mmproj-gemma-4-E4B-it-Q8_0.gguf
Gemma 3图像PNG / JPEG / HEIC。非 gated 4B 投影器:mmproj-model-f16.gguf
Qwen 3.5 / 3.6图像动态分辨率视觉编码器;9B / 3.6 仓库使用 mmproj-F16.gguf
Mistral 3图像Pixtral 视觉编码器。投影器:mmproj-mistralai_Mistral-Small-3.1-24B-Instruct-2503-f16.gguf
Nemotron-H (Omni)图像RADIO / v2_vl ViT 编码器。传入匹配的 --mmproj;图像 token 在 <image> 占位处展开。当前 GGUF 分发未附真实音频推理需要的 Parakeet mmproj。

通过 CLI--image--video--audio--pdf)、Web UI 上传,或 HTTP API(Ollama 用 base64 images 数组,OpenAI 用 image_url data URI)发送文件。数字版 PDF 会提取文本;扫描版 PDF 会转换为页面图像并需要视觉模型。

图像编辑(Qwen-Image-Edit)

Qwen-Image-Edit 接收提示词 + 一张输入图像并返回编辑后的图像——这是与上面文本 LLM 不同的输出模态。所加载的 qwen_image GGUF 仅是 MMDiT(多模态扩散 Transformer);TensorSharp 会在其旁解析两个伴随 GGUF:

将伴随文件放在 DiT GGUF 旁,或用 TS_QWEN_IMAGE_VAE / TS_QWEN_IMAGE_TE / TS_QWEN_IMAGE_MMPROJ 指定(CLI:--qwen-image-vae / --qwen-image-vl / --qwen-image-mmproj)。流水线对参考图做 VAE 编码、构建条件、运行带参考潜变量拼接的 FlowMatch-Euler true-CFG 去噪循环,再 VAE 解码回像素。整个 60 块 DiT 前向被 CUDA 图捕获,flash 注意力默认开启;除非固定宽/高,否则目标面积按设备 VRAM 预算自动钳制。

可选的 Lightning 蒸馏 LoRA--qwen-image-lora / TS_QWEN_IMAGE_LORA.safetensors)会在加载时合并进 DiT——自动推导减少后的去噪步数(如 4 或 8),并将 CFG 切换为 1.0,跳过负向分支。去噪循环还可由整步 DiT 缓存(EasyCache 风格;TS_QWEN_DIT_CACHE_MODE = easycache / fbc)进一步加速:当某个 DiT 步的输出可由上一步预测时直接跳过。

可从 CLI--image + --prompt)、Web UI 图像编辑流程(含实时去噪预览),或在进程内从 C# 通过 QwenImageModel.EditImage() 运行。完整细节见仓库的 docs/models/qwenimage_zh-cn.md 卡片。

思考 / 推理模式

具备思考能力的模型(Qwen 3、Qwen 3.5/3.6、Gemma 4、GPT OSS、Nemotron-H)会在最终答案前产生结构化的思维链。思考内容与可见回复分离,便于客户端显示或隐藏。

通过 --think(CLI)、"think": true(Ollama API / Web UI)或浏览器中的思考开关启用。响应会单独暴露推理 —— 例如 Ollama 聊天响应中的 message.thinking

工具调用 / 函数调用

模型可以调用用户自定义工具,并参与多轮工具调用对话。将工具定义为 JSON,通过 --tools(CLI)或 tools 参数(API)传入。每个架构使用各自的线格式,但输出解析器都会将调用提取为结构化 tool_calls

完整的请求/响应示例与续接循环见 通过 HTTP 进行工具调用