Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DeepSparse backend for CLIP inference #323

Merged
merged 8 commits into from
Jan 6, 2024

Conversation

mgoin
Copy link
Contributor

@mgoin mgoin commented Jan 3, 2024

DeepSparse is an inference runtime for fast sparse model inference on CPUs.
There is a backend available within clip-retrieval by installing it with pip install deepsparse-nightly[clip], and specifying a clip_model with a prepended "nm:", such as "nm:neuralmagic/CLIP-ViT-B-32-256x256-DataComp-s34B-b86K-quant-ds" or "nm:mgoin/CLIP-ViT-B-32-laion2b_s34b_b79k-ds".

Install

git clone https://github.com/mgoin/clip-retrieval
cd clip-retrieval 
git checkout deepsparse-clip-backend 
pip install -e . 
pip install "deepsparse-nightly[clip]"

Setup some example images

pip install img2dataset
echo 'https://placekitten.com/200/305' >> myimglist.txt
echo 'https://placekitten.com/200/304' >> myimglist.txt
echo 'https://placekitten.com/200/303' >> myimglist.txt
img2dataset --url_list=myimglist.txt --output_folder=image_folder --thread_count=64 --image_size=256

Inference!

clip-retrieval inference --batch_size 4 --clip_model=nm:neuralmagic/CLIP-ViT-B-32-256x256-DataComp-s34B-b86K-quant-ds --input_dataset image_folder --output_folder embeddings_folder
The number of samples has been estimated to be 3
Starting the worker
dataset is 12
Starting work on task 0
Fetching 7 files: 100%|███████████████████████████████████████████████████████████████████████████████████| 7/7 [00:00<00:00, 61422.86it/s]
DeepSparse, Copyright 2021-present / Neuralmagic, Inc. version: 1.7.0.20231210 COMMUNITY | (99472380) (release) (optimized) (system=avx512_vnni, binary=avx512)
warming up with batch size 4 on cpu
done warming up in 0.5746381282806396s
 sample_per_sec 0 ; sample_count 3 

@rom1504 rom1504 force-pushed the deepsparse-clip-backend branch 2 times, most recently from 6c8e769 to 9711b9e Compare January 6, 2024 22:53
@rom1504 rom1504 merged commit 36a4060 into rom1504:main Jan 6, 2024
6 checks passed
@rom1504
Copy link
Owner

rom1504 commented Jan 6, 2024

would be great to do more benchmarks with this and add them to the readme

@rom1504
Copy link
Owner

rom1504 commented Jan 6, 2024

thanks for the pr!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants