콘텐츠로 건너뛰기

Neural Magic의 딥스페이스

소프트웨어 제공 AI에 오신 것을 환영합니다.

이 가이드에서는 Neural Magic 의 DeepSparse를 사용하여 YOLOv5 를 배포하는 방법을 설명합니다.

DeepSparse는 CPU에서 탁월한 성능을 발휘하는 추론 런타임입니다. 예를 들어, ONNX 런타임 기준과 비교했을 때, 동일한 컴퓨터에서 실행되는 YOLOv5의 경우 DeepSparse는 5.8배의 속도 향상을 제공합니다!

YOLOv5 속도 향상

For the first time, your deep learning workloads can meet the performance demands of production without the complexity and costs of hardware accelerators. Put simply, DeepSparse gives you the performance of GPUs and the simplicity of software:

  • 유연한 배포: 클라우드, 데이터센터, 엣지 전반에서 일관되게 실행: Intel , AMD, ARM 등 모든 하드웨어 공급업체와 함께 실행하세요.
  • 무한한 확장성: 100개의 코어로 수직 확장하거나, 표준 Kubernetes로 확장하거나, 서버리스로 완전히 추상화할 수 있습니다.
  • 간편한 통합: 모델을 애플리케이션에 통합하고 프로덕션 환경에서 모니터링하기 위한 깔끔한 API

DeepSparse는 어떻게 GPU-클래스 성능을 달성하나요?

DeepSparse는 모델 희소성을 활용하여 성능 속도를 높입니다.

Sparsification through pruning and quantization is a broadly studied technique, allowing order-of-magnitude reductions in the size and compute needed to execute a network, while maintaining high accuracy. DeepSparse is sparsity-aware, meaning it skips the zeroed out parameters, shrinking amount of compute in a forward pass. Since the sparse computation is now memory bound, DeepSparse executes the network depth-wise, breaking the problem into Tensor Columns, vertical stripes of computation that fit in cache.

YOLO 모델 가지치기

캐시에서 깊이 단위로 실행되는 압축 연산이 포함된 스파스 네트워크를 통해 DeepSparse는 CPU에서 GPU-급 성능을 제공할 수 있습니다!

내 데이터로 훈련된 YOLOv5 의 스파스 버전을 만들려면 어떻게 하나요?

Neural Magic의 오픈 소스 모델 저장소인 SparseZoo에는 각 YOLOv5 모델에 대해 미리 지정된 체크포인트가 포함되어 있습니다. Ultralytics 과 통합된 SparseML을 사용하면 CLI 명령 한 번으로 데이터에 대한 스파스 체크포인트를 미세 조정할 수 있습니다.

자세한 내용은 Neural Magic 의 YOLOv5 문서를 참조하세요.

딥스페이스 사용

DeepSparse를 사용하여 YOLOv5의 스파스 버전을 벤치마킹하고 배포하는 예제를 살펴보겠습니다.

DeepSparse 설치

다음을 실행하여 DeepSparse를 설치합니다. Python 을 사용하여 가상 환경을 사용하는 것이 좋습니다.

pip install "deepsparse[server,yolo,onnxruntime]"

ONNX 파일 수집

DeepSparse는 ONNX 형식으로 전달된 모델을 허용합니다:

  • SparseZoo의 ONNX 파일을 식별하는 SparseZoo 스텁입니다.
  • 파일 시스템에서 ONNX 모델에 대한 로컬 경로

아래 예시에서는 다음 SparseZoo 스텁으로 식별되는 표준 조밀하고 정량화된 YOLOv5s 체크포인트를 사용합니다:

zoo:cv/detection/yolov5-s/pytorch/ultralytics/coco/base-none
zoo:cv/detection/yolov5-s/pytorch/ultralytics/coco/pruned65_quant-none

모델 배포

DeepSparse는 모델을 애플리케이션에 통합하기 위한 편리한 API를 제공합니다.

