Instructions to use jinaai/jina-clip-v2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use jinaai/jina-clip-v2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("feature-extraction", model="jinaai/jina-clip-v2", trust_remote_code=True)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("jinaai/jina-clip-v2", trust_remote_code=True, device_map="auto") - sentence-transformers
How to use jinaai/jina-clip-v2 with sentence-transformers:
from sentence_transformers import SentenceTransformer model = SentenceTransformer("jinaai/jina-clip-v2", trust_remote_code=True) sentences = [ "The weather is lovely today.", "It's so sunny outside!", "He drove to the stadium." ] embeddings = model.encode(sentences) similarities = model.similarity(embeddings, embeddings) print(similarities.shape) # [3, 3] - Transformers.js
How to use jinaai/jina-clip-v2 with Transformers.js:
// npm i @huggingface/transformers import { pipeline } from '@huggingface/transformers'; // Allocate pipeline const pipe = await pipeline('feature-extraction', 'jinaai/jina-clip-v2'); - Notebooks
- Google Colab
- Kaggle
onnx use pixel_values = np.random.rand(0, 3, 512, 512).astype(np.float32) will cause onnx warning
I saw in this discussion https://huggingface.co/jinaai/jina-clip-v2/discussions/12
that using pixel_values = np.random.rand(0, 3, 512, 512).astype(np.float32) can skip computing image vectors and only compute text vectors. However, this approach triggers many warnings. How can I avoid these warnings?
❯ ./main.py
2024-12-02 12:59:46.183221 [W:onnxruntime:, execution_frame.cc:651 AllocateMLValueTensorPreAllocateBuffer] Shape mismatch attempting to re-use buffer. {2,1024} != {0,1024}. Validate usage of dim_value (values should be > 0) and dim_param (all values with the same string should equate to the same size) in shapes in the model.
2024-12-02 12:59:46.183253 [W:onnxruntime:, execution_frame.cc:651 AllocateMLValueTensorPreAllocateBuffer] Shape mismatch attempting to re-use buffer. {2,1024} != {0,1024}. Validate usage of dim_value (values should be > 0) and dim_param (all values with the same string should equate to the same size) in shapes in the model.
2024-12-02 12:59:46.183259 [W:onnxruntime:, execution_frame.cc:651 AllocateMLValueTensorPreAllocateBuffer] Shape mismatch attempting to re-use buffer. {2,1} != {0,1}. Validate usage of dim_value (values should be > 0) and dim_param (all values with the same string should equate to the same size) in shapes in the model.
2024-12-02 12:59:46.183265 [W:onnxruntime:, execution_frame.cc:651 AllocateMLValueTensorPreAllocateBuffer] Shape mismatch attempting to re-use buffer. {2,1} != {0,1}. Validate usage of dim_value (values should be > 0) and dim_param (all values with the same string should equate to the same size) in shapes in the model.
2024-12-02 12:59:46.183302 [W:onnxruntime:, execution_frame.cc:651 AllocateMLValueTensorPreAllocateBuffer] Shape mismatch attempting to re-use buffer. {2,1} != {0,1}. Validate usage of dim_value (values should be > 0) and dim_param (all values with the same string should equate to the same size) in shapes in the model.
2024-12-02 12:59:46.183310 [W:onnxruntime:, execution_frame.cc:651 AllocateMLValueTensorPreAllocateBuffer] Shape mismatch attempting to re-use buffer. {2,1024} != {0,1024}. Validate usage of dim_value (values should be > 0) and dim_param (all values with the same string should equate to the same size) in shapes in the model.
2024-12-02 12:59:46.183317 [W:onnxruntime:, execution_frame.cc:651 AllocateMLValueTensorPreAllocateBuffer] Shape mismatch attempting to re-use buffer. {2,1024} != {0,1024}. Validate usage of dim_value (values should be > 0) and dim_param (all values with the same string should equate to the same size) in shapes in the model.
2024-12-02 12:59:46.183408 [W:onnxruntime:, execution_frame.cc:651 AllocateMLValueTensorPreAllocateBuffer] Shape mismatch attempting to re-use buffer. {2,1024} != {0,1024}. Validate usage of dim_value (values should be > 0) and dim_param (all values with the same string should equate to the same size) in shapes in the model.
text_embeddings [[ 0.01912099 0.0926741 -0.07058127 ... 0.00949061 -0.00961232
-0.00106417]
[ 0.02101001 0.06672169 -0.07842559 ... 0.0237933 -0.01988332
0.01268288]]
image_embeddings []
Hey, you can silence the warnings with https://onnxruntime.ai/docs/api/python/api_summary.html#onnxruntime.set_default_logger_severity. @Xenova anything we can do on the model side?
This appears to be a bug in onnxruntime, since the model is a valid ONNX model. Related: https://github.com/microsoft/onnxruntime-genai/issues/1098
Might be worth opening a separate issue though.
Hey, you can silence the warnings with https://onnxruntime.ai/docs/api/python/api_summary.html#onnxruntime.set_default_logger_severity. @Xenova anything we can do on the model side?
I think it can be divided into 2 onnx, one for pictures and one for text
Hey, you can silence the warnings with https://onnxruntime.ai/docs/api/python/api_summary.html#onnxruntime.set_default_logger_severity. @Xenova anything we can do on the model side?
I think it can be divided into 2 onnx, one for pictures and one for text
I did here: https://huggingface.co/satorean/jina-clip-v2-split-onnx
