The CLIP model was proposed in Learning Transferable Visual Models From Natural Language Supervision by Alec Radford, Jong Wook Kim, Chris Hallacy, Aditya Ramesh, Gabriel Goh,
CLIP
Overview
The CLIP model was proposed in Learning Transferable Visual Models From Natural Language Supervision by Alec Radford, Jong Wook Kim, Chris Hallacy, Aditya Ramesh, Gabriel Goh, Sandhini Agarwal, Girish Sastry, Amanda Askell, Pamela Mishkin, Jack Clark, Gretchen Krueger, Ilya Sutskever. CLIP (Contrastive Language-Image Pre-Training) is a neural network trained on a variety of (image, text) pairs. It can be instructed in natural language to predict the most relevant text snippet, given an image, without directly optimizing for the task, similarly to the zero-shot capabilities of GPT-2 and 3.
Export to Neuron
To deploy 🤗 Transformers models on Neuron devices, you first need to compile the models and export them to a serialized format for inference. Below are two approaches to compile the model, you can choose the one that best suits your needs. Here we take the feature-extraction as an example:
Option 1: CLI
You can export the model using the Optimum command-line interface as follows:
optimum-cli export neuron --model openai/clip-vit-base-patch32 --task feature-extraction --text_batch_size 2 --sequence_length 77 --image_batch_size 1 --num_channels 3 --width 224 --height 224 clip_feature_extraction_neuronx/
Tip Execute
optimum-cli export neuron --helpto display all command line options and their description.
Option 2: Python API
from optimum.neuron import NeuronCLIPModel
input_shapes = {"text_batch_size": 2, "sequence_length": 77, "image_batch_size": 1, "num_channels": 3, "width": 224, "height": 224}
compiler_args = {"auto_cast": "matmul", "auto_cast_type": "bf16"}
neuron_model = NeuronCLIPModel.from_pretrained(
"openai/clip-vit-base-patch32",
export=True,
**input_shapes,
**compiler_args,
)
# Save locally
neuron_model.save_pretrained("clip_feature_extraction_neuronx/")
# Upload to the HuggingFace Hub
neuron_model.push_to_hub(
"clip_feature_extraction_neuronx/", repository_id="optimum/clip-vit-base-patch32-neuronx" # Replace with your HF Hub repo id
)
NeuronCLIPModel
[[autodoc]] models.inference.clip.NeuronCLIPModel
NeuronCLIPForImageClassification
[[autodoc]] models.inference.clip.NeuronCLIPForImageClassification
Source and license
Source: AWS Trainium & Inferentia documentation, adapted for this site. Licensing and attribution follow the terms of the upstream project.