아래 배포 예제를 사용해 보려면 샘플 이미지를 끌어와서 다음 이름으로 저장하세요. basilica.jpg 를 다음과 같이 설정합니다:

wget -O basilica.jpg https://raw.githubusercontent.com/neuralmagic/deepsparse/main/src/deepsparse/yolo/sample_images/basilica.jpg

Python API

Pipelines 는 전처리와 출력 후처리를 런타임에 래핑하여 애플리케이션에 DeepSparse를 추가하기 위한 깔끔한 인터페이스를 제공합니다. DeepSparse-Ultralytics 통합에는 즉시 사용 가능한 Pipeline 원시 이미지를 받아들이고 경계 상자를 출력하는 함수입니다.

만들기 Pipeline 를 클릭하고 추론을 실행합니다:

from deepsparse import Pipeline

# list of images in local filesystem
images = ["basilica.jpg"]

# create Pipeline
model_stub = "zoo:cv/detection/yolov5-s/pytorch/ultralytics/coco/pruned65_quant-none"
yolo_pipeline = Pipeline.create(
    task="yolo",
    model_path=model_stub,
)

# run inference on images, receive bounding boxes + classes
pipeline_outputs = yolo_pipeline(images=images, iou_thres=0.6, conf_thres=0.001)
print(pipeline_outputs)

클라우드에서 실행 중인 경우, open-cv를 찾을 수 없다는 오류가 발생할 수 있습니다. libGL.so.1. Ubuntu에서 다음을 실행하면 설치됩니다:

apt-get install libgl1

HTTP 서버

DeepSparse Server runs on top of the popular FastAPI web framework and Uvicorn web server. With just a single CLI command, you can easily setup a model service endpoint with DeepSparse. The Server supports any Pipeline from DeepSparse, including object detection with YOLOv5, enabling you to send raw images to the endpoint and receive the bounding boxes.

정리된 정량화된 YOLOv5로 서버를 스핀업합니다:

deepsparse.server \
    --task yolo \
    --model_path zoo:cv/detection/yolov5-s/pytorch/ultralytics/coco/pruned65_quant-none

Python 를 사용한 요청 예시 requests 패키지입니다:

import json

import requests

# list of images for inference (local files on client side)
path = ["basilica.jpg"]
files = [("request", open(img, "rb")) for img in path]

# send request over HTTP to /predict/from_files endpoint
url = "http://0.0.0.0:5543/predict/from_files"
resp = requests.post(url=url, files=files)

# response is returned in JSON
annotations = json.loads(resp.text)  # dictionary of annotation results
bounding_boxes = annotations["boxes"]
labels = annotations["labels"]

주석 달기 CLI

주석 달기 명령을 사용하여 엔진이 주석이 달린 사진을 디스크에 저장하도록 할 수도 있습니다. 소스 0을 사용해 라이브 웹캠 피드에 주석을 달아 보세요!

deepsparse.object_detection.annotate --model_filepath zoo:cv/detection/yolov5-s/pytorch/ultralytics/coco/pruned65_quant-none --source basilica.jpg

위 명령을 실행하면 annotation-results 폴더에 주석이 달린 이미지를 저장합니다.

주석이 달린

벤치마킹 성능

DeepSparse의 벤치마킹 스크립트를 사용하여 YOLOv5에서 ONNX 런타임의 처리량과 DeepSparse의 처리량을 비교해 보겠습니다.

벤치마크는 AWS에서 실행되었습니다. c6i.8xlarge 인스턴스(16코어).

배치 32 성능 비교

ONNX 런타임 기준선

배치 32에서 ONNX 런타임은 표준 고밀도 YOLOv5를 사용하여 초당 42개의 이미지를 달성합니다:

deepsparse.benchmark zoo:cv/detection/yolov5-s/pytorch/ultralytics/coco/base-none -s sync -b 32 -nstreams 1 -e onnxruntime

> Original Model Path: zoo:cv/detection/yolov5-s/pytorch/ultralytics/coco/base-none
> Batch Size: 32
> Scenario: sync
> Throughput (items/sec): 41.9025

