DeepSparseは、Neural Magicによって開発された革新的なCPU推論ランタイムであり、ニューラルネットワークのスパース性を活用して深層学習モデルの推論プロセスを高速化するために特別に設計されています。このプロジェクトは、SparseML最適化ライブラリと組み合わせることで、CPUハードウェア上で優れた推論性能を実現します。
重要なお知らせ: 2025年1月、Neural MagicはRed Hatに買収されました。DeepSparseコミュニティ版は2025年6月2日にメンテナンスを終了し、廃止されます。チームはvLLMベースの商用およびオープンソースソリューションに移行します。
DeepSparseは、大規模言語モデルの推論に対して初期サポートを提供します。
注意:MacおよびWindowsユーザーはDocker Linuxコンテナの使用を推奨します
pip install deepsparse
pip install deepsparse-nightly
pip install -U deepsparse-nightly[llm]
pip install -e path/to/deepsparse
最も低いレベルのAPIで、ONNXモデルを直接コンパイルし、テンソルの入出力を処理します。
from deepsparse import Engine
# モデルをダウンロードしてコンパイル
zoo_stub = "zoo:nlp/sentiment_analysis/obert-base/pytorch/huggingface/sst2/pruned90_quant-none"
compiled_model = Engine(model=zoo_stub, batch_size=1)
# 推論を実行
inputs = compiled_model.generate_random_inputs()
output = compiled_model(inputs)
Engineをラップし、前処理と後処理機能を追加して、生のデータを直接処理できます。
from deepsparse import Pipeline
# パイプラインを設定
sentiment_analysis_pipeline = Pipeline.create(
task="sentiment-analysis",
model_path="zoo:nlp/sentiment_analysis/obert-base/pytorch/huggingface/sst2/pruned90_quant-none"
)
# 推論を実行
prediction = sentiment_analysis_pipeline("I love using DeepSparse Pipelines")
print(prediction)
# 出力: labels=['positive'] scores=[0.9954759478569031]
FastAPIに基づいてPipelineをラップし、REST APIサービスを提供します。
# サーバーを起動
deepsparse.server \
--task sentiment-analysis \
--model_path zoo:nlp/sentiment_analysis/obert-base/pytorch/huggingface/sst2/pruned90_quant-none
# リクエストを送信
import requests
url = "http://localhost:5543/v2/models/sentiment_analysis/infer"
obj = {"sequences": "Snorlax loves my Tesla!"}
response = requests.post(url, json=obj)
print(response.text)
# 出力: {"labels":["positive"],"scores":[0.9965094327926636]}
from deepsparse import TextGeneration
pipeline = TextGeneration(model="zoo:mpt-7b-dolly_mpt_pretrain-pruned50_quantized")
prompt = """
Below is an instruction that describes a task. Write a response that appropriately completes the request.
### Instruction: what is sparsity?
### Response:
"""
result = pipeline(prompt, max_new_tokens=75)
print(result.generations[0].text)
DeepSparseは、製品の使用状況分析のために基本的な使用状況テレメトリデータを収集します。ユーザーは、環境変数を設定することで無効にできます。
export NM_DISABLE_ANALYTICS=True
このプロジェクトは、以下の重要な学術論文に基づいています。
DeepSparseは、CPU推論最適化分野における大きなブレークスルーであり、革新的なスパース性利用技術を通じて、通常のCPUハードウェア上で前例のない深層学習推論性能を実現します。コミュニティ版はまもなくメンテナンスを終了しますが、その技術革新と理念はRed Hatのサポートの下で発展を続け、AI推論最適化分野にさらに貢献します。