Package: deepsparse-ent
DeepSparseSparsity-aware deep learning inference runtime for CPUsDeepSparseis a CPU inference runtime that takes advantage of sparsity to accelerate neural network inference. Coupled withSparseML, our optimization library for pruning and quantizing your models, DeepSparse delivers exceptional inference performance on CPU hardware.✨NEW✨ DeepSparse LLMsNeural Magic is excited to announce initial support for performant LLM inference in DeepSparse with:sparse kernels for speedups and memory savings from unstructured sparse weights.8-bit weight and activation quantization support.efficient usage of cached attention keys and values for minimal memory movement.Try It NowInstall (requires Linux):pipinstall-Udeepsparse-nightly[llm]Run inference:fromdeepsparseimportTextGenerationpipeline=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:"""print(pipeline(prompt,max_new_tokens=75).generations[0].text)# Sparsity is the property of a matrix or other data structure in which a large number of elements are zero and a smaller number of elements are non-zero. In the context of machine learning, sparsity can be used to improve the efficiency of training and prediction.Check out theTextGenerationdocumentation for usage details.Sparsity :handshake: PerformanceDeveloped in collaboration with IST Austria,our recent paperdetails a new technique calledSparse Fine-Tuning, which allows us to prune MPT-7B to 60% sparsity during fine-tuning without drop in accuracy. With our new support for LLMs, DeepSparse accelerates the sparse-quantized model 7x over the dense baseline:Learn more about our Sparse Fine-Tuning research.Check out the model running live on Hugging Face.LLM RoadmapFollowing this initial launch, we are rapidly expanding our support for LLMs, including:Productizing Sparse Fine-Tuning: Enable external users to apply sparse fine-tuning to their datasets via SparseML.Expanding model support: Apply our sparse fine-tuning results to Llama 2 and Mistral models.Pushing for higher sparsity: Improving our pruning algorithms to reach even higher sparsity.Computer Vision and NLP ModelsIn addition to LLMs, DeepSparse supports many variants of CNNs and Transformer models, such as BERT, ViT, ResNet, EfficientNet, YOLOv5/8, and many more! Take a look at theComputer VisionandNatural Language Processingdomains ofSparseZoo, our home for optimized models.InstallationInstall viaPyPI(optional dependencies detailed here):pipinstalldeepsparseTo experiment with the latest features, there is a nightly build available usingpip install deepsparse-nightlyor you can clone and install from source usingpip install -e path/to/deepsparse.System RequirementsHardware:x86 AVX2, AVX-512, AVX-512 VNNI and ARM v8.2+Operating System: LinuxPython: 3.8-3.11ONNX versions 1.5.0-1.15.0, ONNX opset version 11 or higherFor those using Mac or Windows, we recommend using Linux containers with Docker.Deployment APIsDeepSparse includes three deployment APIs:Engineis the lowest-level API. With Engine, you compile an ONNX model, pass tensors as input, and receive the raw outputs.Pipelinewraps the Engine with pre- and post-processing. With Pipeline, you pass raw data and receive the prediction.Serverwraps Pipelines with a REST API using FastAPI. With Server, you send raw data over HTTP and receive the prediction.EngineThe example below downloads a 90% pruned-quantized BERT model for sentiment analysis in ONNX format from SparseZoo, compiles the model, and runs inference on randomly generated input. Users can provide their own ONNX models, whether dense or sparse.fromdeepsparseimportEngine# download onnx, compilezoo_stub="zoo:nlp/sentiment_analysis/obert-base/pytorch/huggingface/sst2/pruned90_quant-none"compiled_model=Engine(model=zoo_stub,batch_size=1)# run inference (input is raw numpy tensors, output is raw scores)inputs=compiled_model.generate_random_inputs()output=compiled_model(inputs)print(output)# > [array([[-0.3380675 ,  0.09602544]], dtype=float32)] << raw scoresPipelinePipelines wrap Engine with pre- and post-processing, enabling you to pass raw data and receive the post-processed prediction. The example below downloads a 90% pruned-quantized BERT model for sentiment analysis in ONNX format from SparseZoo, sets up a pipeline, and runs inference on sample data.fromdeepsparseimportPipeline# download onnx, set up pipelinezoo_stub="zoo:nlp/sentiment_analysis/obert-base/pytorch/huggingface/sst2/pruned90_quant-none"sentiment_analysis_pipeline=Pipeline.create(task="sentiment-analysis",# name of the taskmodel_path=zoo_stub,# zoo stub or path to local onnx file)# run inference (input is a sentence, output is the prediction)prediction=sentiment_analysis_pipeline("I love using DeepSparse Pipelines")print(prediction)# > labels=['positive'] scores=[0.9954759478569031]ServerServer wraps Pipelines with REST APIs, enabling you to set up a model-serving endpoint running DeepSparse. This enables you to send raw data to DeepSparse over HTTP and receive the post-processed predictions. DeepSparse Server is launched from the command line and configured via arguments or a server configuration file. The following downloads a 90% pruned-quantized BERT model for sentiment analysis in ONNX format from SparseZoo and launches a sentiment analysis endpoint:deepsparse.server\--tasksentiment-analysis\--model_pathzoo:nlp/sentiment_analysis/obert-base/pytorch/huggingface/sst2/pruned90_quant-noneSending a request:importrequestsurl="http://localhost:5543/v2/models/sentiment_analysis/infer"# Server's port default to 5543obj={"sequences":"Snorlax loves my Tesla!"}response=requests.post(url,json=obj)print(response.text)# {"labels":["positive"],"scores":[0.9965094327926636]}Additional ResourcesUse Cases Pagefor more details on supported tasksPipelines User Guidefor Pipeline documentationServer User Guidefor Server documentationBenchmarking User Guidefor benchmarking documentationCloud Deployments and DemosUser Guidefor more detailed documentationProduct Usage AnalyticsDeepSparse gathers basic usage telemetry, including, but not limited to, Invocations, Package, Version, and IP Address, for Product Usage Analytics purposes. Review Neural Magic'sProducts Privacy Policyfor further details on how we process this data.To disable Product Usage Analytics, run:exportNM_DISABLE_ANALYTICS=TrueConfirm that telemetry is shut off through info logs streamed with engine invocation by looking for the phrase "Skipping Neural Magic's latest package version check."CommunityGet In TouchContribution GuideCommunity SlackGitHub Issue QueueSubscribe To Our NewsletterBlogFor more general questions about Neural Magic,complete this form.LicenseDeepSparse Communityis licensed under theNeural Magic DeepSparse Community License.Some source code, example files, and scripts included in the DeepSparse GitHub repository or directory are licensed under theApache License Version 2.0as noted.DeepSparse Enterpriserequires a Trial License orcan be fully licensedfor production, commercial applications.CiteFind this project useful in your research or other communications? Please consider citing:@misc{kurtic2023sparse,title={Sparse Fine-Tuning for Inference Acceleration of Large Language Models},author={Eldar Kurtic and Denis Kuznedelev and Elias Frantar and Michael Goin and Dan Alistarh},year={2023},url={https://arxiv.org/abs/2310.06927},eprint={2310.06927},archivePrefix={arXiv},primaryClass={cs.CL}}@misc{kurtic2022optimal,title={The Optimal BERT Surgeon: Scalable and Accurate Second-Order Pruning for Large Language Models},author={Eldar Kurtic and Daniel Campos and Tuan Nguyen and Elias Frantar and Mark Kurtz and Benjamin Fineran and Michael Goin and Dan Alistarh},year={2022},url={https://arxiv.org/abs/2203.07259},eprint={2203.07259},archivePrefix={arXiv},primaryClass={cs.CL}}@InProceedings{pmlr-v119-kurtz20a,title={Inducing and Exploiting Activation Sparsity for Fast Inference on Deep Neural Networks},author={Kurtz, Mark and Kopinsky, Justin and Gelashvili, Rati and Matveev, Alexander and Carr, John and Goin, Michael and Leiserson, William and Moore, Sage and Nell, Bill and Shavit, Nir and Alistarh, Dan},booktitle={Proceedings of the 37th International Conference on Machine Learning},pages={5533--5543},year={2020},editor={Hal Daumé III and Aarti Singh},volume={119},series={Proceedings of Machine Learning Research},address={Virtual},month={13--18 Jul},publisher={PMLR},pdf={http://proceedings.mlr.press/v119/kurtz20a/kurtz20a.pdf},url={http://proceedings.mlr.press/v119/kurtz20a.html}}@article{DBLP:journals/corr/abs-2111-13445,author={Eugenia Iofinova and Alexandra Peste and Mark Kurtz and Dan Alistarh},title={How Well Do Sparse Imagenet Models Transfer?},journal={CoRR},volume={abs/2111.13445},year={2021},url={https://arxiv.org/abs/2111.13445},eprinttype={arXiv},eprint={2111.13445},timestamp={Wed, 01 Dec 2021 15:16:43 +0100},biburl={https://dblp.org/rec/journals/corr/abs-2111-13445.bib},bibsource={dblp computer science bibliography, https://dblp.org}}