딥스페이스 고밀도 성능

딥스파스는 최적화된 스파스 모델에서 최고의 성능을 제공하지만, 표준 고밀도 YOLOv5에서도 우수한 성능을 발휘합니다.

배치 32에서 딥스페이스는 표준 고밀도 YOLOv5s로 초당 70개의 이미지를 달성하여 ORT보다 1.7배 성능이 향상되었습니다!

deepsparse.benchmark zoo:cv/detection/yolov5-s/pytorch/ultralytics/coco/base-none -s sync -b 32 -nstreams 1

> Original Model Path: zoo:cv/detection/yolov5-s/pytorch/ultralytics/coco/base-none
> Batch Size: 32
> Scenario: sync
> Throughput (items/sec): 69.5546

딥스페어스 스파스 성능

모델에 희소성을 적용하면 ONNX 런타임에 비해 DeepSparse의 성능 향상은 더욱 강력해집니다.

배치 32에서 딥스페이스는 프루닝된 정량화된 YOLOv5s로 초당 241 이미지를 달성하며, 이는 ORT보다 5.8배 향상된 성능입니다!

deepsparse.benchmark zoo:cv/detection/yolov5-s/pytorch/ultralytics/coco/pruned65_quant-none -s sync -b 32 -nstreams 1

> Original Model Path: zoo:cv/detection/yolov5-s/pytorch/ultralytics/coco/pruned65_quant-none
> Batch Size: 32
> Scenario: sync
> Throughput (items/sec): 241.2452

배치 1 성능 비교

또한 딥스페이스는 지연 시간에 민감한 배치 1 시나리오의 경우 ONNX 런타임보다 속도를 높일 수 있습니다.

ONNX 런타임 기준선

배치 1에서 ONNX 런타임은 표준 고밀도 YOLOv5를 사용하여 초당 48개의 이미지를 달성합니다.

deepsparse.benchmark zoo:cv/detection/yolov5-s/pytorch/ultralytics/coco/base-none -s sync -b 1 -nstreams 1 -e onnxruntime

> Original Model Path: zoo:cv/detection/yolov5-s/pytorch/ultralytics/coco/base-none
> Batch Size: 1
> Scenario: sync
> Throughput (items/sec): 48.0921

딥스페어스 스파스 성능

배치 1에서 DeepSparse는 정리된 정량화된 YOLOv5s로 초당 135개의 항목을 달성하여 ONNX 런타임에 비해 2.8배의 성능 향상을 달성했습니다 !

deepsparse.benchmark zoo:cv/detection/yolov5-s/pytorch/ultralytics/coco/pruned65_quant-none -s sync -b 1 -nstreams 1

> Original Model Path: zoo:cv/detection/yolov5-s/pytorch/ultralytics/coco/pruned65_quant-none
> Batch Size: 1
> Scenario: sync
> Throughput (items/sec): 134.9468

이후 c6i.8xlarge 인스턴스에 VNNI 명령어가 있는 경우, 가중치를 4블록 단위로 잘라내면 DeepSparse의 처리량을 더 늘릴 수 있습니다.

배치 1에서 DeepSparse는 4블록 프루닝 정량화된 YOLOv5s로 초당 180개 항목을 달성하여 ONNX 런타임 대비 3.7배의 성능 향상을 달성했습니다 !

deepsparse.benchmark zoo:cv/detection/yolov5-s/pytorch/ultralytics/coco/pruned35_quant-none-vnni -s sync -b 1 -nstreams 1

> Original Model Path: zoo:cv/detection/yolov5-s/pytorch/ultralytics/coco/pruned35_quant-none-vnni
> Batch Size: 1
> Scenario: sync
> Throughput (items/sec): 179.7375

DeepSparse 시작하기

연구 또는 테스트? 딥스페이스 커뮤니티는 연구 및 테스트를 위해 무료로 제공됩니다. 문서에서 시작하세요.

📅 Created 11 months ago ✏️ Updated 29 days ago

댓글