DeepSparse 模型性能基准测试指南

DeepSparse 模型性能基准测试指南

deepsparse Sparsity-aware deep learning inference runtime for CPUs deepsparse 项目地址: https://gitcode.com/gh_mirrors/de/deepsparse

概述

DeepSparse 是一个针对稀疏神经网络优化的高性能推理引擎,能够显著提升模型在CPU上的推理速度。本文将详细介绍如何使用DeepSparse的基准测试工具来评估模型性能,帮助开发者了解不同配置下的模型表现。

环境准备

安装DeepSparse

首先需要安装DeepSparse及其依赖项:

pip install deepsparse[onnxruntime]

建议在32核的AWS c6i.16xlarge实例上进行测试,以获得最佳性能表现。

快速入门

稀疏与密集模型性能对比

让我们通过BERT模型来比较DeepSparse在密集模型和稀疏模型上的表现差异。

测试密集BERT模型

deepsparse.benchmark zoo:nlp/sentiment_analysis/obert-base/pytorch/huggingface/sst2/base-none --batch_size 64

测试90%稀疏度的BERT模型

deepsparse.benchmark zoo:nlp/sentiment_analysis/obert-base/pytorch/huggingface/sst2/pruned90_quant-none --batch_size 64

测试结果显示,稀疏模型达到了889 items/sec的吞吐量,而密集模型仅为102 items/sec,性能提升了8.7倍

与ONNX Runtime对比

DeepSparse还支持与ONNX Runtime进行性能对比:

deepsparse.benchmark zoo:nlp/sentiment_analysis/obert-base/pytorch/huggingface/sst2/base-none --batch_size 64 --engine onnxruntime

测试结果表明,在相同条件下,DeepSparse比ONNX Runtime快13.8倍,这充分展示了DeepSparse在稀疏模型优化方面的优势。

高级使用指南

本地模型测试

除了使用预置模型,也可以测试本地ONNX模型:

  1. 首先下载模型:
sparsezoo.download zoo:cv/detection/yolov5-s/pytorch/ultralytics/coco/pruned85_quant-none --save-dir yolov5-download
  1. 然后测试本地模型:
deepsparse.benchmark yolov5-download/model.onnx

批处理大小优化

批处理大小对性能有显著影响。以ResNet-50为例:

  • 批处理大小为1时:
deepsparse.benchmark zoo:cv/classification/resnet_v1-50/pytorch/sparseml/imagenet/pruned95_quant-none --batch_size 1
  • 批处理大小为64时:
deepsparse.benchmark zoo:cv/classification/resnet_v1-50/pytorch/sparseml/imagenet/pruned95_quant-none --batch_size 64

在多核CPU上,增大批处理大小通常能更好地利用硬件资源,提高吞吐量。

自定义输入尺寸

通过--input_shape参数可以调整输入尺寸:

  • BERT模型序列长度调整为384:
deepsparse.benchmark zoo:nlp/sentiment_analysis/obert-base/pytorch/huggingface/sst2/pruned90_quant-none --input_shape [1,384]
  • YOLOv5输入图像尺寸调整为320x320:
deepsparse.benchmark zoo:cv/detection/yolov5-s/pytorch/ultralytics/coco/pruned85_quant-none -i [1,3,320,320]

推理场景选择

DeepSparse支持两种推理场景:

  1. 同步推理(默认):
deepsparse.benchmark zoo:nlp/sentiment_analysis/obert-base/pytorch/huggingface/sst2/pruned90_quant-none --scenario sync

适合边缘计算场景,追求单次推理延迟最低。

  1. 异步推理
deepsparse.benchmark zoo:nlp/sentiment_analysis/obert-base/pytorch/huggingface/sst2/pruned90_quant-none --scenario async --num_streams 8

适合服务器场景,通过并发处理提高吞吐量。

性能优化建议

  1. 稀疏模型优先:尽可能使用经过剪枝和量化的稀疏模型,能获得最佳性能提升
  2. 批处理大小调优:根据实际业务需求和硬件配置,找到最佳批处理大小
  3. 多核利用:在高核数CPU上,使用异步推理可以更好地利用硬件资源
  4. 输入尺寸优化:在不影响精度的前提下,适当减小输入尺寸可提高性能

通过合理配置这些参数,开发者可以在不同应用场景下获得最优的模型推理性能。

deepsparse Sparsity-aware deep learning inference runtime for CPUs deepsparse 项目地址: https://gitcode.com/gh_mirrors/de/deepsparse

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

盛言蓓Juliana

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值