nexa-sdk-demo.mp4

Nexa SDK - 本地设备端推理框架

MacOS Linux Windows Build workflow GitHub License GitHub Release PyPI

设备端模型中心 | 文档 | Discord | 博客 | X (Twitter)

Nexa SDK 是一个本地设备端推理框架,支持 ONNX 和 GGML 模型,具备文本生成、图像生成、视觉-语言模型 (VLM)、音频-语言模型、语音转文本 (ASR) 和文本转语音 (TTS) 等功能。可通过 Python 包或可执行安装程序安装。

特性

最新消息 🔥

欢迎通过 issues 提交您的请求,我们每周发布。

安装选项 1:可执行安装程序

macOS 安装程序

Windows 安装程序

Linux 安装程序

curl -fsSL https://public-storage.nexa4ai.com/install.sh | sh
常见问题解答:无法使用已安装 nexaai python 包的可执行文件

尝试使用 nexa-exe 代替

nexa-exe <command>

安装选项 2:Python 包

我们已经发布了适用于各种 Python 版本、平台和后端的预构建 wheels,以便在我们索引页面上方便地安装。

CPU
pip install nexaai --prefer-binary --index-url https://github.nexa.ai/whl/cpu --extra-index-url https://pypi.ac.cn/simple --no-cache-dir
Apple GPU (Metal)

对于支持 Metal (macOS) 的 GPU 版本

CMAKE_ARGS="-DGGML_METAL=ON" pip install nexaai --prefer-binary --index-url https://github.nexa.ai/whl/metal --extra-index-url https://pypi.ac.cn/simple --no-cache-dir
常见问题解答:无法在 M1 上使用 Metal/GPU

尝试以下命令

wget https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-MacOSX-arm64.sh
bash Miniforge3-MacOSX-arm64.sh
conda create -n nexasdk python=3.10
conda activate nexasdk
CMAKE_ARGS="-DGGML_METAL=ON" pip install nexaai --prefer-binary --index-url https://github.nexa.ai/whl/metal --extra-index-url https://pypi.ac.cn/simple --no-cache-dir
Nvidia GPU (CUDA)

要安装 CUDA 支持,请确保已安装 CUDA Toolkit 12.0 或更高版本

对于 Linux

CMAKE_ARGS="-DGGML_CUDA=ON" pip install nexaai --prefer-binary --index-url https://github.nexa.ai/whl/cu124 --extra-index-url https://pypi.ac.cn/simple --no-cache-dir

对于 Windows PowerShell

$env:CMAKE_ARGS="-DGGML_CUDA=ON"; pip install nexaai --prefer-binary --index-url https://github.nexa.ai/whl/cu124 --extra-index-url https://pypi.ac.cn/simple --no-cache-dir

对于 Windows 命令提示符

set CMAKE_ARGS="-DGGML_CUDA=ON" & pip install nexaai --prefer-binary --index-url https://github.nexa.ai/whl/cu124 --extra-index-url https://pypi.ac.cn/simple --no-cache-dir

对于 Windows Git Bash

CMAKE_ARGS="-DGGML_CUDA=ON" pip install nexaai --prefer-binary --index-url https://github.nexa.ai/whl/cu124 --extra-index-url https://pypi.ac.cn/simple --no-cache-dir
常见问题解答:llava 的构建问题

如果您在构建时遇到以下问题

尝试以下命令

CMAKE_ARGS="-DCMAKE_CXX_FLAGS=-fopenmp" pip install nexaai
Intel GPU (SYCL)

对于 Windows

确保您已安装以下内容

.\scripts\windows-build-sycl.bat
AMD GPU (ROCm)

要安装 ROCm 支持,请确保您已安装 ROCm 6.2.1 或更高版本

对于 Linux

CMAKE_ARGS="-DGGML_HIPBLAS=on" pip install nexaai --prefer-binary --index-url https://github.nexa.ai/whl/rocm621 --extra-index-url https://pypi.ac.cn/simple --no-cache-dir
GPU (Vulkan)

要安装 Vulkan 支持,请确保您已安装 Vulkan SDK 1.3.261.1 或更高版本

对于 Windows PowerShell

$env:CMAKE_ARGS="-DGGML_VULKAN=on"; pip install nexaai --prefer-binary --index-url https://github.nexa.ai/whl/vulkan --extra-index-url https://pypi.ac.cn/simple --no-cache-dir

对于 Windows 命令提示符

set CMAKE_ARGS="-DGGML_VULKAN=on" & pip install nexaai --prefer-binary --index-url https://github.nexa.ai/whl/vulkan --extra-index-url https://pypi.ac.cn/simple --no-cache-dir

对于 Windows Git Bash

CMAKE_ARGS="-DGGML_VULKAN=on" pip install nexaai --prefer-binary --index-url https://github.nexa.ai/whl/vulkan --extra-index-url https://pypi.ac.cn/simple --no-cache-dir
本地构建

如何克隆此 repo

git clone --recursive https://github.com/NexaAI/nexa-sdk

如果您忘记使用 --recursive,可以使用以下命令添加子模块

git submodule update --init --recursive

然后您可以构建和安装软件包

pip install -e .

差异化

以下是我们与其他类似工具的差异化

特性 Nexa SDK ollama Optimum LM Studio
GGML 支持
ONNX 支持
文本生成
图像生成
视觉-语言模型
音频-语言模型
文本转语音
服务器能力
用户界面
可执行文件安装

支持的模型 & 模型中心

我们的设备端模型中心提供所有类型的量化模型(文本、图像、音频、多模态),并具有 RAM、文件大小、任务等过滤器,以帮助您轻松探索 UI 模型。在 设备端模型中心 探索设备端模型

