链载Ai
标题: 大语言模型引擎全解析:Transformers、vLLM、Llama.cpp、SGLang、MLX 和 Ollama [打印本页]
作者: 链载Ai 时间: 1 小时前
标题: 大语言模型引擎全解析:Transformers、vLLM、Llama.cpp、SGLang、MLX 和 Ollama
本文将带你深入了解 Transformers、vLLM、Llama.cpp、SGLang、MLX 和 Ollama 这些引擎,帮助你找到最适合的工具,释放大语言模型的全部潜力!
一、Transformers 引擎:NLP领域的全能王者
开发者:Hugging Face
核心特色:作为当下最炙手可热的开源NLP库,Transformers堪称NLP领域的“瑞士军刀”,它支持数百种预训练模型,涵盖GPT、BERT、T5等知名模型,从模型加载、微调,到推理,提供了一站式解决方案。
显著优势:
兼容性强:完美适配PyTorch和TensorFlow,为开发者提供更多选择。
生态繁荣:拥有活跃的社区,丰富的模型库与完善的文档,无论是初学者入门,还是专家深入研究,都能从中获益。
应用广泛:适用于从学术研究到工业生产的各类NLP任务。
适用场景:当你需要快速实现文本分类、生成、翻译等任务时,Transformers是不二之选,能助力你轻松实现NLP应用落地 。
二、vLLM 引擎:GPU推理的性能巅峰
开发者:UC Berkeley研究团队
核心特色:vLLM专注于大语言模型推理,凭借创新的内存管理技术(如PagedAttention),大幅提升GPU利用率与推理速度,堪称GPU推理的“性能怪兽”。
显著优势:
性能卓越:极致的推理速度,能够满足大规模部署需求。
内存高效:高效的内存管理,支持更大的模型批次处理。
场景适配:专为GPU优化,在高并发场景中表现出色。
适用场景:若你需在生产环境部署大语言模型,并追求极致性能,vLLM无疑是最佳选择,它能提升模型推理速度,降低硬件成本 。
三、Llama.cpp 引擎:CPU上的轻量化先锋
开发者:社区项目
核心特色:Llama.cpp基于C++实现,专为运行Meta的LLaMA模型而生,通过优化计算与内存管理,让大模型在CPU上运行成为现实,是CPU设备上的“轻量级王者”。
显著优势:
轻量运行:无需GPU,在普通CPU设备上即可运行。
灵活部署:适合资源受限环境,如嵌入式设备、低配服务器。
开源拓展:开源特性使其易于扩展和定制。
适用场景:当设备无GPU资源,却需运行大语言模型时,Llama.cpp是理想之选,让普通设备也能体验大语言模型的强大 。
四、SGLang 引擎:高效推理的潜力新星
开发者:未知
核心特色:SGLang专注高效推理,可能运用稀疏计算、分布式优化等技术提升性能,虽充满神秘感,但潜力无限。
显著优势:
五、MLX 引擎:高效计算的未来之光
开发者:未知
核心特色:MLX可能是针对大语言模型优化的机器学习框架,聚焦高效计算与推理,是高效计算领域的“未来之星”。
显著优势:
六、Ollama:本地大模型运行的便捷之选
开发者:社区项目
核心特色:Ollama是本地运行大语言模型的利器,支持LLaMA、GPT等多种模型,简化模型部署与运行流程。
显著优势:
七、指标对比
1. 性能对比
| | | |
|---|
| ingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: no-common-ligatures;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: center;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;">Transformers | | | |
| ingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: no-common-ligatures;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: center;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;background-color: rgb(247, 247, 247);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;">vLLM | 高性能推理,通过 PagedAttention 等技术优化 GPU 内存和计算效率。 | | |
| ingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: no-common-ligatures;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: center;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;">Llama.cpp | 针对 CPU 优化,性能中等,适合资源受限的环境。 | | |
| ingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: no-common-ligatures;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: center;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;background-color: rgb(247, 247, 247);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;">SGLang | 可能通过稀疏计算或分布式优化提升性能,具体性能取决于实现。 | | |
| ingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: no-common-ligatures;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: center;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;">MLX | 可能针对特定硬件(如 TPU 或定制芯片)优化,性能潜力高。 | | |
| ingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: no-common-ligatures;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: center;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;background-color: rgb(247, 247, 247);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;">Ollama | | | |
总结:
ingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif;font-style: normal;font-variant-ligatures: no-common-ligatures;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;" class="list-paddingleft-1">vLLM在 GPU 上的推理性能最优,适合大规模模型。
Llama.cpp和Ollama适合在 CPU 或低配设备上运行中小规模模型。
SGLang和MLX的性能潜力较大,但需要更多实践验证。
ingFang SC", "Microsoft YaHei", SimHei, Arial, SimSun;font-size: 16px;color: rgb(79, 79, 79);line-height: 26px;font-synthesis-style: auto;overflow-wrap: break-word;font-style: normal;font-variant-ligatures: no-common-ligatures;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: start;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;">2.并发能力对比 | | |
|---|
| Transformers | 支持多线程和多 GPU 推理,但并发能力受限于框架和硬件。 | |
| vLLM | 高并发支持,通过内存优化和批处理技术显著提升并发性能。 | |
| ingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: no-common-ligatures;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: center;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;background-color: rgb(255, 255, 255);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;">Llama.cpp | | |
| ingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif;font-size: 14px;font-style: normal;font-variant-ligatures: no-common-ligatures;font-variant-caps: normal;letter-spacing: normal;orphans: 2;text-align: center;text-indent: 0px;text-transform: none;widows: 2;word-spacing: 0px;-webkit-text-stroke-width: 0px;white-space: normal;background-color: rgb(247, 247, 247);text-decoration-thickness: initial;text-decoration-style: initial;text-decoration-color: initial;">SGLang | 可能通过分布式计算支持高并发,具体能力取决于实现。 | |
| | |
| | |
总结:
3.适用场景对比
| | |
|---|
| Transformers | | |
| vLLM | | |
| | |
| | |
| MLX | | |
| Ollama | | |
总结:
Transformers是通用性最强的工具,适合大多数 NLP 任务。
vLLM是企业级高并发场景的首选。
Llama.cpp和Ollama适合个人开发者或资源受限的环境。
SGLang和MLX适合需要高性能或特定硬件支持的场景。
4.硬件兼容性对比
| | |
|---|
| Transformers | | |
| vLLM | | |
| Llama.cpp | | |
| SGLang | | |
| MLX | | |
| Ollama | | |
总结:
Transformers和Ollama兼容性最强,支持多种设备。
vLLM和SGLang需要高性能 GPU 或服务器。
Llama.cpp适合低配设备,而MLX需要特定硬件支持。
八、每秒输出token对比
1. 性能影响因素
在对比 TPS 之前,需要明确影响性能的关键因素:
硬件性能: GPU 的算力、显存带宽、显存容量等。
模型规模: 参数量越大,推理速度越慢。
批处理大小(Batch Size): 较大的批处理可以提高吞吐量,但会增加显存占用。
引擎优化: 不同引擎在内存管理、计算优化等方面的表现差异显著。
2.GPU 性能对比
以下是 A800、A100 和 H100 的主要参数对比:
3.引擎 TPS 对比
以下是各引擎在不同 GPU 上的预估 TPS(以 LLaMA-13B 模型为例):
说明:
vLLM 在高性能 GPU(如 H100)上的表现最佳,TPS 可达 500-1000,远超其他引擎。
Transformers 性能中等,适合通用场景。
Llama.cpp 和 Ollama 性能较低,适合资源受限的环境。
SGLang 和 MLX 的性能数据较少,需进一步测试。
九、这里简单介绍一下 Xinference 安装
Xinference 在 Linux, Windows, MacOS 上都可以通过pip来安装。如果需要使用 Xinference 进行模型推理,可以根据不同的模型指定不同的引擎。
如果你希望能够推理所有支持的模型,可以用以下命令安装所有需要的依赖:
pipinstall"xinference[all]"
备注
如果你想使用 GGML 格式的模型,建议根据当前使用的硬件手动安装所需要的依赖,以充分利用硬件的加速能力。更多细节可以参考Llama.cpp 引擎这一章节。
如果你只想安装必要的依赖,接下来是如何操作的详细步骤。
Transformers 引擎
PyTorch(transformers) 引擎支持几乎有所的最新模型,这是 Pytorch 模型默认使用的引擎:
pipinstall"xinference[transformers]"
vLLM 引擎
vLLM 是一个支持高并发的高性能大模型推理引擎。当满足以下条件时,Xinference 会自动选择 vllm 作为引擎来达到更高的吞吐量:
模型格式为pytorch,gptq或者awq。
当模型格式为pytorch时,量化选项需为none。
当模型格式为awq时,量化选项需为Int4。
当模型格式为gptq时,量化选项需为Int3、Int4或者Int8。
操作系统为 Linux 并且至少有一个支持 CUDA 的设备
自定义模型的model_family字段和内置模型的model_name字段在 vLLM 的支持列表中。
目前,支持的模型包括:
llama-2,llama-3,llama-2-chat,llama-3-instruct
baichuan,baichuan-chat,baichuan-2-chat
internlm-16k,internlm-chat-7b,internlm-chat-8k,internlm-chat-20b
mistral-v0.1,mistral-instruct-v0.1,mistral-instruct-v0.2,mistral-instruct-v0.3
codestral-v0.1
Yi,Yi-1.5,Yi-chat,Yi-1.5-chat,Yi-1.5-chat-16k
code-llama,code-llama-python,code-llama-instruct
DeepSeek,deepseek-coder,deepseek-chat,deepseek-coder-instruct
codeqwen1.5,codeqwen1.5-chat
vicuna-v1.3,vicuna-v1.5
internlm2-chat
qwen-chat
mixtral-instruct-v0.1,mixtral-8x22B-instruct-v0.1
chatglm3,chatglm3-32k,chatglm3-128k
glm4-chat,glm4-chat-1m
qwen1.5-chat,qwen1.5-moe-chat
qwen2-instruct,qwen2-moe-instruct
gemma-it
orion-chat,orion-chat-rag
c4ai-command-r-v01
安装 xinference 和 vLLM:
pipinstall"xinference[vllm]"
Llama.cpp 引擎
Xinference 通过llama-cpp-python支持gguf和ggml格式的模型。建议根据当前使用的硬件手动安装依赖,从而获得最佳的加速效果。
初始步骤:
pipinstallxinference
不同硬件的安装方式:
Apple M系列
CMAKE_ARGS="-DLLAMA_METAL=on"pipinstallllama-cpp-python
英伟达显卡:
CMAKE_ARGS="-DLLAMA_CUBLAS=on"pipinstallllama-cpp-python
AMD 显卡:
CMAKE_ARGS="-DLLAMA_HIPBLAS=on"pipinstallllama-cpp-python
SGLang 引擎
SGLang 具有基于 RadixAttention 的高性能推理运行时。它通过在多个调用之间自动重用KV缓存,显著加速了复杂 LLM 程序的执行。它还支持其他常见推理技术,如连续批处理和张量并行处理。
初始步骤:
pipinstall'xinference[sglang]'
十、Xinference环境变量
XINFERENCE_ENDPOINT
Xinference 的服务地址,用来与 Xinference 连接。默认地址是 http://127.0.0.1:9997,可以在日志中获得这个地址。
XINFERENCE_MODEL_SRC
配置模型下载仓库。默认下载源是 “huggingface”,也可以设置为 “modelscope” 作为下载源。
XINFERENCE_HOME
Xinference 默认使用<HOME>/.xinference作为默认目录来存储模型以及日志等必要的文件。其中<HOME>是当前用户的主目录。可以通过配置这个环境变量来修改默认目录。
XINFERENCE_HEALTH_CHECK_ATTEMPTS
Xinference 启动时健康检查的次数,如果超过这个次数还未成功,启动会报错,默认值为 3。
XINFERENCE_HEALTH_CHECK_INTERVAL
Xinference 启动时健康检查的时间间隔,如果超过这个时间还未成功,启动会报错,默认值为 3。
XINFERENCE_DISABLE_HEALTH_CHECK
在满足条件时,Xinference 会自动汇报worker健康状况,设置改环境变量为 1可以禁用健康检查。
XINFERENCE_DISABLE_VLLM
在满足条件时,Xinference 会自动使用 vLLM 作为推理引擎提供推理效率,设置改环境变量为 1可以禁用 vLLM。
XINFERENCE_DISABLE_METRICS
Xinference 会默认在 supervisor 和 worker 上启用 metrics exporter。设置环境变量为 1可以在 supervisor 上禁用 /metrics 端点,并在 worker 上禁用 HTTP 服务(仅提供 /metrics 端点)
| 欢迎光临 链载Ai (https://www.lianzai.com/) |
Powered by Discuz! X3.5 |