返回模型
说明文档
这是 Mistral 7B 模型的优化版本,可在以下仓库获取:https://huggingface.co/mistralai/Mistral-7B-v0.1,并受该仓库许可证的约束。Microsoft 允许您在遵守许可协议中的限制和免责声明的前提下,使用、修改、重新分发 Microsoft 对优化版本的贡献并创建衍生作品。
Mistral-7b for ONNX Runtime
简介
本仓库托管了 Mistral-7B-v0.1 的优化版本,以加速使用 ONNX Runtime CUDA 执行提供程序的推理。
请参阅使用说明了解如何使用本仓库中托管的 ONNX 文件对该模型进行推理。
模型描述
- 开发者: MistralAI
- 模型类型: 预训练生成式文本模型
- 许可证: Apache 2.0 许可证
- 模型描述: 这是 Mistral-7B-v0.1 的转换版本,用于使用 CUDA 执行提供程序进行 ONNX Runtime 推理。
性能对比
Token 生成延迟
以下是在 NVIDIA A100-SXM4-80GB GPU 上,使用不同大小的提示生成一个 token 的平均延迟,数据来自 ORT Mistral 基准测试脚本
| 提示长度 | 批量大小 | PyTorch 2.1 torch.compile | ONNX Runtime CUDA |
|---|---|---|---|
| 32 | 1 | 32.58ms | 12.08ms |
| 256 | 1 | 54.54ms | 23.20ms |
| 1024 | 1 | 100.6ms | 77.49ms |
| 2048 | 1 | 236.8ms | 144.99ms |
| 32 | 4 | 63.71ms | 15.32ms |
| 256 | 4 | 86.74ms | 75.94ms |
| 1024 | 4 | 380.2ms | 273.9ms |
| 2048 | 4 | N/A | 554.5ms |
使用示例
按照基准测试说明操作。示例步骤:
- 克隆 onnxruntime 仓库。
git clone https://github.com/microsoft/onnxruntime
cd onnxruntime
- 安装所需依赖
python3 -m pip install -r onnxruntime/python/tools/transformers/models/llama/requirements-cuda.txt
- 使用手动模型 API 进行推理,或使用 Hugging Face 的 ORTModelForCausalLM
from optimum.onnxruntime import ORTModelForCausalLM
from onnxruntime import InferenceSession
from transformers import AutoConfig, AutoTokenizer
sess = InferenceSession(\"Mistral-7B-v0.1.onnx\", providers = [\"CUDAExecutionProvider\"])
config = AutoConfig.from_pretrained(\"mistralai/Mistral-7B-v0.1\")
model = ORTModelForCausalLM(sess, config, use_cache = True, use_io_binding = True)
tokenizer = AutoTokenizer.from_pretrained(\"mistralai/Mistral-7B-v0.1\")
inputs = tokenizer(\"Instruct: What is a fermi paradox?\nOutput:\", return_tensors=\"pt\")
outputs = model.generate(**inputs)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
microsoft/Mistral-7B-v0.1-onnx
作者 microsoft
↓ 0
♥ 17
创建时间: 2023-11-14 17:07:36+00:00
更新时间: 2024-03-19 18:56:14+00:00
在 Hugging Face 上查看文件 (4)
.gitattributes
Mistral-7B-v0.1.onnx
ONNX
Mistral-7B-v0.1.onnx.data
README.md