支持的模型示例(完整列表请参见 模型中心

模型 类型 格式 命令
omniaudio AudioLM GGUF nexa run omniaudio
qwen2audio AudioLM GGUF nexa run qwen2audio
octopus-v2 函数调用 GGUF nexa run octopus-v2
octo-net 文本 GGUF nexa run octo-net
omniVLM 多模态 GGUF nexa run omniVLM
nanollava 多模态 GGUF nexa run nanollava
llava-phi3 多模态 GGUF nexa run llava-phi3
llava-llama3 多模态 GGUF nexa run llava-llama3
llava1.6-mistral 多模态 GGUF nexa run llava1.6-mistral
llava1.6-vicuna 多模态 GGUF nexa run llava1.6-vicuna
llama3.2 文本 GGUF nexa run llama3.2
llama3-uncensored 文本 GGUF nexa run llama3-uncensored
gemma2 文本 GGUF nexa run gemma2
qwen2.5 文本 GGUF nexa run qwen2.5
mathqwen 文本 GGUF nexa run mathqwen
codeqwen 文本 GGUF nexa run codeqwen
mistral 文本 GGUF/ONNX nexa run mistral
deepseek-coder 文本 GGUF nexa run deepseek-coder
DeepSeek-R1-Distill-Qwen-1.5B 文本 GGUF nexa run DeepSeek-R1-Distill-Qwen-1.5B:q4_K_M
DeepSeek-R1-Distill-Llama-8B 文本 GGUF nexa run DeepSeek-R1-Distill-Llama-8B:q4_K_M
phi3.5 文本 GGUF nexa run phi3.5
openelm 文本 GGUF nexa run openelm
stable-diffusion-v2-1 图像生成 GGUF nexa run sd2-1
stable-diffusion-3-medium 图像生成 GGUF nexa run sd3
FLUX.1-schnell 图像生成 GGUF nexa run flux
lcm-dreamshaper 图像生成 GGUF/ONNX nexa run lcm-dreamshaper
whisper-large-v3-turbo 语音转文本 BIN nexa run faster-whisper-large-turbo
whisper-tiny.en 语音转文本 ONNX nexa run whisper-tiny.en
mxbai-embed-large-v1 Embedding GGUF nexa embed mxbai
nomic-embed-text-v1.5 Embedding GGUF nexa embed nomic
all-MiniLM-L12-v2 Embedding GGUF nexa embed all-MiniLM-L12-v2:fp16
bark-small 文本转语音 GGUF nexa run bark-small:fp16
OuteTTS-0.1-350M 文本转语音 GGUF nexa run OuteTTS-0.1-350M:q4_K_M
OuteTTS-0.2-500M 文本转语音 GGUF nexa run OuteTTS-0.2-500M:q4_K_M

从 🤗 HuggingFace 或 🤖 ModelScope 运行模型

您可以使用 Nexa SDK 从 HF 或 MS 拉取、转换(为 .gguf)、量化和运行 llama.cpp 支持的 文本生成模型。

运行 .gguf 文件

使用 nexa run -hf <hf-model-id>nexa run -ms <ms-model-id> 运行带有提供的 .gguf 文件的模型

nexa run -hf Qwen/Qwen2.5-Coder-7B-Instruct-GGUF
nexa run -ms Qwen/Qwen2.5-Coder-7B-Instruct-GGUF

注意: 系统将提示您选择一个 .gguf 文件。如果您所需的量化版本有多个拆分文件(如 fp16-00001-of-00004),请使用 Nexa 的转换工具(见下文)在本地转换和量化模型。

转换 .safetensors 文件

安装 Nexa Python 包,并使用 pip install "nexaai[convert]" 安装 Nexa 转换工具,然后使用 nexa convert <hf-model-id> 从 huggingface 转换模型

nexa convert HuggingFaceTB/SmolLM2-135M-Instruct

或者您可以使用 nexa convert -ms <ms-model-id> 从 ModelScope 转换模型

nexa convert -ms Qwen/Qwen2.5-7B-Instruct

注意: 查看我们的 排行榜,了解主流语言模型的不同量化版本的性能基准,并查看 HuggingFace 文档,了解量化选项。

📋 您可以使用 nexa list 查看下载和转换的模型

文档

注意

  1. 如果您想使用 ONNX 模型,只需在提供的命令中将 pip install nexaai 替换为 pip install "nexaai[onnx]"
  2. 如果您想运行基准评估,只需在提供的命令中将 pip install nexaai 替换为 pip install "nexaai[eval]"
  3. 如果您想将 huggingface 模型转换和量化为 GGUF 模型,只需在提供的命令中将 pip install nexaai 替换为 pip install "nexaai[convert]"
  4. 如果您想使用 TTS 模型,只需在提供的命令中将 pip install nexaai 替换为 pip install nexaai[tts]
  5. 对于中国开发者,我们建议您使用清华大学开源软件镜像站作为额外的索引网址,只需在提供的命令中将 --extra-index-url https://pypi.ac.cn/simple 替换为 --extra-index-url https://pypi.tuna.tsinghua.edu.cn/simple

CLI 参考

以下是主要 CLI 命令的简要概述

有关 CLI 命令和用法的详细信息,请参阅 CLI 参考 文档。

启动本地服务器

要使用本地计算机上的模型启动本地服务器,您可以使用 nexa server 命令。有关服务器设置、API 端点和使用示例的详细信息,请参阅 服务器参考 文档。

基准测试

安装 Nexa Python 包,并使用 pip install "nexaai[eval]" 安装 Nexa 基准测试工具,然后使用以下命令评估模型的基准:

nexa eval <model_path> --tasks <task> --num_workers <num_workers>

Swift 包

Swift SDK 提供了一个 Swifty API,允许 Swift 开发人员轻松地在其项目中集成和使用 llama.cpp 模型。

更多文档

致谢

我们要感谢以下项目: