Resume hlip backup excluding two local secret files (part 2)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +3 -0
- hlip/open_clip/docs/clip_zeroshot.png +3 -0
- hlip/open_clip/docs/clipa.md +103 -0
- hlip/open_clip/docs/clipa_acc_compute.png +3 -0
- hlip/open_clip/docs/clipa_reduce_image_token.png +3 -0
- hlip/open_clip/docs/clipa_reduce_text_token.png +3 -0
- hlip/open_clip/docs/datacomp_models.md +69 -0
- hlip/open_clip/docs/effective_robustness.png +3 -0
- hlip/open_clip/docs/inverse_scaling_law.png +3 -0
- hlip/open_clip/docs/laion2b_clip_zeroshot_b32.png +3 -0
- hlip/open_clip/docs/laion_clip_zeroshot.png +3 -0
- hlip/open_clip/docs/laion_clip_zeroshot_b16.png +3 -0
- hlip/open_clip/docs/laion_clip_zeroshot_b16_plus_240.png +3 -0
- hlip/open_clip/docs/laion_clip_zeroshot_l14.png +3 -0
- hlip/open_clip/docs/laion_openai_compare_b32.jpg +3 -0
- hlip/open_clip/docs/model_profile.csv +86 -0
- hlip/open_clip/docs/openclip_classification_results.csv +122 -0
- hlip/open_clip/docs/openclip_multilingual_retrieval_results.csv +0 -0
- hlip/open_clip/docs/openclip_results.csv +122 -0
- hlip/open_clip/docs/openclip_retrieval_results.csv +122 -0
- hlip/open_clip/docs/scaling.png +3 -0
- hlip/open_clip/docs/script_examples/clipa/vit_b16/i50_t16_finetune.sh +27 -0
- hlip/open_clip/docs/script_examples/clipa/vit_b16/i50_t16_pretrain.sh +26 -0
- hlip/open_clip/docs/script_examples/clipa/vit_l16/i17_t16_finetune.sh +27 -0
- hlip/open_clip/docs/script_examples/clipa/vit_l16/i17_t16_pretrain.sh +26 -0
- hlip/open_clip/docs/script_examples/clipa/vit_l16/i37_t8_finetune.sh +27 -0
- hlip/open_clip/docs/script_examples/clipa/vit_l16/i37_t8_pretrain.sh +26 -0
- hlip/open_clip/docs/script_examples/clipav2/vit_h14/i257_t32_finetunex4.sh +32 -0
- hlip/open_clip/docs/script_examples/clipav2/vit_h14/i50_t8_pretrain.sh +30 -0
- hlip/open_clip/docs/script_examples/clipav2/vit_h14/i577_t32_finetunex1.sh +32 -0
- hlip/open_clip/docs/script_examples/stability_example.sh +60 -0
- hlip/open_clip/pyproject.toml +79 -0
- hlip/open_clip/pytest.ini +3 -0
- hlip/open_clip/requirements-test.txt +4 -0
- hlip/open_clip/requirements-training.txt +13 -0
- hlip/open_clip/requirements.txt +8 -0
- hlip/open_clip/scripts/clipav1_vit_l16_i37_t8.sh +6 -0
- hlip/open_clip/scripts/clipav2_vit_h14_i84_224_336_cl32_gap_datacomp1b.sh +10 -0
- hlip/open_clip/scripts/h14_224_32_finetune.sh +31 -0
- hlip/open_clip/scripts/h14_84_8_pretrain.sh +31 -0
- hlip/open_clip/src/open_clip/__init__.py +18 -0
- hlip/open_clip/src/open_clip/bpe_simple_vocab_16e6.txt.gz +3 -0
- hlip/open_clip/src/open_clip/coca_model.py +582 -0
- hlip/open_clip/src/open_clip/constants.py +11 -0
- hlip/open_clip/src/open_clip/convert.py +206 -0
- hlip/open_clip/src/open_clip/factory.py +1108 -0
- hlip/open_clip/src/open_clip/hf_configs.py +67 -0
- hlip/open_clip/src/open_clip/hf_model.py +193 -0
- hlip/open_clip/src/open_clip/loss.py +464 -0
- hlip/open_clip/src/open_clip/model.py +892 -0
.gitattributes
CHANGED
|
@@ -67,3 +67,6 @@ hlip/hlip/data/ct_rate/metafiles/train_metadata.csv filter=lfs diff=lfs merge=lf
|
|
| 67 |
hlip/hlip/data/ct_rate/metafiles/train_reports.csv filter=lfs diff=lfs merge=lfs -text
|
| 68 |
hlip/hlip/data/rad_chestct/metafiles/imgtrain_Abnormality_and_Location_Labels.csv filter=lfs diff=lfs merge=lfs -text
|
| 69 |
hlip/hlip/data/rad_chestct/metafiles/imgvalid_Abnormality_and_Location_Labels.csv filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
hlip/hlip/data/ct_rate/metafiles/train_reports.csv filter=lfs diff=lfs merge=lfs -text
|
| 68 |
hlip/hlip/data/rad_chestct/metafiles/imgtrain_Abnormality_and_Location_Labels.csv filter=lfs diff=lfs merge=lfs -text
|
| 69 |
hlip/hlip/data/rad_chestct/metafiles/imgvalid_Abnormality_and_Location_Labels.csv filter=lfs diff=lfs merge=lfs -text
|
| 70 |
+
hlip/selected_10k_reports.csv filter=lfs diff=lfs merge=lfs -text
|
| 71 |
+
hlip/train_metadata.csv filter=lfs diff=lfs merge=lfs -text
|
| 72 |
+
hlip/train_reports.csv filter=lfs diff=lfs merge=lfs -text
|
hlip/open_clip/docs/clip_zeroshot.png
ADDED
|
Git LFS Details
|
hlip/open_clip/docs/clipa.md
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
## CLIPA
|
| 2 |
+
|
| 3 |
+
In this work, we present a surprising finding that there exists an _inverse_ scaling law for CLIP training,
|
| 4 |
+
whereby the larger the image/text encoders used, the shorter the sequence length of image/text tokens that can be applied in training.
|
| 5 |
+
Moreover, we showcase that the strategy for reducing image/text token length plays a crucial role in determining the quality of this scaling law.
|
| 6 |
+
|
| 7 |
+

|
| 8 |
+
|
| 9 |
+
As a result of this finding, we are able to successfully train CLIP even by using academic resources.
|
| 10 |
+
For example, on an A100 eight-GPU server, our CLIP models achieve zero-shot top-1 ImageNet accuracies of **63.2%** in about **2 days**,
|
| 11 |
+
**67.8%** in about **3 days**, and **69.3%** in about **4 days**.
|
| 12 |
+
|
| 13 |
+
Moreover, We find that CLIPA at scale leads to state-of-the-art performance. For example, our CLIPA-v2 H/14 achieves a zero-shot top-1 ImageNet accuracy of **81.8%**,
|
| 14 |
+
with a budget less than **$15000**.
|
| 15 |
+
|
| 16 |
+

|
| 17 |
+
|
| 18 |
+
For more details, please see our paper [An Inverse Scaling Law for CLIP Training](https://arxiv.org/abs/2305.07017) and
|
| 19 |
+
[CLIPA-v2: Scaling CLIP Training with 81.1% Zero-shot ImageNet Accuracy within a $10,000 Budget; An Extra $4,000 Unlocks 81.8% Accuracy](https://arxiv.org/abs/2306.15658).
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
Eight token length reduction strategies are investigated in this work, detailed as follows.
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
## Image token length reduction
|
| 26 |
+
|
| 27 |
+

|
| 28 |
+
|
| 29 |
+
* `resize`: use `--force-image-size` to specify the image size you want to adopt. We find this strategy generally works the best as it retains full image information.
|
| 30 |
+
|
| 31 |
+
* `random mask`: Randomly mask out image patches. use `--force-patch-dropout` to specify the mask ratio you want to adopt.
|
| 32 |
+
|
| 33 |
+
* `grid mask`: Preserve one patch in each 2 × 2 grid window. We do not provide implementation for grid masking, as it is only experimental and we generally find resizing works better.
|
| 34 |
+
|
| 35 |
+
* `block mask`: Keep a single block and remove other patches. We do not provide implementation for block masking, as it is only experimental and we generally find resizing works better.
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
## Text token length reduction
|
| 39 |
+
|
| 40 |
+
* `syntax mask`: Assign different masking priorities to parts of speech. Specify `"text_mask": syntax` in `"tokenizer_kwargs"` in `"text_cfg"` of model config `json` file to use.
|
| 41 |
+
Specifically, we prioritize retaining nouns, followed by adjectives, and then other words.
|
| 42 |
+
We find this strategy generally works the best as it retains critical information for contrastive learning.
|
| 43 |
+
|
| 44 |
+
* `truncate`: Truncation selects the first N text tokens and discards the rest. This is the default setting of `open_clip`.
|
| 45 |
+
|
| 46 |
+
* `random mask`: Randomly drops a portion of the text tokens. Specify `"text_mask": random` in `"tokenizer_kwargs"` in `"text_cfg"` of model config `json` file to use.
|
| 47 |
+
|
| 48 |
+
* `block mask`: Randomly preserves consecutive text sequences. Specify `"text_mask": block` in `"tokenizer_kwargs"` in `"text_cfg"` of model config `json` file to use.
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
## Installation
|
| 52 |
+
|
| 53 |
+
The installation is really the same as `open_clip`, except for the usage of Natural Language Toolkit (NLTK) in `syntax mask` of text token length reduction.
|
| 54 |
+
Please follow the [official doc](https://www.nltk.org/) to install NLTK.
|
| 55 |
+
|
| 56 |
+
Note that the the usage of NLTK brings two constraints:
|
| 57 |
+
* Because certain functions like `nltk.pos_tag` from NLTK only support English and Russian for now, the `syntax mask` only works for English.
|
| 58 |
+
we have not tested it on Russian or any other language. Theoretically, it should work the same, given a proper language processing toolkit for other languages.
|
| 59 |
+
If you still want to apply `syntax mask` on other languages, try finding the right toolkit. Otherwise, use other text token length reduction strategies
|
| 60 |
+
* some modules of NLTK like `punkt` or `averaged_perceptron_tagger` need to be downloaded first before using NLTK.
|
| 61 |
+
We have included the downloading code in `tokenizer.py`, but this might cause trouble in certain cases.
|
| 62 |
+
You may want to manually download those modules first, by `nltk.download('punkt')` and `nltk.download('averaged_perceptron_tagger')`,
|
| 63 |
+
and then setup the environmental variable before running the script `export NLTK_DATA=cache`.
|
| 64 |
+
Note that this is a one-time effort. Remember to comment out those `nltk.download` lines in `tokenizer.py` afterwards.
|
| 65 |
+
|
| 66 |
+
## Training
|
| 67 |
+
We provide example scripts to reproduce our CLIPA results on an A100 eight-GPU machine under path `docs/script_examples/clipa`.
|
| 68 |
+
|
| 69 |
+
For instance, to reproduce the CLIPA-L16(I37,T8) results, first run the pre-training script
|
| 70 |
+
```
|
| 71 |
+
bash docs/script_examples/clipa/vit_l16/i37_t8_pretrain.sh
|
| 72 |
+
```
|
| 73 |
+
and fine-tune the pre-trained checkpoint with
|
| 74 |
+
```
|
| 75 |
+
bash docs/script_examples/clipa/vit_l16/i37_t8_finetune.sh
|
| 76 |
+
```
|
| 77 |
+
- Remember to change the path to dataset to your own path.
|
| 78 |
+
- This is a two-stage training pipeline. Remember to change the path to pre-trained checkpoint to your own when fine-tuning.
|
| 79 |
+
- The training time is ~3 days for pre-training and ~1 day for fine-tuning on an A100 eight-GPU machine.
|
| 80 |
+
|
| 81 |
+
## Model Weights
|
| 82 |
+
Below are CLIPA trained weights on LAION-400M with an A100 eight-GPU machine.
|
| 83 |
+
All models are pre-trained for 6 epochs with reduced input token lengths and subsequently fine-tuned for 0.36 epoch with full input token lengths.
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
| | Pre-trained Weights | zero-shot IN-1K |
|
| 87 |
+
|---------------------|:----------------------------------------------------------------------------------------------:|:---------------:|
|
| 88 |
+
| CLIPA-B/16(I50,T16) | [download](https://drive.google.com/file/d/1MDpz8gV2Vjaazk16rBhLxU8811U7_cGL/view?usp=sharing) | 59.7 |
|
| 89 |
+
| CLIPA-L/16(I17,T16) | [download](https://drive.google.com/file/d/1Tr2GYiKAaMH6EGIn5l7eX_1K20eaA3WA/view?usp=sharing) | 60.3 |
|
| 90 |
+
| CLIPA_L/16(I37,T8) | [download](https://drive.google.com/file/d/1EM1ChRNARpLckkJjf6m7njCY3xyvpGBu/view?usp=sharing) | 57.9 |
|
| 91 |
+
|
| 92 |
+
| | Fine-tuned Weights | zero-shot IN-1K |
|
| 93 |
+
|---------------------|:----------------------------------------------------------------------------------------------:|:-----:|
|
| 94 |
+
| CLIPA-B/16(I50,T16) | [download](https://drive.google.com/file/d/1fURK0K_a3-83jVEI4PVEbnEJb_V6UbGv/view?usp=sharing) | 63.2 |
|
| 95 |
+
| CLIPA-L/16(I17,T16) | [download](https://drive.google.com/file/d/18qqZGOTGOgb3I3JWONuat6qObsgLq7sR/view?usp=sharing) | 67.8 |
|
| 96 |
+
| CLIPA_L/16(I37,T8) | [download](https://drive.google.com/file/d/1lV7pLORUK04T9QKKx9TpYtMws-AZrib0/view?usp=sharing) | 69.3 |
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
## CLIPA-v2
|
| 100 |
+
We also provide example scripts to reproduce our CLIPA-v2 H/14 results under path `docs/script_examples/clipav2`.
|
| 101 |
+
Note that the original results are obtained with [our JAX implementation](https://github.com/UCSC-VLAA/CLIPA/tree/master/clipa_jax).
|
| 102 |
+
These scripts are written after manually scanning the JAX config files.
|
| 103 |
+
As it is infeasible for us to retrain those models again with pytorch, its correctness cannot be verified with 100% confidence. Use them at your own discretion.
|
hlip/open_clip/docs/clipa_acc_compute.png
ADDED
|
Git LFS Details
|
hlip/open_clip/docs/clipa_reduce_image_token.png
ADDED
|
Git LFS Details
|
hlip/open_clip/docs/clipa_reduce_text_token.png
ADDED
|
Git LFS Details
|
hlip/open_clip/docs/datacomp_models.md
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
## CommonPool and DataComp models
|
| 2 |
+
|
| 3 |
+
As part of [DataComp](https://github.com/mlfoundations/datacomp), we trained models on CommonPool using various data filtering strategies.
|
| 4 |
+
We release models for all four scales of the competition, small, medium, large and xlarge, corresponding to a pool size and number of samples seen of 12.8M, 128M, 1.28B and 12.8B, respectively.
|
| 5 |
+
|
| 6 |
+
The models are specified below, see our paper [DataComp: In seearch of the next generation of multimodal datasets](https://arxiv.org/abs/2304.14108) for more details.
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
## xlarge scale models
|
| 10 |
+
|
| 11 |
+
* `datacomp_xl_s13b_b90k`: A ViT-L/14 trained on DataComp-1B for 12.8B steps and batch size 90k. Achieves 79.2% zero-shot accuracy on ImageNet. Available at https://huggingface.co/laion/CLIP-ViT-L-14-DataComp.XL-s13B-b90K.
|
| 12 |
+
|
| 13 |
+
* `commonpool_xl_clip_s13b_b90k`: A ViT-L/14 trained on CommonPool-XL filtered using CLIP scores, for 12.8B steps and batch size 90k. Achieves 76.4% zero-shot accuracy on ImageNet. Available at https://huggingface.co/laion/CLIP-ViT-L-14-CommonPool.XL.clip-s13B-b90K.
|
| 14 |
+
|
| 15 |
+
* `commonpool_xl_laion_s13b_b90k`: A ViT-L/14 trained on CommonPool-XL filtered using the LAION-2B filtering scheme, for 12.8B steps and batch size 90k. Achieves 75.5% zero-shot accuracy on ImageNet. Available at https://huggingface.co/laion/CLIP-ViT-L-14-CommonPool.XL.laion-s13B-b90K.
|
| 16 |
+
|
| 17 |
+
* `commonpool_xl_s13b_b90k`: A ViT-L/14 trained on CommonPool-XL without any filtering, for 12.8B steps and batch size 90k. Achieves 72.3% zero-shot accuracy on ImageNet. Available at https://huggingface.co/laion/CLIP-ViT-L-14-CommonPool.XL-s13B-b90K.
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
## large scale models
|
| 21 |
+
|
| 22 |
+
* `datacomp_l_s1b_b8k`: A ViT-B/16 trained on a 140M subset of DataComp-1B, for 1.28B steps and batch size 8k. Achieves 63.1% zero-shot accuracy on ImageNet. Available at https://huggingface.co/laion/CLIP-ViT-B-16-DataComp.L-s1B-b8K.
|
| 23 |
+
|
| 24 |
+
* `commonpool_l_clip_s1b_b8k`: A ViT-B/16 trained on CommonPool-L filtered using CLIP scores, for 1.28B steps and batch size 8k. Achieves 57.8% zero-shot accuracy on ImageNet. Available at https://huggingface.co/laion/CLIP-ViT-B-16-CommonPool.L.clip-s1B-b8K.
|
| 25 |
+
|
| 26 |
+
* `commonpool_l_laion_s1b_b8k`: A ViT-B/16 trained on CommonPool-L filtered using the LAION-2B filtering scheme, for 1.28B steps and batch size 8k. Achieves 55.3% zero-shot accuracy on ImageNet. Available at https://huggingface.co/laion/CLIP-ViT-B-16-CommonPool.L.laion-s1B-b8K.
|
| 27 |
+
|
| 28 |
+
* `commonpool_l_image_s1b_b8k`: A ViT-B/16 trained on CommonPool-L filtered using image-based filtering, for 1.28B steps and batch size 8k. Achieves 57.2% zero-shot accuracy on ImageNet. Available at https://huggingface.co/laion/CLIP-ViT-B-16-CommonPool.L.image-s1B-b8K.
|
| 29 |
+
|
| 30 |
+
* `commonpool_l_text_s1b_b8k`: A ViT-B/16 trained on CommonPool-L filtered using text-based filtering, for 1.28B steps and batch size 8k. Achieves 56.1% zero-shot accuracy on ImageNet. Available at https://huggingface.co/laion/CLIP-ViT-B-16-CommonPool.L.text-s1B-b8K.
|
| 31 |
+
|
| 32 |
+
* `commonpool_l_basic_s1b_b8k`: A ViT-B/16 trained on CommonPool-L filtered using basic filtering (English filtering + caption length and image size filtering), for 1.28B steps and batch size 8k. Achieves 51.6% zero-shot accuracy on ImageNet. Available at https://huggingface.co/laion/CLIP-ViT-B-16-CommonPool.L.basic-s1B-b8K.
|
| 33 |
+
|
| 34 |
+
* `commonpool_l_s1b_b8k`: A ViT-B/16 trained on CommonPool-L without any filtering, for 1.28B steps and batch size 8k. Achieves 45.9% zero-shot accuracy on ImageNet. Available at https://huggingface.co/laion/CLIP-ViT-B-16-CommonPool.L-s1B-b8K.
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
## medium scale models
|
| 38 |
+
|
| 39 |
+
* `datacomp_m_s128m_b4k`: A ViT-B/32 trained on a 14M subset of DataComp-1B, for 128M steps and batch size 4k. Achieves 29.7% zero-shot accuracy on ImageNet. Available at https://huggingface.co/laion/CLIP-ViT-B-32-DataComp.M-s128M-b4K.
|
| 40 |
+
|
| 41 |
+
* `commonpool_m_clip_s128m_b4k`: A ViT-B/32 trained on CommonPool-M filtered using CLIP scores, for 128M steps and batch size 4k. Achieves 27.3% zero-shot accuracy on ImageNet. Available at https://huggingface.co/laion/CLIP-ViT-B-32-CommonPool.M.clip-s128M-b4K.
|
| 42 |
+
|
| 43 |
+
* `commonpool_m_laion_s128m_b4k`: A ViT-B/32 trained on CommonPool-M filtered using the LAION-2B filtering scheme, for 128M steps and batch size 4k. Achieves 23.0% zero-shot accuracy on ImageNet. Available at https://huggingface.co/laion/CLIP-ViT-B-32-CommonPool.M.laion-s128M-b4K.
|
| 44 |
+
|
| 45 |
+
* `commonpool_m_image_s128m_b4k`: A ViT-B/32 trained on CommonPool-M filtered using image-based filtering, for 128M steps and batch size 4k. Achieves 26.8% zero-shot accuracy on ImageNet. Available at https://huggingface.co/laion/CLIP-ViT-B-32-CommonPool.M.image-s128M-b4K.
|
| 46 |
+
|
| 47 |
+
* `commonpool_m_text_s128m_b4k`: A ViT-B/32 trained on CommonPool-M filtered using text-based filtering, for 128M steps and batch size 4k. Achieves 25.5% zero-shot accuracy on ImageNet. Available at https://huggingface.co/laion/CLIP-ViT-B-32-CommonPool.M.text-s128M-b4K.
|
| 48 |
+
|
| 49 |
+
* `commonpool_m_basic_s128m_b4k`: A ViT-B/32 trained on CommonPool-M filtered using basic filtering (English filtering + caption length and image size filtering), for 128M steps and batch size 4k. Achieves 22.6% zero-shot accuracy on ImageNet. Available at https://huggingface.co/laion/CLIP-ViT-B-32-CommonPool.M.basic-s128M-b4K.
|
| 50 |
+
|
| 51 |
+
* `commonpool_m_s128m_b4k`: A ViT-B/32 trained on CommonPool-M without any filtering, for 128M steps and batch size 4k. Achieves 17.6% zero-shot accuracy on ImageNet. Available at https://huggingface.co/laion/CLIP-ViT-B-32-CommonPool.M-s128M-b4K.
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
## small scale models
|
| 55 |
+
|
| 56 |
+
* `datacomp_s_s13m_b4k`: A ViT-B/32 trained on a 1.4M subset of DataComp-1B, for 12.8M steps and batch size 4k. Achieves 3.9% zero-shot accuracy on ImageNet. Available at https://huggingface.co/laion/CLIP-ViT-B-32-DataComp.S-s13M-b4K.
|
| 57 |
+
|
| 58 |
+
* `commonpool_s_clip_s13m_b4k`: A ViT-B/32 trained on CommonPool-S filtered using CLIP scores, for 12.8M steps and batch size 4k. Achieves 5.1% zero-shot accuracy on ImageNet. Available at https://huggingface.co/laion/CLIP-ViT-B-32-CommonPool.S.clip-s13M-b4K.
|
| 59 |
+
|
| 60 |
+
* `commonpool_s_laion_s13m_b4k`: A ViT-B/32 trained on CommonPool-S filtered using the LAION-2B filtering scheme scores, for 12.8M steps and batch size 4k. Achieves 3.1% zero-shot accuracy on ImageNet. Available at https://huggingface.co/laion/CLIP-ViT-B-32-CommonPool.S.laion-s13M-b4K.
|
| 61 |
+
|
| 62 |
+
* `commonpool_s_image_s13m_b4k`: A ViT-B/32 trained on CommonPool-S filtered using image-based filtering, for 12.8M steps and batch size 4k. Achieves 4.3% zero-shot accuracy on ImageNet. Available at https://huggingface.co/laion/CLIP-ViT-B-32-CommonPool.S.image-s13M-b4K.
|
| 63 |
+
|
| 64 |
+
* `commonpool_s_text_s13m_b4k`: A ViT-B/32 trained on CommonPool-S filtered using text-based filtering, for 12.8M steps and batch size 4k. Achieves 4.6% zero-shot accuracy on ImageNet. Available at https://huggingface.co/laion/CLIP-ViT-B-32-CommonPool.S.text-s13M-b4K.
|
| 65 |
+
|
| 66 |
+
* `commonpool_s_basic_s13m_b4k`: A ViT-B/32 trained on CommonPool-S filtered using basic filtering (English filtering + caption length and image size filtering), for 12.8M steps and batch size 4k. Achieves 3.0% zero-shot accuracy on ImageNet. Available at https://huggingface.co/laion/CLIP-ViT-B-32-CommonPool.S.basic-s13M-b4K.
|
| 67 |
+
|
| 68 |
+
* `commonpool_s_s13m_b4k`: A ViT-B/32 trained on CommonPool-S without any filtering, for 12.8M steps and batch size 4k. Achieves 2.5% zero-shot accuracy on ImageNet. Available at https://huggingface.co/laion/CLIP-ViT-B-32-CommonPool.S-s13M-b4K.
|
| 69 |
+
|
hlip/open_clip/docs/effective_robustness.png
ADDED
|
Git LFS Details
|
hlip/open_clip/docs/inverse_scaling_law.png
ADDED
|
Git LFS Details
|
hlip/open_clip/docs/laion2b_clip_zeroshot_b32.png
ADDED
|
Git LFS Details
|
hlip/open_clip/docs/laion_clip_zeroshot.png
ADDED
|
Git LFS Details
|
hlip/open_clip/docs/laion_clip_zeroshot_b16.png
ADDED
|
Git LFS Details
|
hlip/open_clip/docs/laion_clip_zeroshot_b16_plus_240.png
ADDED
|
Git LFS Details
|
hlip/open_clip/docs/laion_clip_zeroshot_l14.png
ADDED
|
Git LFS Details
|
hlip/open_clip/docs/laion_openai_compare_b32.jpg
ADDED
|
Git LFS Details
|
hlip/open_clip/docs/model_profile.csv
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
model,image_size,image_width,text_width,embed_dim,mparams,image_mparams,text_mparams,gflops,image_gflops,text_gflops
|
| 2 |
+
ViT-S-32-alt,224,384,256,256,43.22,22.59,20.63,3.56,2.29,1.27
|
| 3 |
+
ViT-S-32,224,384,384,384,63.09,22.64,40.44,5.66,2.29,3.38
|
| 4 |
+
ViT-M-32-alt,224,512,384,384,80.07,39.63,40.44,7.37,3.99,3.38
|
| 5 |
+
ViT-M-32,224,512,512,512,103.12,39.69,63.43,9.95,3.99,5.96
|
| 6 |
+
ViT-S-16-alt,224,384,256,256,42.4,21.76,20.63,10.47,9.2,1.27
|
| 7 |
+
ViT-S-16,224,384,384,384,62.26,21.81,40.44,12.58,9.2,3.38
|
| 8 |
+
ViT-B-32,224,768,512,512,151.28,87.85,63.43,14.78,8.82,5.96
|
| 9 |
+
ViT-B-32-quickgelu,224,768,512,512,151.28,87.85,63.43,14.78,8.82,5.96
|
| 10 |
+
convnext_tiny,224,768,512,1024,92.3,28.61,63.69,14.87,8.91,5.96
|
| 11 |
+
ViT-B-32-256,256,768,512,512,151.29,87.86,63.43,17.46,11.5,5.96
|
| 12 |
+
RN50,224,64,512,1024,102.01,38.32,63.69,18.18,12.22,5.96
|
| 13 |
+
RN50-quickgelu,224,64,512,1024,102.01,38.32,63.69,18.18,12.22,5.96
|
| 14 |
+
ViT-M-16-alt,224,512,384,384,78.98,38.53,40.44,19.36,15.98,3.38
|
| 15 |
+
ViT-M-16,224,512,512,512,102.02,38.59,63.43,21.94,15.98,5.96
|
| 16 |
+
vit_relpos_medium_patch16_cls_224,224,768,512,512,101.94,38.51,63.43,21.99,16.03,5.96
|
| 17 |
+
mt5-base-ViT-B-32,224,768,512,512,365.71,87.85,277.86,22.12,8.82,13.3
|
| 18 |
+
convnext_small,224,768,512,512,113.28,49.85,63.43,23.33,17.37,5.96
|
| 19 |
+
ViT-B-32-plus-256,256,896,640,640,210.3,119.13,91.16,24.83,15.56,9.27
|
| 20 |
+
RN101,224,64,512,512,119.69,56.26,63.43,25.5,19.54,5.96
|
| 21 |
+
RN101-quickgelu,224,64,512,512,119.69,56.26,63.43,25.5,19.54,5.96
|
| 22 |
+
vit_medium_patch16_gap_256,256,768,512,512,102.04,38.61,63.43,27.1,21.14,5.96
|
| 23 |
+
coca_ViT-B-32,224,768,512,512,253.56,89.16,63.43,33.34,9.19,5.96
|
| 24 |
+
convnext_base,224,768,512,512,151.52,88.09,63.43,36.67,30.71,5.96
|
| 25 |
+
swin_base_patch4_window7_224,224,768,640,640,178.56,87.4,91.16,40.13,30.86,9.27
|
| 26 |
+
ViT-B-16,224,768,512,512,149.62,86.19,63.43,41.09,35.13,5.96
|
| 27 |
+
ViT-B-16-quickgelu,224,768,512,512,149.62,86.19,63.43,41.09,35.13,5.96
|
| 28 |
+
EVA02-B-16,224,768,512,512,149.69,86.26,63.43,41.09,35.13,5.96
|
| 29 |
+
ViT-B-16-SigLIP,224,768,768,768,203.16,92.88,110.27,46.44,35.42,11.02
|
| 30 |
+
convnext_base_w,256,768,640,640,179.39,88.22,91.16,49.38,40.11,9.27
|
| 31 |
+
RN50x4,288,80,640,640,178.3,87.14,91.16,51.82,42.56,9.27
|
| 32 |
+
coca_roberta-ViT-B-32,224,768,768,512,420.37,87.85,124.45,53.12,8.82,13.12
|
| 33 |
+
ViT-B-16-plus,224,896,640,640,208.35,117.19,91.16,56.75,47.49,9.27
|
| 34 |
+
ViT-B-16-SigLIP-256,256,768,768,768,203.2,92.93,110.27,57.84,46.82,11.02
|
| 35 |
+
ViT-B-16-SigLIP-i18n-256,256,768,768,768,370.63,92.93,277.7,57.84,46.82,11.02
|
| 36 |
+
ViT-B-16-plus-240,240,896,640,640,208.38,117.21,91.16,64.03,54.76,9.27
|
| 37 |
+
convnext_base_w_320,320,768,640,640,179.39,88.22,91.16,71.94,62.67,9.27
|
| 38 |
+
convnext_large,224,768,768,768,321.06,197.41,123.65,82.02,68.72,13.3
|
| 39 |
+
coca_base,288,768,768,512,440.34,86.4,134.66,99.09,46.47,13.3
|
| 40 |
+
roberta-ViT-B-32,224,768,512,512,212.72,87.85,124.87,105.87,8.82,97.05
|
| 41 |
+
xlm-roberta-base-ViT-B-32,224,768,512,512,366.12,87.85,278.27,105.87,8.82,97.05
|
| 42 |
+
convnext_large_d,256,768,768,768,351.77,199.77,152.0,107.5,89.76,17.73
|
| 43 |
+
ViT-B-16-SigLIP-384,384,768,768,768,203.45,93.18,110.27,123.15,112.13,11.02
|
| 44 |
+
ViT-L-16,224,1024,768,768,427.74,304.09,123.65,136.41,123.11,13.3
|
| 45 |
+
convnext_large_d_320,320,768,768,768,351.77,199.77,152.0,157.98,140.25,17.73
|
| 46 |
+
RN50x16,384,96,768,768,290.98,167.33,123.65,162.69,149.39,13.3
|
| 47 |
+
ViT-L-14-CLIPA,224,1024,768,768,414.21,303.96,110.25,167.5,162.03,5.47
|
| 48 |
+
EVA02-L-14,224,768,768,768,427.76,304.11,123.65,175.3,162.0,13.3
|
| 49 |
+
ViT-L-14,224,1024,768,768,427.62,303.97,123.65,175.33,162.03,13.3
|
| 50 |
+
ViT-L-14-quickgelu,224,1024,768,768,427.62,303.97,123.65,175.33,162.03,13.3
|
| 51 |
+
convnext_xlarge,256,768,1024,1024,653.89,350.25,303.65,198.38,159.14,39.24
|
| 52 |
+
ViT-L-16-SigLIP-256,256,768,1024,1024,652.15,315.96,336.19,201.62,162.56,39.06
|
| 53 |
+
coca_ViT-L-14,224,1024,768,768,638.45,306.72,123.65,214.52,163.64,13.3
|
| 54 |
+
ViT-B-16-SigLIP-512,512,768,768,768,203.79,93.52,110.27,227.26,216.24,11.02
|
| 55 |
+
ViT-SO400M-14-SigLIP,224,768,1152,1152,877.36,427.68,449.68,233.54,220.35,13.19
|
| 56 |
+
ViT-L-14-280,280,1024,768,768,427.76,304.11,123.65,271.79,258.49,13.3
|
| 57 |
+
ViT-L-16-320,320,1024,768,768,427.95,304.3,123.65,271.93,258.63,13.3
|
| 58 |
+
ViT-H-16,224,1280,1024,1024,986.26,632.23,354.03,301.72,254.63,47.09
|
| 59 |
+
ViT-H-14-CLIPA,224,1280,1024,1024,968.24,632.07,336.16,354.02,334.59,19.43
|
| 60 |
+
nllb-clip-base,224,768,512,512,501.89,87.85,414.04,369.6,8.82,360.78
|
| 61 |
+
ViT-H-14,224,1280,1024,1024,986.11,632.08,354.03,381.68,334.59,47.09
|
| 62 |
+
ViT-H-14-quickgelu,224,1280,1024,1024,986.11,632.08,354.03,381.68,334.59,47.09
|
| 63 |
+
ViT-L-14-CLIPA-336,336,1024,768,768,414.54,304.29,110.25,387.39,381.92,5.47
|
| 64 |
+
EVA02-L-14-336,336,768,768,768,428.08,304.43,123.65,395.16,381.86,13.3
|
| 65 |
+
ViT-L-14-336,336,1024,768,768,427.94,304.29,123.65,395.22,381.92,13.3
|
| 66 |
+
ViT-L-16-SigLIP-384,384,768,1024,1024,652.48,316.28,336.19,422.91,383.85,39.06
|
| 67 |
+
convnext_xxlarge,256,768,1024,1024,1200.58,846.54,354.03,443.03,395.94,47.09
|
| 68 |
+
nllb-clip-base-siglip,384,768,512,768,507.47,93.18,414.3,472.91,112.13,360.78
|
| 69 |
+
mt5-xl-ViT-H-14,224,1280,512,1024,2306.75,632.08,1674.68,514.04,334.59,179.45
|
| 70 |
+
EVA01-g-14,224,768,768,1024,1136.44,1012.59,123.85,547.36,534.06,13.3
|
| 71 |
+
RN50x64,448,128,1024,1024,623.26,420.38,202.88,552.65,529.11,23.55
|
| 72 |
+
EVA01-g-14-plus,224,768,1024,1024,1366.62,1012.59,354.03,581.15,534.06,47.09
|
| 73 |
+
ViT-g-14,224,1408,1024,1024,1366.68,1012.65,354.03,581.15,534.06,47.09
|
| 74 |
+
convnext_xxlarge_320,320,768,1024,1024,1200.58,846.54,354.03,665.74,618.65,47.09
|
| 75 |
+
xlm-roberta-large-ViT-H-14,224,1280,512,1024,1193.01,632.08,560.94,671.01,334.59,336.42
|
| 76 |
+
ViT-SO400M-14-SigLIP-384,384,768,1152,1152,877.96,428.23,449.73,723.48,670.35,53.13
|
| 77 |
+
ViT-H-14-CLIPA-336,336,1280,1024,1024,968.64,632.48,336.16,800.88,781.45,19.43
|
| 78 |
+
ViT-bigG-14-CLIPA,224,1664,1280,1280,2517.22,1844.9,672.32,1007.93,967.5,40.44
|
| 79 |
+
ViT-H-14-378-quickgelu,378,1280,1024,1024,986.71,632.68,354.03,1054.05,1006.96,47.09
|
| 80 |
+
ViT-bigG-14,224,1664,1280,1280,2539.57,1844.91,694.66,1065.36,967.5,97.86
|
| 81 |
+
nllb-clip-large,224,1280,512,1024,1399.22,632.08,767.14,1468.46,334.59,1133.87
|
| 82 |
+
nllb-clip-large-siglip,384,768,512,1152,1195.5,428.23,767.27,1804.22,670.35,1133.87
|
| 83 |
+
ViT-e-14,224,1792,1280,1280,4581.09,3807.72,773.37,2091.45,1981.35,110.1
|
| 84 |
+
ViT-bigG-14-CLIPA-336,336,1664,1280,1280,2517.76,1845.44,672.32,2271.58,2231.15,40.44
|
| 85 |
+
EVA02-E-14,224,768,1024,1024,4704.59,4350.56,354.03,2311.42,2264.33,47.09
|
| 86 |
+
EVA02-E-14-plus,224,768,1280,1024,5044.89,4350.56,694.33,2362.19,2264.33,97.86
|
hlip/open_clip/docs/openclip_classification_results.csv
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name,pretrained,params (M),FLOPs (B),Average perf. on 35 datasets,ImageNet 1k,Caltech-101,CIFAR-10,CIFAR-100,CLEVR Counts,CLEVR Distance,Country211,Describable Textures,EuroSAT,FGVC Aircraft,Food-101,GTSRB,ImageNet Sketch,ImageNet v2,ImageNet-A,ImageNet-O,ImageNet-R,KITTI Vehicle Distance,MNIST,ObjectNet,Oxford Flowers-102,Oxford-IIIT Pet,Pascal VOC 2007,PatchCamelyon,Rendered SST2,RESISC45,Stanford Cars,STL-10,SUN397,SVHN,iWildCam,Camelyon17,FMoW,Dollar Street,GeoDE
|
| 2 |
+
ViT-H-14-378-quickgelu,dfn5b,986.71,1054.05,0.7090,0.8437,0.9517,0.9880,0.9043,0.3596,0.2085,0.3787,0.7106,0.6133,0.7219,0.9623,0.6782,0.7324,0.7833,0.7964,0.3810,0.9376,0.3966,0.8364,0.7340,0.8935,0.9696,0.8241,0.6964,0.5546,0.7589,0.9598,0.9906,0.7733,0.6739,0.2205,0.7211,0.2075,0.7173,0.9349
|
| 3 |
+
EVA02-E-14-plus,laion2b_s9b_b144k,5044.89,2362.19,0.6980,0.8201,0.9535,0.9934,0.9316,0.2991,0.1998,0.3564,0.6777,0.7574,0.5360,0.9496,0.6740,0.7162,0.7564,0.8223,0.3540,0.9456,0.1842,0.7463,0.7937,0.8433,0.9567,0.8569,0.6442,0.6271,0.7490,0.9457,0.9926,0.7510,0.7560,0.2591,0.6948,0.2668,0.6951,0.9244
|
| 4 |
+
ViT-H-14-quickgelu,dfn5b,986.11,381.68,0.6972,0.8344,0.9552,0.9878,0.9051,0.2967,0.2117,0.3442,0.7064,0.6546,0.7147,0.9568,0.6772,0.7274,0.7736,0.6987,0.3810,0.9296,0.3347,0.8579,0.6813,0.8995,0.9658,0.8184,0.6539,0.5464,0.7508,0.9580,0.9890,0.7691,0.6764,0.2025,0.7050,0.2079,0.7009,0.9286
|
| 5 |
+
ViT-SO400M-14-SigLIP-384,webli,877.96,723.48,0.6916,0.8308,0.9599,0.9672,0.8357,0.4071,0.2246,0.3645,0.7303,0.6354,0.6069,0.9635,0.6429,0.7454,0.7717,0.8247,0.2775,0.9575,0.2082,0.8862,0.7695,0.9114,0.9680,0.7171,0.5268,0.7002,0.7211,0.9521,0.9930,0.7541,0.5151,0.2294,0.6149,0.3309,0.7301,0.9328
|
| 6 |
+
ViT-bigG-14-CLIPA-336,datacomp1b,2517.76,2271.58,0.6888,0.8309,0.9529,0.9904,0.9123,0.1399,0.2161,0.4094,0.7293,0.6457,0.5561,0.9623,0.6407,0.7454,0.7726,0.8599,0.3130,0.9535,0.2630,0.8533,0.7966,0.8694,0.9562,0.8162,0.5411,0.6420,0.7257,0.9542,0.9956,0.7645,0.6691,0.2383,0.5874,0.1766,0.6869,0.9407
|
| 7 |
+
ViT-bigG-14-CLIPA,datacomp1b,2517.22,1007.93,0.6871,0.8270,0.9513,0.9912,0.9135,0.1357,0.2113,0.3921,0.7207,0.6861,0.5576,0.9583,0.6460,0.7431,0.7699,0.8179,0.3075,0.9512,0.2743,0.8544,0.7694,0.8693,0.9576,0.8188,0.5345,0.6332,0.7137,0.9560,0.9965,0.7642,0.6811,0.2269,0.5955,0.1959,0.6869,0.9382
|
| 8 |
+
ViT-SO400M-14-SigLIP,webli,877.36,233.54,0.6819,0.8203,0.9600,0.9679,0.8417,0.4210,0.2213,0.3243,0.7106,0.6274,0.6029,0.9556,0.6382,0.7402,0.7607,0.7185,0.2960,0.9506,0.2489,0.8929,0.7060,0.8982,0.9522,0.7034,0.5057,0.6936,0.7257,0.9032,0.9939,0.7436,0.5670,0.1915,0.6215,0.3163,0.7173,0.9278
|
| 9 |
+
EVA02-E-14,laion2b_s4b_b115k,4704.59,2311.42,0.6725,0.8196,0.9541,0.9925,0.9258,0.1632,0.2499,0.3482,0.6878,0.7446,0.4892,0.9523,0.6729,0.7151,0.7566,0.8044,0.3340,0.9407,0.1294,0.7581,0.7674,0.8210,0.9569,0.8136,0.4972,0.5859,0.7324,0.9438,0.9926,0.7658,0.6381,0.2289,0.4894,0.2801,0.6682,0.9182
|
| 10 |
+
ViT-H-14-CLIPA-336,datacomp1b,968.64,800.88,0.6713,0.8180,0.9467,0.9890,0.8968,0.1326,0.2254,0.3551,0.7197,0.6604,0.4718,0.9572,0.5816,0.7282,0.7562,0.8275,0.3115,0.9438,0.2574,0.8245,0.7742,0.8463,0.9573,0.8134,0.4979,0.6052,0.7114,0.9483,0.9955,0.7635,0.6599,0.2239,0.4357,0.2500,0.6822,0.9278
|
| 11 |
+
ViT-L-14-quickgelu,dfn2b,427.62,175.33,0.6703,0.8141,0.9532,0.9836,0.8837,0.3325,0.2481,0.2823,0.6606,0.6493,0.3936,0.9457,0.6168,0.6832,0.7461,0.6677,0.3930,0.9000,0.2011,0.8470,0.7397,0.8654,0.9555,0.8162,0.6318,0.5502,0.7327,0.9470,0.9768,0.7546,0.6525,0.1883,0.6237,0.2237,0.6916,0.9111
|
| 12 |
+
ViT-bigG-14,laion2b_s39b_b160k,2539.57,1065.36,0.6694,0.8009,0.9484,0.9824,0.8752,0.2989,0.2002,0.3379,0.6867,0.6919,0.4953,0.9309,0.6244,0.6894,0.7359,0.6933,0.3785,0.9213,0.1308,0.7157,0.7284,0.8163,0.9529,0.8077,0.6364,0.6535,0.7235,0.9460,0.9850,0.7450,0.6961,0.1760,0.5905,0.2352,0.6857,0.9127
|
| 13 |
+
ViT-H-14-CLIPA,datacomp1b,968.24,354.02,0.6688,0.8152,0.9458,0.9888,0.8991,0.1513,0.2255,0.3401,0.7090,0.7146,0.4751,0.9554,0.5538,0.7272,0.7498,0.7701,0.3135,0.9426,0.2461,0.8189,0.7423,0.8437,0.9559,0.8170,0.4958,0.6189,0.7098,0.9458,0.9948,0.7608,0.6622,0.2160,0.4415,0.2684,0.6694,0.9236
|
| 14 |
+
ViT-H-14-quickgelu,metaclip_fullcc,986.11,381.68,0.6684,0.8051,0.9536,0.9804,0.8634,0.2115,0.1881,0.3716,0.7271,0.6450,0.5114,0.9423,0.6257,0.7052,0.7417,0.7533,0.3040,0.9342,0.2771,0.7266,0.7642,0.8448,0.9561,0.7495,0.6222,0.6925,0.7024,0.8990,0.9944,0.7440,0.5910,0.1680,0.5782,0.2314,0.6811,0.9077
|
| 15 |
+
ViT-L-14,datacomp_xl_s13b_b90k,427.62,175.33,0.6674,0.7921,0.9465,0.9824,0.8736,0.3555,0.2443,0.3157,0.6649,0.7124,0.4750,0.9452,0.5853,0.6795,0.7205,0.6959,0.3255,0.9083,0.2785,0.8661,0.7425,0.8262,0.9506,0.8247,0.5118,0.6101,0.6941,0.9305,0.9925,0.7427,0.6769,0.1614,0.5089,0.2403,0.6624,0.9152
|
| 16 |
+
ViT-L-16-SigLIP-384,webli,652.48,422.91,0.6668,0.8207,0.9611,0.9605,0.8188,0.3275,0.2077,0.2470,0.7080,0.5817,0.5312,0.9564,0.6385,0.7360,0.7593,0.7663,0.3130,0.9507,0.2222,0.8525,0.7284,0.8934,0.9681,0.7172,0.5466,0.5634,0.6789,0.9493,0.9924,0.7250,0.5672,0.2236,0.6637,0.1489,0.6916,0.9207
|
| 17 |
+
EVA01-g-14-plus,merged2b_s11b_b114k,1366.62,581.15,0.6645,0.7933,0.9506,0.9910,0.9008,0.2302,0.2293,0.3087,0.6734,0.7280,0.3947,0.9366,0.6644,0.6814,0.7214,0.7416,0.3415,0.9246,0.1491,0.7176,0.7491,0.7959,0.9490,0.8285,0.6244,0.5854,0.7079,0.9073,0.9949,0.7426,0.5951,0.1882,0.7100,0.2283,0.6589,0.9148
|
| 18 |
+
ViT-L-14-CLIPA-336,datacomp1b,414.54,387.39,0.6609,0.8026,0.9439,0.9864,0.8826,0.1566,0.2439,0.3066,0.6856,0.5811,0.4281,0.9456,0.5695,0.7087,0.7346,0.7771,0.3290,0.9329,0.1997,0.7667,0.7317,0.8100,0.9495,0.7979,0.6028,0.5316,0.6884,0.9407,0.9929,0.7560,0.6290,0.1937,0.6783,0.2500,0.6752,0.9240
|
| 19 |
+
ViT-L-14-quickgelu,metaclip_fullcc,427.62,175.33,0.6607,0.7917,0.9527,0.9759,0.8410,0.3107,0.2260,0.3394,0.6862,0.5894,0.4537,0.9352,0.5623,0.6896,0.7256,0.7231,0.3010,0.9205,0.2785,0.6444,0.7457,0.8143,0.9461,0.8030,0.6197,0.6678,0.7360,0.8868,0.9933,0.7355,0.4681,0.1581,0.7551,0.2592,0.6752,0.9140
|
| 20 |
+
EVA02-L-14-336,merged2b_s6b_b61k,428.08,395.16,0.6603,0.8039,0.9525,0.9892,0.8980,0.3635,0.2485,0.3354,0.6473,0.7139,0.3758,0.9421,0.5759,0.6891,0.7380,0.8289,0.2850,0.9324,0.2377,0.6421,0.7789,0.7645,0.9424,0.8267,0.5487,0.6463,0.6910,0.9158,0.9966,0.7480,0.4575,0.2105,0.5691,0.2198,0.6811,0.9136
|
| 21 |
+
ViT-L-14-CLIPA,datacomp1b,414.21,167.5,0.6577,0.7957,0.9453,0.9866,0.8850,0.1857,0.2449,0.2941,0.6963,0.6044,0.4299,0.9415,0.5906,0.7061,0.7305,0.7125,0.3370,0.9288,0.1927,0.7374,0.6988,0.8101,0.9497,0.8067,0.5915,0.5387,0.6843,0.9366,0.9919,0.7528,0.6390,0.1724,0.6760,0.2457,0.6647,0.9152
|
| 22 |
+
ViT-L-14,commonpool_xl_clip_s13b_b90k,427.62,175.33,0.6553,0.7637,0.9502,0.9797,0.8615,0.2547,0.2451,0.2984,0.6521,0.6681,0.3860,0.9355,0.5980,0.6538,0.6953,0.6197,0.3525,0.8924,0.2982,0.9040,0.7165,0.8006,0.9424,0.8336,0.5688,0.6178,0.6978,0.9352,0.9875,0.7351,0.6853,0.1439,0.5100,0.1705,0.6776,0.9056
|
| 23 |
+
convnext_xxlarge,laion2b_s34b_b82k_augreg_soup,1200.58,443.03,0.6545,0.7947,0.9448,0.9822,0.8687,0.1454,0.2365,0.3170,0.7053,0.6128,0.4434,0.9321,0.5508,0.6840,0.7260,0.6719,0.4060,0.9160,0.2363,0.8277,0.7273,0.8241,0.9445,0.8090,0.5142,0.6952,0.7190,0.9409,0.9810,0.7458,0.6254,0.1730,0.6071,0.0000,0.6764,0.9215
|
| 24 |
+
ViT-L-16-SigLIP-256,webli,652.15,201.62,0.6534,0.8045,0.9593,0.9619,0.8191,0.4065,0.2150,0.2141,0.7027,0.5598,0.5259,0.9463,0.6115,0.7209,0.7376,0.6213,0.3265,0.9396,0.1983,0.8499,0.6526,0.8827,0.9604,0.7409,0.5458,0.6172,0.6817,0.9386,0.9911,0.7253,0.5211,0.1796,0.5757,0.1296,0.6904,0.9173
|
| 25 |
+
convnext_xxlarge,laion2b_s34b_b82k_augreg_rewind,1200.58,443.03,0.6534,0.7931,0.9452,0.9823,0.8686,0.1651,0.2534,0.3155,0.7016,0.6331,0.4398,0.9308,0.5491,0.6825,0.7228,0.6657,0.3975,0.9139,0.2419,0.7930,0.7252,0.8241,0.9438,0.8100,0.5014,0.6897,0.7168,0.9406,0.9801,0.7459,0.6137,0.1735,0.6071,0.0000,0.6799,0.9228
|
| 26 |
+
xlm-roberta-large-ViT-H-14,frozen_laion5b_s13b_b90k,1193.01,671.01,0.6519,0.7695,0.9422,0.9718,0.8430,0.3358,0.2050,0.3172,0.6926,0.6793,0.4673,0.9236,0.6239,0.6581,0.6944,0.5935,0.3390,0.8940,0.1364,0.7804,0.6911,0.7532,0.9431,0.7995,0.5792,0.6436,0.6825,0.9362,0.9889,0.7551,0.5950,0.1392,0.6749,0.2098,0.6460,0.9111
|
| 27 |
+
EVA02-L-14,merged2b_s4b_b131k,427.76,175.3,0.6502,0.7977,0.9512,0.9908,0.9071,0.3176,0.2462,0.3091,0.6319,0.6994,0.3638,0.9340,0.5718,0.6813,0.7295,0.7619,0.2880,0.9272,0.2518,0.6729,0.7489,0.7631,0.9398,0.8220,0.5431,0.6150,0.6968,0.9055,0.9961,0.7410,0.4793,0.1886,0.5124,0.2017,0.6624,0.9073
|
| 28 |
+
convnext_xxlarge,laion2b_s34b_b82k_augreg,1200.58,443.03,0.6494,0.7907,0.9429,0.9816,0.8677,0.1399,0.1195,0.3127,0.7096,0.6030,0.4250,0.9295,0.5454,0.6806,0.7223,0.6692,0.4025,0.9131,0.2616,0.8687,0.7235,0.8091,0.9455,0.8116,0.5340,0.6782,0.7100,0.9399,0.9824,0.7436,0.6379,0.1616,0.5719,0.0000,0.6729,0.9228
|
| 29 |
+
ViT-g-14,laion2b_s34b_b88k,1366.68,581.15,0.6454,0.7847,0.9452,0.9815,0.8465,0.3768,0.1870,0.3091,0.6856,0.6530,0.4441,0.9241,0.4964,0.6754,0.7158,0.6092,0.3705,0.9020,0.2700,0.7191,0.6908,0.8010,0.9379,0.8166,0.5384,0.5678,0.6960,0.9394,0.9893,0.7411,0.5611,0.1524,0.4771,0.2090,0.6671,0.9090
|
| 30 |
+
ViT-H-14,laion2b_s32b_b79k,986.11,381.68,0.6442,0.7796,0.9421,0.9745,0.8473,0.2676,0.2358,0.2986,0.6782,0.7278,0.4265,0.9273,0.5832,0.6657,0.7090,0.5935,0.3825,0.8934,0.1097,0.7284,0.6941,0.7982,0.9438,0.7768,0.5430,0.6392,0.6995,0.9338,0.9848,0.7521,0.5252,0.1528,0.5638,0.2264,0.6343,0.9086
|
| 31 |
+
ViT-H-14-CLIPA-336,laion2b,968.64,800.88,0.6440,0.7910,0.9438,0.9826,0.8643,0.1835,0.2158,0.3111,0.7160,0.6393,0.3437,0.9303,0.5007,0.6994,0.7241,0.7213,0.3655,0.9269,0.1561,0.6365,0.7022,0.8009,0.9444,0.7723,0.5787,0.6178,0.7029,0.9476,0.9894,0.7567,0.6255,0.1853,0.5001,0.1666,0.6706,0.9257
|
| 32 |
+
ViT-B-16-SigLIP-512,webli,203.79,227.26,0.6434,0.7914,0.9516,0.9265,0.7146,0.2411,0.2226,0.1927,0.6793,0.4007,0.4521,0.9394,0.5171,0.6990,0.7283,0.6769,0.3615,0.9264,0.3924,0.8288,0.6764,0.8677,0.9499,0.7139,0.6615,0.5722,0.6538,0.9249,0.9853,0.7152,0.5444,0.1925,0.6606,0.1411,0.6928,0.9244
|
| 33 |
+
convnext_large_d_320,laion2b_s29b_b131k_ft_soup,351.77,157.98,0.6401,0.7685,0.9348,0.9659,0.8304,0.4293,0.2010,0.2654,0.6830,0.7161,0.3621,0.9162,0.5822,0.6504,0.6944,0.6044,0.4410,0.8862,0.1027,0.7434,0.6898,0.7755,0.9358,0.8129,0.4814,0.5585,0.7078,0.9369,0.9856,0.7376,0.6712,0.1786,0.4088,0.1901,0.6449,0.9094
|
| 34 |
+
EVA01-g-14,laion400m_s11b_b41k,1136.44,547.36,0.6390,0.7852,0.9477,0.9829,0.8865,0.1966,0.2467,0.2862,0.6144,0.7237,0.3226,0.9345,0.4913,0.6730,0.7152,0.7359,0.3285,0.9250,0.2405,0.6218,0.7200,0.7427,0.9414,0.8325,0.4987,0.5832,0.6976,0.9171,0.9889,0.7416,0.5889,0.1975,0.4999,0.1859,0.6741,0.8969
|
| 35 |
+
ViT-L-14,commonpool_xl_laion_s13b_b90k,427.62,175.33,0.6374,0.7545,0.9352,0.9796,0.8585,0.3819,0.2489,0.2503,0.6191,0.7378,0.2869,0.9200,0.6018,0.6352,0.6851,0.5747,0.3730,0.8708,0.1378,0.7740,0.6846,0.7435,0.9308,0.8107,0.5069,0.5986,0.7065,0.8912,0.9903,0.7327,0.5730,0.1421,0.5671,0.2337,0.6600,0.9115
|
| 36 |
+
convnext_large_d_320,laion2b_s29b_b131k_ft,351.77,157.98,0.6358,0.7660,0.9341,0.9647,0.8313,0.3688,0.1999,0.2673,0.6846,0.7131,0.3770,0.9160,0.5688,0.6472,0.6929,0.5933,0.4400,0.8823,0.1027,0.7695,0.6813,0.7696,0.9346,0.8002,0.4576,0.5623,0.6989,0.9348,0.9854,0.7355,0.6496,0.1664,0.4342,0.1782,0.6355,0.9090
|
| 37 |
+
ViT-B-16-SigLIP-384,webli,203.45,123.15,0.6349,0.7849,0.9507,0.9276,0.7147,0.2195,0.2239,0.1858,0.6718,0.4307,0.4522,0.9362,0.5196,0.6955,0.7211,0.6233,0.3640,0.9214,0.3333,0.8088,0.6343,0.8624,0.9515,0.7162,0.7010,0.5607,0.6579,0.9245,0.9863,0.7096,0.5285,0.1719,0.5931,0.1365,0.6846,0.9194
|
| 38 |
+
ViT-L-14-336,openai,427.94,395.22,0.6348,0.7656,0.9225,0.9493,0.7436,0.2003,0.1895,0.3445,0.5559,0.6144,0.3346,0.9386,0.5239,0.6100,0.7089,0.7748,0.3265,0.8905,0.2616,0.7916,0.7183,0.7852,0.9369,0.7815,0.6073,0.7057,0.6379,0.7932,0.9943,0.6865,0.5560,0.1490,0.6456,0.2325,0.6390,0.9015
|
| 39 |
+
coca_ViT-L-14,laion2b_s13b_b90k,638.45,214.52,0.6346,0.7561,0.9430,0.9722,0.8318,0.3781,0.2446,0.2551,0.6239,0.6752,0.3590,0.9038,0.5624,0.6453,0.6798,0.5336,0.3540,0.8812,0.1899,0.7790,0.6405,0.7643,0.9402,0.8096,0.5500,0.6634,0.6878,0.9276,0.9894,0.7406,0.6237,0.1375,0.4268,0.1932,0.6542,0.8960
|
| 40 |
+
ViT-g-14,laion2b_s12b_b42k,1366.68,581.15,0.6312,0.7663,0.9415,0.9706,0.8392,0.3317,0.2225,0.2878,0.6824,0.6469,0.3768,0.9155,0.4985,0.6516,0.6956,0.5716,0.3785,0.8869,0.1350,0.6840,0.6761,0.7800,0.9431,0.8108,0.5624,0.6425,0.7176,0.9292,0.9865,0.7541,0.3930,0.1486,0.4948,0.2040,0.6542,0.9132
|
| 41 |
+
convnext_large_d,laion2b_s26b_b102k_augreg,351.77,107.5,0.6303,0.7591,0.9365,0.9655,0.8309,0.3461,0.1997,0.2525,0.6739,0.6959,0.3610,0.9055,0.5299,0.6430,0.6826,0.5352,0.4425,0.8767,0.1027,0.8063,0.6618,0.7667,0.9282,0.7891,0.5309,0.5612,0.6768,0.9316,0.9829,0.7307,0.6812,0.1549,0.3964,0.1793,0.6402,0.9019
|
| 42 |
+
ViT-L-14-quickgelu,metaclip_400m,427.62,175.33,0.6264,0.7620,0.9464,0.9544,0.7727,0.2271,0.2514,0.3085,0.6245,0.6033,0.3983,0.9073,0.4755,0.6505,0.6977,0.6640,0.2895,0.8889,0.2419,0.6186,0.6923,0.7648,0.9381,0.7440,0.7039,0.6551,0.6848,0.8477,0.9928,0.7073,0.3239,0.1408,0.6916,0.1874,0.6741,0.8931
|
| 43 |
+
ViT-L-14,commonpool_xl_s13b_b90k,427.62,175.33,0.6251,0.7229,0.9327,0.9801,0.8410,0.1985,0.2461,0.2962,0.6202,0.6889,0.1957,0.9107,0.5467,0.6118,0.6511,0.5625,0.2855,0.8594,0.3390,0.9084,0.7022,0.6966,0.9060,0.8076,0.5248,0.5953,0.5756,0.8939,0.9890,0.7103,0.6589,0.1229,0.5246,0.1948,0.6811,0.8990
|
| 44 |
+
ViT-L-14,openai,427.62,175.33,0.6237,0.7554,0.9249,0.9559,0.7582,0.1943,0.2021,0.3187,0.5537,0.6263,0.3181,0.9305,0.5055,0.5959,0.6983,0.7075,0.3235,0.8784,0.2180,0.7634,0.6889,0.7923,0.9323,0.7828,0.5204,0.6881,0.6337,0.7788,0.9936,0.6756,0.5840,0.1211,0.6741,0.2229,0.6297,0.8839
|
| 45 |
+
ViT-L-14,laion2b_s32b_b82k,427.62,175.33,0.6219,0.7525,0.9388,0.9662,0.8332,0.3123,0.2234,0.2631,0.6293,0.6459,0.3652,0.9100,0.5618,0.6328,0.6780,0.5385,0.3870,0.8742,0.2293,0.5410,0.6529,0.7479,0.9309,0.8053,0.5641,0.5925,0.6687,0.9263,0.9885,0.7434,0.4087,0.1257,0.5972,0.2007,0.6402,0.8919
|
| 46 |
+
ViT-B-16-SigLIP,webli,203.16,46.44,0.6206,0.7604,0.9518,0.9234,0.7223,0.2373,0.2409,0.1594,0.6468,0.4428,0.4377,0.9162,0.5164,0.6792,0.6893,0.4541,0.3815,0.9030,0.4093,0.8354,0.5509,0.8549,0.9420,0.7212,0.5953,0.5244,0.6454,0.9081,0.9821,0.7001,0.5586,0.1309,0.6045,0.1265,0.6589,0.9106
|
| 47 |
+
ViT-B-16-SigLIP-256,webli,203.2,57.84,0.6196,0.7653,0.9496,0.9334,0.7327,0.2276,0.2340,0.1581,0.6574,0.4606,0.4473,0.9200,0.4940,0.6810,0.6920,0.4877,0.3785,0.9076,0.3685,0.8457,0.5723,0.8521,0.9424,0.7254,0.5657,0.5739,0.6440,0.9106,0.9818,0.7026,0.5399,0.1493,0.4966,0.1253,0.6589,0.9061
|
| 48 |
+
ViT-B-16,datacomp_xl_s13b_b90k,149.62,41.09,0.6178,0.7349,0.9380,0.9624,0.8212,0.3267,0.2461,0.2215,0.5793,0.5883,0.2970,0.9047,0.5523,0.6044,0.6598,0.4840,0.4285,0.8362,0.2883,0.7649,0.6350,0.7701,0.9254,0.8178,0.6002,0.5162,0.6535,0.8883,0.9811,0.7051,0.6272,0.1181,0.4799,0.1504,0.6168,0.8990
|
| 49 |
+
ViT-B-32-256,datacomp_s34b_b86k,151.29,17.46,0.6133,0.7281,0.9348,0.9653,0.8287,0.2489,0.2271,0.1968,0.6064,0.6469,0.3645,0.8909,0.5152,0.6065,0.6481,0.3757,0.4635,0.8344,0.2658,0.7939,0.5960,0.7822,0.9115,0.7880,0.5880,0.5294,0.6505,0.8990,0.9731,0.7021,0.6708,0.0910,0.6252,0.0000,0.6238,0.8923
|
| 50 |
+
coca_ViT-L-14,mscoco_finetuned_laion2b_s13b_b90k,638.45,214.52,0.6128,0.7204,0.9420,0.9630,0.7965,0.3765,0.2501,0.1800,0.6213,0.5867,0.2329,0.8436,0.5453,0.6114,0.6475,0.4548,0.3865,0.8574,0.3797,0.8292,0.6253,0.7074,0.9115,0.8106,0.4943,0.6107,0.6267,0.8865,0.9861,0.7398,0.5564,0.1303,0.4294,0.1678,0.6636,0.8772
|
| 51 |
+
RN50x64,openai,623.26,552.65,0.6111,0.7391,0.9026,0.8510,0.5985,0.2254,0.1994,0.2981,0.5314,0.5765,0.3103,0.9205,0.4792,0.5593,0.6706,0.7077,0.3830,0.8441,0.3094,0.8583,0.6820,0.7745,0.9360,0.7398,0.5387,0.7106,0.6265,0.7581,0.9829,0.6661,0.6044,0.1469,0.5280,0.1939,0.6472,0.8898
|
| 52 |
+
ViT-B-16,dfn2b,149.62,41.09,0.6090,0.7624,0.9429,0.9672,0.8349,0.2327,0.2453,0.1955,0.5755,0.5402,0.2473,0.9130,0.4701,0.6204,0.6818,0.4820,0.4925,0.8310,0.1927,0.7814,0.6319,0.8201,0.9372,0.7884,0.5214,0.4876,0.6137,0.9073,0.9753,0.7143,0.5985,0.1554,0.4993,0.1415,0.6250,0.8910
|
| 53 |
+
ViT-B-16-quickgelu,metaclip_fullcc,149.62,41.09,0.6042,0.7212,0.9328,0.9572,0.7891,0.2935,0.2260,0.2271,0.6223,0.5265,0.3059,0.8882,0.4659,0.6016,0.6505,0.4953,0.4150,0.8423,0.1871,0.6610,0.6138,0.7358,0.9175,0.7818,0.5915,0.5898,0.6744,0.8302,0.9841,0.6879,0.3909,0.1227,0.6993,0.1932,0.6402,0.8868
|
| 54 |
+
ViT-B-16-SigLIP-i18n-256,webli,370.63,57.84,0.6037,0.7513,0.9475,0.9118,0.7216,0.2552,0.1976,0.1593,0.6426,0.3826,0.3325,0.9171,0.5276,0.6588,0.6814,0.4585,0.3685,0.8920,0.3826,0.8301,0.5977,0.8387,0.9387,0.7536,0.5381,0.5700,0.5737,0.8926,0.9764,0.6978,0.4272,0.1451,0.4899,0.1064,0.6472,0.9186
|
| 55 |
+
ViT-L-14,laion400m_e32,427.62,175.33,0.5998,0.7277,0.9266,0.9464,0.7741,0.2421,0.2452,0.2302,0.6053,0.6233,0.2490,0.9007,0.4989,0.5964,0.6545,0.4647,0.4190,0.8467,0.1997,0.7612,0.5969,0.7306,0.9170,0.7561,0.4968,0.5601,0.6741,0.8962,0.9808,0.7258,0.4955,0.1254,0.4555,0.1708,0.6168,0.8839
|
| 56 |
+
ViT-L-14,laion400m_e31,427.62,175.33,0.5991,0.7271,0.9259,0.9465,0.7738,0.2420,0.2452,0.2290,0.5973,0.6322,0.2462,0.9002,0.4965,0.5944,0.6547,0.4596,0.4225,0.8466,0.1997,0.7668,0.5962,0.7323,0.9154,0.7585,0.4877,0.5651,0.6710,0.8964,0.9804,0.7247,0.4956,0.1239,0.4595,0.1651,0.6075,0.8831
|
| 57 |
+
EVA02-B-16,merged2b_s8b_b131k,149.69,41.09,0.5891,0.7472,0.9302,0.9846,0.8773,0.2125,0.2254,0.2136,0.5282,0.6635,0.2506,0.8943,0.4630,0.5771,0.6701,0.5396,0.3410,0.8244,0.2208,0.4729,0.6214,0.7245,0.9211,0.8019,0.5091,0.5415,0.6037,0.7855,0.9949,0.7064,0.2497,0.1515,0.7095,0.1724,0.6086,0.8810
|
| 58 |
+
convnext_base_w_320,laion_aesthetic_s13b_b82k_augreg,179.39,71.94,0.5874,0.7128,0.9255,0.8823,0.6515,0.2825,0.2225,0.2243,0.6074,0.5124,0.2632,0.8947,0.4365,0.5646,0.6362,0.4157,0.5075,0.8136,0.2180,0.7219,0.5237,0.7524,0.9239,0.7530,0.5696,0.5508,0.6421,0.8918,0.9755,0.7037,0.4443,0.1392,0.5502,0.1215,0.6297,0.8935
|
| 59 |
+
ViT-B-16,laion2b_s34b_b88k,149.62,41.09,0.5869,0.7023,0.9287,0.9494,0.7684,0.2149,0.2455,0.2029,0.5633,0.5346,0.2695,0.8663,0.4826,0.5608,0.6228,0.3823,0.4625,0.8061,0.1730,0.6577,0.5598,0.7084,0.9048,0.7886,0.5639,0.5969,0.6275,0.8848,0.9786,0.7085,0.5002,0.1217,0.6249,0.1211,0.5841,0.8735
|
| 60 |
+
convnext_base_w,laion2b_s13b_b82k_augreg,179.39,49.38,0.5833,0.7147,0.9258,0.9561,0.8021,0.3307,0.2450,0.2016,0.6144,0.4828,0.2235,0.8675,0.4654,0.5890,0.6329,0.3817,0.5110,0.8253,0.2068,0.6441,0.5732,0.7017,0.9191,0.7979,0.4823,0.5925,0.6056,0.9126,0.9705,0.7113,0.5376,0.1285,0.3801,0.0000,0.5935,0.8881
|
| 61 |
+
ViT-B-32,datacomp_xl_s13b_b90k,151.28,14.78,0.5831,0.6917,0.9230,0.9561,0.8031,0.1294,0.2423,0.1756,0.5713,0.5746,0.2463,0.8632,0.5185,0.5676,0.6075,0.3035,0.4975,0.7818,0.1632,0.8124,0.5510,0.7353,0.9002,0.8151,0.5284,0.4849,0.6343,0.8728,0.9654,0.6780,0.6240,0.0863,0.6656,0.0000,0.5643,0.8731
|
| 62 |
+
ViT-B-16-quickgelu,metaclip_400m,149.62,41.09,0.5778,0.7080,0.9341,0.9014,0.6657,0.3010,0.2245,0.2260,0.5590,0.5572,0.2839,0.8725,0.4375,0.5789,0.6261,0.4700,0.3920,0.8177,0.2419,0.4794,0.5916,0.7229,0.9035,0.7217,0.6203,0.6046,0.6619,0.7421,0.9724,0.6678,0.2523,0.1122,0.6769,0.1991,0.6063,0.8894
|
| 63 |
+
convnext_base_w,laion2b_s13b_b82k,179.39,49.38,0.5744,0.7078,0.9222,0.9383,0.7519,0.2385,0.1866,0.2018,0.5957,0.5678,0.2825,0.8711,0.4930,0.5712,0.6234,0.3993,0.4815,0.8070,0.1505,0.5435,0.5795,0.6955,0.9189,0.8038,0.4154,0.6041,0.6284,0.8957,0.9775,0.7128,0.3459,0.1181,0.4812,0.1072,0.6075,0.8802
|
| 64 |
+
convnext_base_w,laion_aesthetic_s13b_b82k,179.39,49.38,0.5744,0.7099,0.9061,0.8305,0.6116,0.2960,0.1956,0.2228,0.6229,0.4519,0.2938,0.8847,0.4016,0.5546,0.6342,0.4123,0.4750,0.7986,0.2630,0.6739,0.5559,0.7170,0.9199,0.7548,0.5517,0.5579,0.6162,0.8661,0.9709,0.7143,0.2802,0.1378,0.5859,0.1284,0.6343,0.8722
|
| 65 |
+
ViT-B-16-plus-240,laion400m_e32,208.38,64.03,0.5735,0.6919,0.9239,0.9273,0.7377,0.2387,0.2348,0.1894,0.5548,0.5820,0.1852,0.8734,0.4944,0.5442,0.6148,0.3689,0.4980,0.8049,0.2813,0.5709,0.5384,0.6886,0.9015,0.7636,0.5524,0.5799,0.6137,0.8448,0.9698,0.6985,0.3777,0.1163,0.4876,0.1616,0.5923,0.8697
|
| 66 |
+
ViT-B-16-plus-240,laion400m_e31,208.38,64.03,0.5725,0.6904,0.9219,0.9247,0.7329,0.2413,0.2346,0.1884,0.5548,0.5702,0.1861,0.8735,0.4897,0.5443,0.6138,0.3676,0.5030,0.8038,0.2799,0.5722,0.5374,0.6825,0.9035,0.7634,0.5512,0.5859,0.6144,0.8450,0.9689,0.6991,0.3767,0.1164,0.4837,0.1618,0.5841,0.8689
|
| 67 |
+
ViT-B-32,laion2b_s34b_b79k,151.28,14.78,0.5701,0.6656,0.9105,0.9358,0.7555,0.1535,0.2451,0.1667,0.5569,0.4806,0.2453,0.8269,0.4933,0.5366,0.5814,0.2627,0.4995,0.7643,0.2630,0.6996,0.4883,0.7024,0.9076,0.7910,0.5993,0.5728,0.6106,0.8607,0.9656,0.6872,0.4257,0.0930,0.6392,0.1479,0.5666,0.8543
|
| 68 |
+
RN50x16,openai,290.98,162.69,0.5697,0.7072,0.8856,0.8134,0.5209,0.1953,0.2095,0.2437,0.5266,0.4328,0.2783,0.9051,0.3984,0.5063,0.6420,0.5724,0.4495,0.7933,0.2307,0.6798,0.6071,0.7188,0.8956,0.6800,0.6249,0.6771,0.5883,0.7286,0.9775,0.6391,0.4548,0.1079,0.6248,0.1593,0.6121,0.8539
|
| 69 |
+
ViT-B-16,openai,149.62,41.09,0.5657,0.6834,0.8901,0.9077,0.6695,0.2123,0.2231,0.2282,0.4495,0.5594,0.2421,0.8872,0.4339,0.4824,0.6188,0.4995,0.4230,0.7770,0.2644,0.5135,0.5531,0.6907,0.8886,0.7831,0.5072,0.6068,0.5822,0.6477,0.9825,0.6435,0.5190,0.1099,0.6808,0.1888,0.5876,0.8614
|
| 70 |
+
xlm-roberta-base-ViT-B-32,laion5b_s13b_b90k,366.12,105.87,0.5648,0.6236,0.9079,0.9366,0.7654,0.1675,0.2025,0.1896,0.6037,0.6006,0.2692,0.8010,0.4561,0.5071,0.5425,0.2355,0.4825,0.7410,0.1814,0.7407,0.4607,0.6235,0.8690,0.7856,0.6423,0.5354,0.6137,0.8556,0.9668,0.6785,0.5532,0.0801,0.5770,0.1292,0.5771,0.8647
|
| 71 |
+
convnext_base_w_320,laion_aesthetic_s13b_b82k,179.39,71.94,0.5634,0.7167,0.9136,0.8613,0.5900,0.2283,0.2255,0.2237,0.5931,0.3519,0.2834,0.8930,0.4459,0.5639,0.6398,0.4225,0.4745,0.8054,0.0928,0.6647,0.5616,0.7165,0.9244,0.7240,0.4899,0.5541,0.6176,0.8821,0.9664,0.7161,0.2606,0.1473,0.4729,0.1813,0.6273,0.8856
|
| 72 |
+
ViT-B-16,laion400m_e32,149.62,41.09,0.5633,0.6705,0.9131,0.9172,0.7116,0.2869,0.2451,0.1810,0.5133,0.5019,0.1765,0.8613,0.4346,0.5238,0.5963,0.3324,0.5075,0.7793,0.1814,0.6624,0.5152,0.6691,0.8917,0.7684,0.5960,0.5437,0.5852,0.8373,0.9698,0.6961,0.3413,0.1028,0.5999,0.1546,0.5935,0.8534
|
| 73 |
+
ViT-B-16,laion400m_e31,149.62,41.09,0.5632,0.6698,0.9159,0.9169,0.7130,0.2889,0.2451,0.1804,0.5138,0.5033,0.1742,0.8587,0.4353,0.5233,0.5943,0.3327,0.5035,0.7777,0.1997,0.6531,0.5128,0.6693,0.8911,0.7678,0.5925,0.5459,0.5849,0.8365,0.9703,0.6958,0.3388,0.1056,0.5976,0.1546,0.5946,0.8534
|
| 74 |
+
convnext_base,laion400m_s13b_b51k,151.52,36.67,0.5594,0.6627,0.9151,0.8899,0.6462,0.2386,0.2209,0.1700,0.5404,0.4850,0.1556,0.8515,0.4551,0.5196,0.5859,0.3092,0.4925,0.7575,0.2925,0.6114,0.5058,0.6900,0.8853,0.7528,0.6116,0.5376,0.5683,0.8409,0.9656,0.6845,0.4038,0.1095,0.6565,0.1589,0.5537,0.8530
|
| 75 |
+
ViT-B-32-quickgelu,metaclip_fullcc,151.28,14.78,0.5564,0.6766,0.9290,0.9518,0.7767,0.1871,0.2307,0.1764,0.5883,0.4991,0.2705,0.8309,0.3922,0.5599,0.5957,0.2993,0.4825,0.7805,0.1871,0.4272,0.5286,0.6935,0.9087,0.7652,0.5596,0.5310,0.6124,0.7738,0.9630,0.6689,0.3447,0.0915,0.5656,0.1588,0.6051,0.8610
|
| 76 |
+
coca_ViT-B-32,laion2b_s13b_b90k,253.56,33.34,0.5537,0.6331,0.9078,0.9387,0.7378,0.1831,0.2175,0.1450,0.5367,0.4602,0.1783,0.7893,0.4532,0.5121,0.5522,0.2149,0.4920,0.7376,0.2644,0.7097,0.4470,0.6226,0.8875,0.7832,0.5938,0.5766,0.5994,0.8397,0.9626,0.6736,0.5503,0.0876,0.5749,0.1010,0.5724,0.8430
|
| 77 |
+
ViT-B-32,laion2b_e16,151.28,14.78,0.5470,0.6565,0.9104,0.9403,0.7544,0.1923,0.2310,0.1652,0.5383,0.5030,0.2298,0.8166,0.3655,0.5287,0.5739,0.2615,0.5030,0.7588,0.1758,0.6347,0.4877,0.6732,0.8903,0.7877,0.5072,0.5437,0.6190,0.8437,0.9653,0.6851,0.4164,0.0971,0.4648,0.0000,0.5724,0.8526
|
| 78 |
+
ViT-B-16,datacomp_l_s1b_b8k,149.62,41.09,0.5406,0.6310,0.8969,0.9381,0.7540,0.2314,0.2513,0.1434,0.4691,0.5011,0.1001,0.8311,0.4343,0.4976,0.5521,0.2545,0.4955,0.7177,0.4008,0.5400,0.5298,0.6261,0.8352,0.8089,0.4973,0.5294,0.5273,0.7718,0.9576,0.6431,0.4595,0.0729,0.5000,0.0976,0.5748,0.8493
|
| 79 |
+
roberta-ViT-B-32,laion2b_s12b_b32k,212.72,105.87,0.5405,0.6171,0.9039,0.9325,0.7505,0.1472,0.2007,0.1472,0.5920,0.5215,0.1725,0.7812,0.4082,0.4912,0.5331,0.2120,0.5075,0.7224,0.3854,0.6636,0.4499,0.5893,0.8670,0.7804,0.4985,0.5420,0.6117,0.8315,0.9564,0.6627,0.4526,0.0606,0.4098,0.1161,0.5549,0.8426
|
| 80 |
+
ViT-B-32-quickgelu,metaclip_400m,151.28,14.78,0.5377,0.6558,0.9171,0.9125,0.7006,0.2175,0.2448,0.1716,0.5255,0.5239,0.2680,0.8106,0.3576,0.5330,0.5760,0.2863,0.4680,0.7477,0.2588,0.4144,0.5046,0.6811,0.8877,0.7081,0.6426,0.5338,0.5954,0.7060,0.9543,0.6345,0.2056,0.0819,0.6443,0.0000,0.5970,0.8539
|
| 81 |
+
ViT-B-16,commonpool_l_clip_s1b_b8k,149.62,41.09,0.5348,0.5777,0.8853,0.9349,0.7313,0.2691,0.2313,0.1417,0.4500,0.4728,0.0822,0.7995,0.4657,0.4589,0.4995,0.2165,0.4950,0.6843,0.3755,0.7032,0.4914,0.5667,0.7561,0.7821,0.4962,0.5036,0.5295,0.8171,0.9496,0.6295,0.5985,0.0741,0.4920,0.1257,0.5818,0.8501
|
| 82 |
+
ViT-B-32-quickgelu,laion400m_e32,151.28,14.78,0.5282,0.6293,0.9118,0.9074,0.7029,0.1624,0.2391,0.1475,0.5457,0.5143,0.1658,0.8086,0.4197,0.4939,0.5506,0.2172,0.5345,0.7342,0.2897,0.3733,0.4389,0.6620,0.8671,0.7582,0.5592,0.5228,0.5454,0.7926,0.9560,0.6700,0.3039,0.0745,0.4709,0.1296,0.5491,0.8380
|
| 83 |
+
ViT-B-32-quickgelu,laion400m_e31,151.28,14.78,0.5273,0.6294,0.9121,0.9060,0.7021,0.1659,0.2397,0.1476,0.5447,0.5085,0.1675,0.8080,0.4230,0.4937,0.5487,0.2161,0.5335,0.7349,0.2911,0.3656,0.4374,0.6638,0.8629,0.7539,0.5543,0.5217,0.5446,0.7914,0.9553,0.6702,0.3144,0.0788,0.4554,0.1310,0.5467,0.8363
|
| 84 |
+
ViT-B-32,openai,151.28,14.78,0.5265,0.6332,0.8758,0.8983,0.6423,0.2320,0.2335,0.1720,0.4436,0.5044,0.1953,0.8400,0.3258,0.4229,0.5592,0.3155,0.4775,0.6933,0.2743,0.4839,0.4431,0.6670,0.8700,0.7640,0.6224,0.5865,0.5362,0.5963,0.9713,0.6248,0.3159,0.0732,0.6061,0.1676,0.5386,0.8217
|
| 85 |
+
ViT-B-32-quickgelu,openai,151.28,14.78,0.5265,0.6332,0.8758,0.8983,0.6423,0.2320,0.2335,0.1720,0.4436,0.5044,0.1953,0.8400,0.3258,0.4229,0.5592,0.3155,0.4775,0.6933,0.2743,0.4839,0.4431,0.6670,0.8700,0.7640,0.6224,0.5865,0.5362,0.5963,0.9713,0.6248,0.3159,0.0732,0.6061,0.1676,0.5386,0.8217
|
| 86 |
+
RN50x4,openai,178.3,51.82,0.5191,0.6627,0.8661,0.7943,0.4514,0.2045,0.0905,0.2039,0.4862,0.3354,0.2102,0.8640,0.3622,0.4468,0.5944,0.4145,0.4955,0.7274,0.2335,0.4903,0.5141,0.6766,0.8829,0.6814,0.5675,0.6716,0.5338,0.6673,0.9658,0.6089,0.3190,0.0870,0.5435,0.1130,0.5654,0.8376
|
| 87 |
+
nllb-clip-large-siglip,v1,1195.5,1804.22,0.5148,0.5175,0.8392,0.9651,0.7626,0.1737,0.2211,0.1549,0.4394,0.4941,0.0451,0.6312,0.4700,0.5050,0.4631,0.5611,0.1825,0.8325,0.4290,0.6203,0.6492,0.2846,0.4082,0.7823,0.5004,0.5601,0.5656,0.6451,0.9939,0.6355,0.4258,0.0950,0.5000,0.1415,0.6390,0.8855
|
| 88 |
+
ViT-B-32,laion400m_e31,151.28,14.78,0.5070,0.6022,0.8916,0.8825,0.6781,0.1549,0.2261,0.1356,0.5218,0.4694,0.1437,0.7814,0.4082,0.4648,0.5234,0.1957,0.5085,0.7079,0.1224,0.4108,0.4281,0.6319,0.8541,0.7312,0.5495,0.5162,0.5108,0.7436,0.9494,0.6508,0.2891,0.0745,0.4975,0.1076,0.5491,0.8328
|
| 89 |
+
ViT-B-32,laion400m_e32,151.28,14.78,0.5067,0.6024,0.8918,0.8840,0.6773,0.1536,0.2261,0.1349,0.5229,0.4754,0.1467,0.7817,0.4070,0.4646,0.5237,0.1953,0.5080,0.7084,0.1181,0.4000,0.4292,0.6323,0.8513,0.7328,0.5490,0.5206,0.5094,0.7454,0.9498,0.6509,0.2759,0.0741,0.5084,0.1068,0.5444,0.8326
|
| 90 |
+
RN101,openai,119.69,25.5,0.5036,0.6228,0.8527,0.8078,0.4764,0.2437,0.0923,0.1693,0.4335,0.3131,0.1853,0.8367,0.3753,0.4106,0.5612,0.2944,0.5085,0.6817,0.2644,0.5254,0.4515,0.6532,0.8652,0.6512,0.5819,0.6403,0.5476,0.6100,0.9680,0.5803,0.3185,0.0888,0.4723,0.1615,0.5631,0.8164
|
| 91 |
+
RN101-quickgelu,openai,119.69,25.5,0.5036,0.6228,0.8527,0.8078,0.4764,0.2437,0.0923,0.1693,0.4335,0.3131,0.1853,0.8367,0.3753,0.4106,0.5612,0.2944,0.5085,0.6817,0.2644,0.5254,0.4515,0.6532,0.8652,0.6512,0.5819,0.6403,0.5476,0.6100,0.9680,0.5803,0.3185,0.0888,0.4723,0.1615,0.5631,0.8164
|
| 92 |
+
ViT-B-16,commonpool_l_laion_s1b_b8k,149.62,41.09,0.5017,0.5526,0.8766,0.9296,0.7184,0.2681,0.2173,0.1119,0.4144,0.4115,0.0714,0.7661,0.3296,0.4315,0.4790,0.2004,0.4930,0.6501,0.3432,0.4753,0.4638,0.5023,0.7769,0.7686,0.5158,0.5228,0.5314,0.6760,0.9409,0.6278,0.4301,0.0490,0.5127,0.1026,0.5514,0.8463
|
| 93 |
+
RN50,openai,102.01,18.18,0.4812,0.5982,0.8329,0.7157,0.4030,0.2171,0.1623,0.1542,0.4154,0.4081,0.1703,0.8080,0.3510,0.3544,0.5284,0.2327,0.5720,0.6073,0.1730,0.5755,0.4141,0.6522,0.8529,0.6510,0.6393,0.5645,0.4521,0.5453,0.9419,0.5994,0.2883,0.0623,0.5624,0.0000,0.5222,0.8129
|
| 94 |
+
RN50-quickgelu,openai,102.01,18.18,0.4812,0.5982,0.8329,0.7157,0.4030,0.2171,0.1623,0.1542,0.4154,0.4081,0.1703,0.8080,0.3510,0.3544,0.5284,0.2327,0.5720,0.6073,0.1730,0.5755,0.4141,0.6522,0.8529,0.6510,0.6393,0.5645,0.4521,0.5453,0.9419,0.5994,0.2883,0.0623,0.5624,0.0000,0.5222,0.8129
|
| 95 |
+
ViT-B-16,commonpool_l_image_s1b_b8k,149.62,41.09,0.4812,0.5719,0.8856,0.9321,0.6955,0.2143,0.2453,0.1308,0.4170,0.3193,0.0735,0.7797,0.2514,0.4343,0.4872,0.2143,0.4725,0.6356,0.3826,0.2219,0.4793,0.4817,0.7784,0.7841,0.5002,0.4986,0.4622,0.6627,0.9489,0.6335,0.2673,0.0424,0.5000,0.0000,0.5946,0.8422
|
| 96 |
+
ViT-B-16,commonpool_l_text_s1b_b8k,149.62,41.09,0.4758,0.5605,0.8720,0.9391,0.7054,0.1843,0.2373,0.0995,0.3941,0.3830,0.0451,0.7724,0.2317,0.4437,0.4835,0.2220,0.4770,0.6708,0.2686,0.2593,0.4911,0.5164,0.7049,0.7669,0.4857,0.4931,0.4663,0.6525,0.9523,0.6088,0.2122,0.0623,0.5697,0.0000,0.5643,0.8564
|
| 97 |
+
ViT-B-16,commonpool_l_basic_s1b_b8k,149.62,41.09,0.4566,0.5155,0.8444,0.8289,0.5251,0.2061,0.2277,0.1173,0.4133,0.3820,0.0481,0.7461,0.2021,0.3932,0.4325,0.1913,0.4600,0.6087,0.3333,0.2809,0.4493,0.4357,0.6956,0.7151,0.5899,0.5387,0.4313,0.7216,0.9373,0.5974,0.1173,0.0436,0.5712,0.0000,0.5421,0.8384
|
| 98 |
+
ViT-B-16,commonpool_l_s1b_b8k,149.62,41.09,0.4386,0.4593,0.8089,0.9133,0.6421,0.1594,0.2203,0.1177,0.3383,0.3348,0.0316,0.6735,0.2766,0.3448,0.3914,0.1592,0.4335,0.5265,0.2686,0.3603,0.4126,0.3681,0.5587,0.7093,0.5516,0.5118,0.4154,0.6060,0.9339,0.5713,0.3047,0.0399,0.5102,0.0000,0.5654,0.8305
|
| 99 |
+
nllb-clip-base-siglip,v1,507.47,472.91,0.4377,0.3909,0.7507,0.9043,0.5939,0.1453,0.2254,0.0583,0.3617,0.3744,0.0090,0.4961,0.3429,0.3886,0.3439,0.3165,0.1695,0.6846,0.1927,0.5007,0.5001,0.1567,0.1868,0.7599,0.6692,0.5859,0.5049,0.4703,0.9818,0.5640,0.4033,0.0694,0.6500,0.0956,0.6320,0.8392
|
| 100 |
+
nllb-clip-large,v1,1399.22,1468.46,0.4163,0.3672,0.7234,0.9634,0.6797,0.2389,0.2254,0.0691,0.3447,0.5454,0.0216,0.4447,0.2462,0.3316,0.3233,0.2632,0.1725,0.5624,0.3727,0.2716,0.5268,0.0978,0.1283,0.7551,0.5417,0.5585,0.4983,0.3865,0.9811,0.5512,0.1725,0.0403,0.5181,0.1419,0.6752,0.8305
|
| 101 |
+
ViT-B-32,datacomp_m_s128m_b4k,151.28,14.78,0.3364,0.2972,0.7159,0.8252,0.5476,0.1365,0.2249,0.0453,0.2133,0.3393,0.0304,0.4168,0.1366,0.1930,0.2440,0.0493,0.4085,0.3402,0.2110,0.1147,0.1971,0.2965,0.4311,0.5459,0.5862,0.5316,0.2778,0.2803,0.8365,0.3637,0.1500,0.0142,0.6669,0.0000,0.4498,0.6559
|
| 102 |
+
ViT-B-32,commonpool_m_clip_s128m_b4k,151.28,14.78,0.3344,0.2725,0.6678,0.8405,0.5549,0.1402,0.2238,0.0458,0.2176,0.2589,0.0215,0.3999,0.1586,0.1844,0.2247,0.0420,0.3925,0.3297,0.3235,0.1778,0.2093,0.2551,0.3828,0.6074,0.5210,0.5014,0.2641,0.4123,0.8370,0.3875,0.1931,0.0154,0.5369,0.0000,0.4451,0.6610
|
| 103 |
+
nllb-clip-base,v1,501.89,369.6,0.3290,0.2432,0.5914,0.8435,0.4839,0.1531,0.2254,0.0312,0.2782,0.4104,0.0185,0.2962,0.1852,0.1838,0.2029,0.0921,0.2195,0.3656,0.3741,0.1821,0.2874,0.0850,0.0784,0.6802,0.5509,0.5420,0.3603,0.1921,0.9514,0.4708,0.1441,0.0463,0.4873,0.0000,0.5456,0.7136
|
| 104 |
+
RN50-quickgelu,cc12m,102.01,18.18,0.3193,0.3647,0.6581,0.5404,0.2079,0.2063,0.1574,0.0431,0.1910,0.2146,0.0226,0.4392,0.1284,0.2412,0.3098,0.0759,0.4160,0.4468,0.3713,0.1261,0.2320,0.2383,0.5651,0.4394,0.5033,0.4789,0.2137,0.1837,0.8751,0.4442,0.0918,0.0476,0.5000,0.0000,0.4883,0.7119
|
| 105 |
+
RN50,cc12m,102.01,18.18,0.3180,0.3591,0.6432,0.5241,0.2093,0.2076,0.1576,0.0422,0.2074,0.2202,0.0178,0.4241,0.1155,0.2354,0.3065,0.0763,0.4165,0.4466,0.3713,0.0919,0.2326,0.2465,0.5504,0.4700,0.5035,0.4871,0.2351,0.1818,0.8696,0.4440,0.0923,0.0464,0.5000,0.0000,0.4907,0.7086
|
| 106 |
+
ViT-B-32,commonpool_m_image_s128m_b4k,151.28,14.78,0.3166,0.2678,0.6650,0.7815,0.5203,0.1298,0.2248,0.0466,0.1910,0.2261,0.0219,0.3553,0.1513,0.1623,0.2183,0.0385,0.3795,0.2959,0.2996,0.1079,0.1837,0.2383,0.3482,0.6147,0.5742,0.5266,0.2275,0.1593,0.8171,0.3706,0.1294,0.0149,0.6905,0.0000,0.4638,0.6397
|
| 107 |
+
ViT-B-32,commonpool_m_text_s128m_b4k,151.28,14.78,0.3116,0.2548,0.6632,0.8164,0.5133,0.1891,0.2449,0.0355,0.1995,0.3587,0.0212,0.3568,0.1048,0.1655,0.2142,0.0431,0.3705,0.3107,0.2897,0.1034,0.1889,0.2184,0.2991,0.5355,0.5495,0.5008,0.2627,0.1935,0.7966,0.3535,0.1265,0.0063,0.5336,0.0000,0.4544,0.6317
|
| 108 |
+
ViT-B-32,commonpool_m_laion_s128m_b4k,151.28,14.78,0.2970,0.2304,0.6312,0.7744,0.5009,0.1623,0.2261,0.0345,0.2043,0.1880,0.0169,0.3131,0.0906,0.1515,0.1895,0.0424,0.3480,0.2801,0.2827,0.1520,0.1763,0.2090,0.2973,0.5302,0.6225,0.4964,0.2470,0.2189,0.7774,0.3327,0.0881,0.0167,0.5054,0.0000,0.4357,0.6234
|
| 109 |
+
RN101-quickgelu,yfcc15m,119.69,25.5,0.2967,0.3487,0.5437,0.5298,0.2262,0.1609,0.2504,0.0683,0.1851,0.2030,0.0420,0.4686,0.0940,0.0888,0.3003,0.1568,0.3370,0.2643,0.2068,0.1239,0.1988,0.4942,0.2970,0.4603,0.5004,0.4992,0.2138,0.0373,0.8661,0.4085,0.0781,0.0357,0.5000,0.0546,0.4930,0.6483
|
| 110 |
+
RN101,yfcc15m,119.69,25.5,0.2964,0.3407,0.5538,0.5048,0.2197,0.1369,0.2257,0.0699,0.1899,0.2076,0.0443,0.4729,0.1092,0.0888,0.2933,0.1611,0.3240,0.2629,0.2138,0.1086,0.1991,0.4886,0.3068,0.4886,0.5013,0.4920,0.2011,0.0381,0.8803,0.4235,0.1348,0.0371,0.5000,0.0000,0.5035,0.6509
|
| 111 |
+
ViT-B-32,commonpool_m_basic_s128m_b4k,151.28,14.78,0.2878,0.2255,0.6118,0.6321,0.3531,0.1417,0.2217,0.0423,0.1973,0.2191,0.0155,0.3165,0.1225,0.1434,0.1820,0.0383,0.3505,0.2684,0.2982,0.1229,0.1754,0.1853,0.2752,0.5323,0.5402,0.5014,0.2305,0.2900,0.7793,0.3490,0.0638,0.0133,0.5137,0.0285,0.4591,0.6322
|
| 112 |
+
RN50,yfcc15m,102.01,18.18,0.2784,0.3238,0.5095,0.4943,0.1862,0.1315,0.2003,0.0642,0.1745,0.1811,0.0373,0.4304,0.0844,0.0729,0.2806,0.1371,0.3265,0.2231,0.2602,0.1004,0.1824,0.4680,0.2777,0.3888,0.5331,0.4992,0.1494,0.0429,0.8161,0.3999,0.0640,0.0324,0.5256,0.0501,0.4673,0.6289
|
| 113 |
+
RN50-quickgelu,yfcc15m,102.01,18.18,0.2747,0.3275,0.5089,0.4919,0.2033,0.1305,0.1990,0.0637,0.1729,0.1596,0.0371,0.4493,0.0956,0.0715,0.2793,0.1373,0.3315,0.2220,0.2560,0.0924,0.1772,0.4718,0.2771,0.3845,0.5131,0.4992,0.1424,0.0407,0.7914,0.3919,0.0642,0.0261,0.5058,0.0000,0.4638,0.6343
|
| 114 |
+
ViT-B-32,commonpool_m_s128m_b4k,151.28,14.78,0.2614,0.1755,0.5231,0.7459,0.4391,0.1263,0.2265,0.0362,0.1606,0.2537,0.0115,0.2342,0.0869,0.0952,0.1440,0.0388,0.2780,0.1983,0.2743,0.0933,0.1574,0.1128,0.1676,0.5448,0.5048,0.5003,0.1810,0.1332,0.7690,0.3066,0.0933,0.0127,0.5015,0.0000,0.4276,0.5942
|
| 115 |
+
ViT-B-32,commonpool_s_clip_s13m_b4k,151.28,14.78,0.1778,0.0505,0.2483,0.4768,0.1937,0.1529,0.2313,0.0119,0.0782,0.2067,0.0083,0.0801,0.0732,0.0200,0.0380,0.0181,0.1380,0.0655,0.2785,0.0874,0.0506,0.0539,0.0796,0.3379,0.6367,0.5014,0.0806,0.0276,0.5353,0.1126,0.1166,0.0004,0.6874,0.0000,0.2605,0.2827
|
| 116 |
+
ViT-B-32,commonpool_s_text_s13m_b4k,151.28,14.78,0.1601,0.0460,0.2231,0.4679,0.1844,0.1350,0.1899,0.0121,0.0670,0.0896,0.0139,0.0618,0.0411,0.0175,0.0398,0.0187,0.1270,0.0606,0.3980,0.0771,0.0494,0.0428,0.0581,0.2942,0.5027,0.5008,0.1029,0.0204,0.5019,0.1051,0.0933,0.0015,0.5000,0.0000,0.2745,0.2843
|
| 117 |
+
ViT-B-32,commonpool_s_image_s13m_b4k,151.28,14.78,0.1492,0.0392,0.2238,0.3176,0.1329,0.1121,0.2217,0.0109,0.0521,0.1593,0.0120,0.0604,0.0579,0.0186,0.0308,0.0155,0.1055,0.0578,0.2883,0.0991,0.0436,0.0528,0.0474,0.2666,0.5273,0.4646,0.0794,0.0173,0.4601,0.0725,0.1305,0.0033,0.5425,0.0085,0.2150,0.2752
|
| 118 |
+
ViT-B-32,datacomp_s_s13m_b4k,151.28,14.78,0.1492,0.0392,0.2238,0.3176,0.1329,0.1121,0.2217,0.0109,0.0521,0.1593,0.0120,0.0604,0.0579,0.0186,0.0308,0.0155,0.1055,0.0578,0.2883,0.0991,0.0436,0.0528,0.0474,0.2666,0.5273,0.4646,0.0794,0.0173,0.4601,0.0725,0.1305,0.0033,0.5425,0.0085,0.2150,0.2752
|
| 119 |
+
ViT-B-32,commonpool_s_basic_s13m_b4k,151.28,14.78,0.1445,0.0377,0.1806,0.2664,0.1154,0.1245,0.2335,0.0120,0.0553,0.0587,0.0103,0.0588,0.0638,0.0151,0.0319,0.0203,0.0985,0.0499,0.3390,0.1085,0.0440,0.0351,0.0488,0.3081,0.5096,0.4986,0.0795,0.0200,0.4659,0.0879,0.0810,0.0003,0.5001,0.0000,0.2325,0.2643
|
| 120 |
+
ViT-B-32,commonpool_s_s13m_b4k,151.28,14.78,0.1441,0.0270,0.1564,0.4079,0.1296,0.1305,0.2233,0.0126,0.0574,0.1487,0.0081,0.0473,0.0654,0.0108,0.0234,0.0141,0.1000,0.0404,0.3460,0.0708,0.0360,0.0338,0.0443,0.2235,0.5268,0.5008,0.0698,0.0143,0.4266,0.0766,0.1121,0.0002,0.5124,0.0000,0.2290,0.2167
|
| 121 |
+
ViT-B-32,commonpool_s_laion_s13m_b4k,151.28,14.78,0.1367,0.0305,0.1549,0.3364,0.1347,0.1309,0.1299,0.0098,0.0553,0.1578,0.0134,0.0501,0.0538,0.0125,0.0271,0.0147,0.1015,0.0443,0.2518,0.1387,0.0369,0.0244,0.0399,0.3030,0.4216,0.4992,0.0583,0.0155,0.4874,0.0659,0.1473,0.0017,0.3703,0.0000,0.2079,0.2580
|
| 122 |
+
coca_ViT-B-32,mscoco_finetuned_laion2b_s13b_b90k,253.56,33.34,0.1133,0.0079,0.0320,0.2564,0.0193,0.1245,0.2027,0.0044,0.0303,0.1157,0.0064,0.0159,0.0146,0.0028,0.0067,0.0121,0.0220,0.0199,0.3010,0.1506,0.0144,0.0054,0.0416,0.2023,0.5713,0.4992,0.0478,0.0056,0.2579,0.0204,0.1529,0.0004,0.5681,0.0000,0.1729,0.0589
|
hlip/open_clip/docs/openclip_multilingual_retrieval_results.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
hlip/open_clip/docs/openclip_results.csv
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name,pretrained,params (M),FLOPs (B),Average perf. on 38 datasets,ImageNet 1k,Caltech-101,CIFAR-10,CIFAR-100,CLEVR Counts,CLEVR Distance,Country211,Describable Textures,EuroSAT,FGVC Aircraft,Food-101,GTSRB,ImageNet Sketch,ImageNet v2,ImageNet-A,ImageNet-O,ImageNet-R,KITTI Vehicle Distance,MNIST,ObjectNet,Oxford Flowers-102,Oxford-IIIT Pet,Pascal VOC 2007,PatchCamelyon,Rendered SST2,RESISC45,Stanford Cars,STL-10,SUN397,SVHN,Flickr,MSCOCO,WinoGAViL,iWildCam,Camelyon17,FMoW,Dollar Street,GeoDE
|
| 2 |
+
ViT-H-14-378-quickgelu,dfn5b,986.71,1054.05,0.7079,0.8437,0.9517,0.9880,0.9043,0.3596,0.2085,0.3787,0.7106,0.6133,0.7219,0.9623,0.6782,0.7324,0.7833,0.7964,0.3810,0.9376,0.3966,0.8364,0.7340,0.8935,0.9696,0.8241,0.6964,0.5546,0.7589,0.9598,0.9906,0.7733,0.6739,0.8801,0.6376,0.5674,0.2205,0.7211,0.2075,0.7173,0.9349
|
| 3 |
+
ViT-H-14-quickgelu,dfn5b,986.11,381.68,0.6961,0.8344,0.9552,0.9878,0.9051,0.2967,0.2117,0.3442,0.7064,0.6546,0.7147,0.9568,0.6772,0.7274,0.7736,0.6987,0.3810,0.9296,0.3347,0.8579,0.6813,0.8995,0.9658,0.8184,0.6539,0.5464,0.7508,0.9580,0.9890,0.7691,0.6764,0.8646,0.6311,0.5561,0.2025,0.7050,0.2079,0.7009,0.9286
|
| 4 |
+
EVA02-E-14-plus,laion2b_s9b_b144k,5044.89,2362.19,0.6930,0.8201,0.9535,0.9934,0.9316,0.2991,0.1998,0.3564,0.6777,0.7574,0.5360,0.9496,0.6740,0.7162,0.7564,0.8223,0.3540,0.9456,0.1842,0.7463,0.7937,0.8433,0.9567,0.8569,0.6442,0.6271,0.7490,0.9457,0.9926,0.7510,0.7560,0.8648,0.5991,0.4403,0.2591,0.6948,0.2668,0.6951,0.9244
|
| 5 |
+
ViT-SO400M-14-SigLIP-384,webli,877.96,723.48,0.6921,0.8308,0.9599,0.9672,0.8357,0.4071,0.2246,0.3645,0.7303,0.6354,0.6069,0.9635,0.6429,0.7454,0.7717,0.8247,0.2775,0.9575,0.2082,0.8862,0.7695,0.9114,0.9680,0.7171,0.5268,0.7002,0.7211,0.9521,0.9930,0.7541,0.5151,0.8863,0.6331,0.5754,0.2294,0.6149,0.3309,0.7301,0.9328
|
| 6 |
+
ViT-bigG-14-CLIPA-336,datacomp1b,2517.76,2271.58,0.6842,0.8309,0.9529,0.9904,0.9123,0.1399,0.2161,0.4094,0.7293,0.6457,0.5561,0.9623,0.6407,0.7454,0.7726,0.8599,0.3130,0.9535,0.2630,0.8533,0.7966,0.8694,0.9562,0.8162,0.5411,0.6420,0.7257,0.9542,0.9956,0.7645,0.6691,0.8524,0.5909,0.4487,0.2383,0.5874,0.1766,0.6869,0.9407
|
| 7 |
+
ViT-bigG-14-CLIPA,datacomp1b,2517.22,1007.93,0.6822,0.8270,0.9513,0.9912,0.9135,0.1357,0.2113,0.3921,0.7207,0.6861,0.5576,0.9583,0.6460,0.7431,0.7699,0.8179,0.3075,0.9512,0.2743,0.8544,0.7694,0.8693,0.9576,0.8188,0.5345,0.6332,0.7137,0.9560,0.9965,0.7642,0.6811,0.8488,0.5888,0.4383,0.2269,0.5955,0.1959,0.6869,0.9382
|
| 8 |
+
ViT-SO400M-14-SigLIP,webli,877.36,233.54,0.6808,0.8203,0.9600,0.9679,0.8417,0.4210,0.2213,0.3243,0.7106,0.6274,0.6029,0.9556,0.6382,0.7402,0.7607,0.7185,0.2960,0.9506,0.2489,0.8929,0.7060,0.8982,0.9522,0.7034,0.5057,0.6936,0.7257,0.9032,0.9939,0.7436,0.5670,0.8313,0.6071,0.5665,0.1915,0.6215,0.3163,0.7173,0.9278
|
| 9 |
+
EVA02-E-14,laion2b_s4b_b115k,4704.59,2311.42,0.6690,0.8196,0.9541,0.9925,0.9258,0.1632,0.2499,0.3482,0.6878,0.7446,0.4892,0.9523,0.6729,0.7151,0.7566,0.8044,0.3340,0.9407,0.1294,0.7581,0.7674,0.8210,0.9569,0.8136,0.4972,0.5859,0.7324,0.9438,0.9926,0.7658,0.6381,0.8515,0.5892,0.4429,0.2289,0.4894,0.2801,0.6682,0.9182
|
| 10 |
+
ViT-L-14-quickgelu,dfn2b,427.62,175.33,0.6687,0.8141,0.9532,0.9836,0.8837,0.3325,0.2481,0.2823,0.6606,0.6493,0.3936,0.9457,0.6168,0.6832,0.7461,0.6677,0.3930,0.9000,0.2011,0.8470,0.7397,0.8654,0.9555,0.8162,0.6318,0.5502,0.7327,0.9470,0.9768,0.7546,0.6525,0.8253,0.5708,0.5519,0.1883,0.6237,0.2237,0.6916,0.9111
|
| 11 |
+
ViT-L-16-SigLIP-384,webli,652.48,422.91,0.6683,0.8207,0.9611,0.9605,0.8188,0.3275,0.2077,0.2470,0.7080,0.5817,0.5312,0.9564,0.6385,0.7360,0.7593,0.7663,0.3130,0.9507,0.2222,0.8525,0.7284,0.8934,0.9681,0.7172,0.5466,0.5634,0.6789,0.9493,0.9924,0.7250,0.5672,0.8756,0.6290,0.5550,0.2236,0.6637,0.1489,0.6916,0.9207
|
| 12 |
+
ViT-H-14-CLIPA-336,datacomp1b,968.64,800.88,0.6677,0.8180,0.9467,0.9890,0.8968,0.1326,0.2254,0.3551,0.7197,0.6604,0.4718,0.9572,0.5816,0.7282,0.7562,0.8275,0.3115,0.9438,0.2574,0.8245,0.7742,0.8463,0.9573,0.8134,0.4979,0.6052,0.7114,0.9483,0.9955,0.7635,0.6599,0.8356,0.5822,0.4587,0.2239,0.4357,0.2500,0.6822,0.9278
|
| 13 |
+
ViT-H-14-quickgelu,metaclip_fullcc,986.11,381.68,0.6671,0.8051,0.9536,0.9804,0.8634,0.2115,0.1881,0.3716,0.7271,0.6450,0.5114,0.9423,0.6257,0.7052,0.7417,0.7533,0.3040,0.9342,0.2771,0.7266,0.7642,0.8448,0.9561,0.7495,0.6222,0.6925,0.7024,0.8990,0.9944,0.7440,0.5910,0.8507,0.5752,0.5312,0.1680,0.5782,0.2314,0.6811,0.9077
|
| 14 |
+
ViT-bigG-14,laion2b_s39b_b160k,2539.57,1065.36,0.6667,0.8009,0.9484,0.9824,0.8752,0.2989,0.2002,0.3379,0.6867,0.6919,0.4953,0.9309,0.6244,0.6894,0.7359,0.6933,0.3785,0.9213,0.1308,0.7157,0.7284,0.8163,0.9529,0.8077,0.6364,0.6535,0.7235,0.9460,0.9850,0.7450,0.6961,0.8623,0.5938,0.4488,0.1760,0.5905,0.2352,0.6857,0.9127
|
| 15 |
+
ViT-H-14-CLIPA,datacomp1b,968.24,354.02,0.6653,0.8152,0.9458,0.9888,0.8991,0.1513,0.2255,0.3401,0.7090,0.7146,0.4751,0.9554,0.5538,0.7272,0.7498,0.7701,0.3135,0.9426,0.2461,0.8189,0.7423,0.8437,0.9559,0.8170,0.4958,0.6189,0.7098,0.9458,0.9948,0.7608,0.6622,0.8344,0.5804,0.4578,0.2160,0.4415,0.2684,0.6694,0.9236
|
| 16 |
+
ViT-L-14,datacomp_xl_s13b_b90k,427.62,175.33,0.6627,0.7921,0.9465,0.9824,0.8736,0.3555,0.2443,0.3157,0.6649,0.7124,0.4750,0.9452,0.5853,0.6795,0.7205,0.6959,0.3255,0.9083,0.2785,0.8661,0.7425,0.8262,0.9506,0.8247,0.5118,0.6101,0.6941,0.9305,0.9925,0.7427,0.6769,0.8119,0.5451,0.4666,0.1614,0.5089,0.2403,0.6624,0.9152
|
| 17 |
+
EVA01-g-14-plus,merged2b_s11b_b114k,1366.62,581.15,0.6624,0.7933,0.9506,0.9910,0.9008,0.2302,0.2293,0.3087,0.6734,0.7280,0.3947,0.9366,0.6644,0.6814,0.7214,0.7416,0.3415,0.9246,0.1491,0.7176,0.7491,0.7959,0.9490,0.8285,0.6244,0.5854,0.7079,0.9073,0.9949,0.7426,0.5951,0.8535,0.5925,0.4684,0.1882,0.7100,0.2283,0.6589,0.9148
|
| 18 |
+
ViT-L-14-quickgelu,metaclip_fullcc,427.62,175.33,0.6592,0.7917,0.9527,0.9759,0.8410,0.3107,0.2260,0.3394,0.6862,0.5894,0.4537,0.9352,0.5623,0.6896,0.7256,0.7231,0.3010,0.9205,0.2785,0.6444,0.7457,0.8143,0.9461,0.8030,0.6197,0.6678,0.7360,0.8868,0.9933,0.7355,0.4681,0.8326,0.5576,0.5357,0.1581,0.7551,0.2592,0.6752,0.9140
|
| 19 |
+
EVA02-L-14-336,merged2b_s6b_b61k,428.08,395.16,0.6583,0.8039,0.9525,0.9892,0.8980,0.3635,0.2485,0.3354,0.6473,0.7139,0.3758,0.9421,0.5759,0.6891,0.7380,0.8289,0.2850,0.9324,0.2377,0.6421,0.7789,0.7645,0.9424,0.8267,0.5487,0.6463,0.6910,0.9158,0.9966,0.7480,0.4575,0.8381,0.5605,0.5053,0.2105,0.5691,0.2198,0.6811,0.9136
|
| 20 |
+
ViT-L-14-CLIPA-336,datacomp1b,414.54,387.39,0.6570,0.8026,0.9439,0.9864,0.8826,0.1566,0.2439,0.3066,0.6856,0.5811,0.4281,0.9456,0.5695,0.7087,0.7346,0.7771,0.3290,0.9329,0.1997,0.7667,0.7317,0.8100,0.9495,0.7979,0.6028,0.5316,0.6884,0.9407,0.9929,0.7560,0.6290,0.8251,0.5640,0.4449,0.1937,0.6783,0.2500,0.6752,0.9240
|
| 21 |
+
ViT-L-16-SigLIP-256,webli,652.15,201.62,0.6557,0.8045,0.9593,0.9619,0.8191,0.4065,0.2150,0.2141,0.7027,0.5598,0.5259,0.9463,0.6115,0.7209,0.7376,0.6213,0.3265,0.9396,0.1983,0.8499,0.6526,0.8827,0.9604,0.7409,0.5458,0.6172,0.6817,0.9386,0.9911,0.7253,0.5211,0.8542,0.6154,0.5748,0.1796,0.5757,0.1296,0.6904,0.9173
|
| 22 |
+
ViT-L-14-CLIPA,datacomp1b,414.21,167.5,0.6536,0.7957,0.9453,0.9866,0.8850,0.1857,0.2449,0.2941,0.6963,0.6044,0.4299,0.9415,0.5906,0.7061,0.7305,0.7125,0.3370,0.9288,0.1927,0.7374,0.6988,0.8101,0.9497,0.8067,0.5915,0.5387,0.6843,0.9366,0.9919,0.7528,0.6390,0.8188,0.5604,0.4388,0.1724,0.6760,0.2457,0.6647,0.9152
|
| 23 |
+
convnext_xxlarge,laion2b_s34b_b82k_augreg_soup,1200.58,443.03,0.6530,0.7947,0.9448,0.9822,0.8687,0.1454,0.2365,0.3170,0.7053,0.6128,0.4434,0.9321,0.5508,0.6840,0.7260,0.6719,0.4060,0.9160,0.2363,0.8277,0.7273,0.8241,0.9445,0.8090,0.5142,0.6952,0.7190,0.9409,0.9810,0.7458,0.6254,0.8521,0.5867,0.4702,0.1730,0.6071,0.0000,0.6764,0.9215
|
| 24 |
+
convnext_xxlarge,laion2b_s34b_b82k_augreg_rewind,1200.58,443.03,0.6521,0.7931,0.9452,0.9823,0.8686,0.1651,0.2534,0.3155,0.7016,0.6331,0.4398,0.9308,0.5491,0.6825,0.7228,0.6657,0.3975,0.9139,0.2419,0.7930,0.7252,0.8241,0.9438,0.8100,0.5014,0.6897,0.7168,0.9406,0.9801,0.7459,0.6137,0.8498,0.5871,0.4741,0.1735,0.6071,0.0000,0.6799,0.9228
|
| 25 |
+
xlm-roberta-large-ViT-H-14,frozen_laion5b_s13b_b90k,1193.01,671.01,0.6515,0.7695,0.9422,0.9718,0.8430,0.3358,0.2050,0.3172,0.6926,0.6793,0.4673,0.9236,0.6239,0.6581,0.6944,0.5935,0.3390,0.8940,0.1364,0.7804,0.6911,0.7532,0.9431,0.7995,0.5792,0.6436,0.6825,0.9362,0.9889,0.7551,0.5950,0.8461,0.5758,0.5206,0.1392,0.6749,0.2098,0.6460,0.9111
|
| 26 |
+
ViT-L-14,commonpool_xl_clip_s13b_b90k,427.62,175.33,0.6501,0.7637,0.9502,0.9797,0.8615,0.2547,0.2451,0.2984,0.6521,0.6681,0.3860,0.9355,0.5980,0.6538,0.6953,0.6197,0.3525,0.8924,0.2982,0.9040,0.7165,0.8006,0.9424,0.8336,0.5688,0.6178,0.6978,0.9352,0.9875,0.7351,0.6853,0.7768,0.5156,0.4728,0.1439,0.5100,0.1705,0.6776,0.9056
|
| 27 |
+
EVA02-L-14,merged2b_s4b_b131k,427.76,175.3,0.6488,0.7977,0.9512,0.9908,0.9071,0.3176,0.2462,0.3091,0.6319,0.6994,0.3638,0.9340,0.5718,0.6813,0.7295,0.7619,0.2880,0.9272,0.2518,0.6729,0.7489,0.7631,0.9398,0.8220,0.5431,0.6150,0.6968,0.9055,0.9961,0.7410,0.4793,0.8351,0.5556,0.5081,0.1886,0.5124,0.2017,0.6624,0.9073
|
| 28 |
+
convnext_xxlarge,laion2b_s34b_b82k_augreg,1200.58,443.03,0.6479,0.7907,0.9429,0.9816,0.8677,0.1399,0.1195,0.3127,0.7096,0.6030,0.4250,0.9295,0.5454,0.6806,0.7223,0.6692,0.4025,0.9131,0.2616,0.8687,0.7235,0.8091,0.9455,0.8116,0.5340,0.6782,0.7100,0.9399,0.9824,0.7436,0.6379,0.8531,0.5834,0.4536,0.1616,0.5719,0.0000,0.6729,0.9228
|
| 29 |
+
ViT-B-16-SigLIP-512,webli,203.79,227.26,0.6459,0.7914,0.9516,0.9265,0.7146,0.2411,0.2226,0.1927,0.6793,0.4007,0.4521,0.9394,0.5171,0.6990,0.7283,0.6769,0.3615,0.9264,0.3924,0.8288,0.6764,0.8677,0.9499,0.7139,0.6615,0.5722,0.6538,0.9249,0.9853,0.7152,0.5444,0.8578,0.5963,0.5696,0.1925,0.6606,0.1411,0.6928,0.9244
|
| 30 |
+
ViT-H-14-CLIPA-336,laion2b,968.64,800.88,0.6439,0.7910,0.9438,0.9826,0.8643,0.1835,0.2158,0.3111,0.7160,0.6393,0.3437,0.9303,0.5007,0.6994,0.7241,0.7213,0.3655,0.9269,0.1561,0.6365,0.7022,0.8009,0.9444,0.7723,0.5787,0.6178,0.7029,0.9476,0.9894,0.7567,0.6255,0.8522,0.5883,0.4878,0.1853,0.5001,0.1666,0.6706,0.9257
|
| 31 |
+
ViT-g-14,laion2b_s34b_b88k,1366.68,581.15,0.6427,0.7847,0.9452,0.9815,0.8465,0.3768,0.1870,0.3091,0.6856,0.6530,0.4441,0.9241,0.4964,0.6754,0.7158,0.6092,0.3705,0.9020,0.2700,0.7191,0.6908,0.8010,0.9379,0.8166,0.5384,0.5678,0.6960,0.9394,0.9893,0.7411,0.5611,0.8456,0.5758,0.4104,0.1524,0.4771,0.2090,0.6671,0.9090
|
| 32 |
+
ViT-H-14,laion2b_s32b_b79k,986.11,381.68,0.6419,0.7796,0.9421,0.9745,0.8473,0.2676,0.2358,0.2986,0.6782,0.7278,0.4265,0.9273,0.5832,0.6657,0.7090,0.5935,0.3825,0.8934,0.1097,0.7284,0.6941,0.7982,0.9438,0.7768,0.5430,0.6392,0.6995,0.9338,0.9848,0.7521,0.5252,0.8417,0.5770,0.4247,0.1528,0.5638,0.2264,0.6343,0.9086
|
| 33 |
+
convnext_large_d_320,laion2b_s29b_b131k_ft_soup,351.77,157.98,0.6387,0.7685,0.9348,0.9659,0.8304,0.4293,0.2010,0.2654,0.6830,0.7161,0.3621,0.9162,0.5822,0.6504,0.6944,0.6044,0.4410,0.8862,0.1027,0.7434,0.6898,0.7755,0.9358,0.8129,0.4814,0.5585,0.7078,0.9369,0.9856,0.7376,0.6712,0.8467,0.5665,0.4549,0.1786,0.4088,0.1901,0.6449,0.9094
|
| 34 |
+
ViT-B-16-SigLIP-384,webli,203.45,123.15,0.6379,0.7849,0.9507,0.9276,0.7147,0.2195,0.2239,0.1858,0.6718,0.4307,0.4522,0.9362,0.5196,0.6955,0.7211,0.6233,0.3640,0.9214,0.3333,0.8088,0.6343,0.8624,0.9515,0.7162,0.7010,0.5607,0.6579,0.9245,0.9863,0.7096,0.5285,0.8559,0.5882,0.5719,0.1719,0.5931,0.1365,0.6846,0.9194
|
| 35 |
+
ViT-L-14,commonpool_xl_laion_s13b_b90k,427.62,175.33,0.6360,0.7545,0.9352,0.9796,0.8585,0.3819,0.2489,0.2503,0.6191,0.7378,0.2869,0.9200,0.6018,0.6352,0.6851,0.5747,0.3730,0.8708,0.1378,0.7740,0.6846,0.7435,0.9308,0.8107,0.5069,0.5986,0.7065,0.8912,0.9903,0.7327,0.5730,0.8130,0.5513,0.4966,0.1421,0.5671,0.2337,0.6600,0.9115
|
| 36 |
+
EVA01-g-14,laion400m_s11b_b41k,1136.44,547.36,0.6358,0.7852,0.9477,0.9829,0.8865,0.1966,0.2467,0.2862,0.6144,0.7237,0.3226,0.9345,0.4913,0.6730,0.7152,0.7359,0.3285,0.9250,0.2405,0.6218,0.7200,0.7427,0.9414,0.8325,0.4987,0.5832,0.6976,0.9171,0.9889,0.7416,0.5889,0.8037,0.5293,0.4640,0.1975,0.4999,0.1859,0.6741,0.8969
|
| 37 |
+
convnext_large_d_320,laion2b_s29b_b131k_ft,351.77,157.98,0.6345,0.7660,0.9341,0.9647,0.8313,0.3688,0.1999,0.2673,0.6846,0.7131,0.3770,0.9160,0.5688,0.6472,0.6929,0.5933,0.4400,0.8823,0.1027,0.7695,0.6813,0.7696,0.9346,0.8002,0.4576,0.5623,0.6989,0.9348,0.9854,0.7355,0.6496,0.8415,0.5599,0.4558,0.1664,0.4342,0.1782,0.6355,0.9090
|
| 38 |
+
coca_ViT-L-14,laion2b_s13b_b90k,638.45,214.52,0.6327,0.7561,0.9430,0.9722,0.8318,0.3781,0.2446,0.2551,0.6239,0.6752,0.3590,0.9038,0.5624,0.6453,0.6798,0.5336,0.3540,0.8812,0.1899,0.7790,0.6405,0.7643,0.9402,0.8096,0.5500,0.6634,0.6878,0.9276,0.9894,0.7406,0.6237,0.8134,0.5428,0.4739,0.1375,0.4268,0.1932,0.6542,0.8960
|
| 39 |
+
ViT-g-14,laion2b_s12b_b42k,1366.68,581.15,0.6299,0.7663,0.9415,0.9706,0.8392,0.3317,0.2225,0.2878,0.6824,0.6469,0.3768,0.9155,0.4985,0.6516,0.6956,0.5716,0.3785,0.8869,0.1350,0.6840,0.6761,0.7800,0.9431,0.8108,0.5624,0.6425,0.7176,0.9292,0.9865,0.7541,0.3930,0.8366,0.5647,0.4427,0.1486,0.4948,0.2040,0.6542,0.9132
|
| 40 |
+
convnext_large_d,laion2b_s26b_b102k_augreg,351.77,107.5,0.6294,0.7591,0.9365,0.9655,0.8309,0.3461,0.1997,0.2525,0.6739,0.6959,0.3610,0.9055,0.5299,0.6430,0.6826,0.5352,0.4425,0.8767,0.1027,0.8063,0.6618,0.7667,0.9282,0.7891,0.5309,0.5612,0.6768,0.9316,0.9829,0.7307,0.6812,0.8384,0.5550,0.4646,0.1549,0.3964,0.1793,0.6402,0.9019
|
| 41 |
+
ViT-L-14-336,openai,427.94,395.22,0.6284,0.7656,0.9225,0.9493,0.7436,0.2003,0.1895,0.3445,0.5559,0.6144,0.3346,0.9386,0.5239,0.6100,0.7089,0.7748,0.3265,0.8905,0.2616,0.7916,0.7183,0.7852,0.9369,0.7815,0.6073,0.7057,0.6379,0.7932,0.9943,0.6865,0.5560,0.7730,0.4751,0.4145,0.1490,0.6456,0.2325,0.6390,0.9015
|
| 42 |
+
ViT-L-14-quickgelu,metaclip_400m,427.62,175.33,0.6252,0.7620,0.9464,0.9544,0.7727,0.2271,0.2514,0.3085,0.6245,0.6033,0.3983,0.9073,0.4755,0.6505,0.6977,0.6640,0.2895,0.8889,0.2419,0.6186,0.6923,0.7648,0.9381,0.7440,0.7039,0.6551,0.6848,0.8477,0.9928,0.7073,0.3239,0.7981,0.5191,0.5175,0.1408,0.6916,0.1874,0.6741,0.8931
|
| 43 |
+
ViT-B-16-SigLIP,webli,203.16,46.44,0.6232,0.7604,0.9518,0.9234,0.7223,0.2373,0.2409,0.1594,0.6468,0.4428,0.4377,0.9162,0.5164,0.6792,0.6893,0.4541,0.3815,0.9030,0.4093,0.8354,0.5509,0.8549,0.9420,0.7212,0.5953,0.5244,0.6454,0.9081,0.9821,0.7001,0.5586,0.8189,0.5676,0.5738,0.1309,0.6045,0.1265,0.6589,0.9106
|
| 44 |
+
ViT-B-16-SigLIP-256,webli,203.2,57.84,0.6226,0.7653,0.9496,0.9334,0.7327,0.2276,0.2340,0.1581,0.6574,0.4606,0.4473,0.9200,0.4940,0.6810,0.6920,0.4877,0.3785,0.9076,0.3685,0.8457,0.5723,0.8521,0.9424,0.7254,0.5657,0.5739,0.6440,0.9106,0.9818,0.7026,0.5399,0.8272,0.5724,0.5715,0.1493,0.4966,0.1253,0.6589,0.9061
|
| 45 |
+
ViT-L-14,commonpool_xl_s13b_b90k,427.62,175.33,0.6207,0.7229,0.9327,0.9801,0.8410,0.1985,0.2461,0.2962,0.6202,0.6889,0.1957,0.9107,0.5467,0.6118,0.6511,0.5625,0.2855,0.8594,0.3390,0.9084,0.7022,0.6966,0.9060,0.8076,0.5248,0.5953,0.5756,0.8939,0.9890,0.7103,0.6589,0.7339,0.4652,0.5072,0.1229,0.5246,0.1948,0.6811,0.8990
|
| 46 |
+
ViT-L-14,laion2b_s32b_b82k,427.62,175.33,0.6205,0.7525,0.9388,0.9662,0.8332,0.3123,0.2234,0.2631,0.6293,0.6459,0.3652,0.9100,0.5618,0.6328,0.6780,0.5385,0.3870,0.8742,0.2293,0.5410,0.6529,0.7479,0.9309,0.8053,0.5641,0.5925,0.6687,0.9263,0.9885,0.7434,0.4087,0.8251,0.5493,0.4385,0.1257,0.5972,0.2007,0.6402,0.8919
|
| 47 |
+
ViT-L-14,openai,427.62,175.33,0.6173,0.7554,0.9249,0.9559,0.7582,0.1943,0.2021,0.3187,0.5537,0.6263,0.3181,0.9305,0.5055,0.5959,0.6983,0.7075,0.3235,0.8784,0.2180,0.7634,0.6889,0.7923,0.9323,0.7828,0.5204,0.6881,0.6337,0.7788,0.9936,0.6756,0.5840,0.7508,0.4642,0.4136,0.1211,0.6741,0.2229,0.6297,0.8839
|
| 48 |
+
coca_ViT-L-14,mscoco_finetuned_laion2b_s13b_b90k,638.45,214.52,0.6159,0.7204,0.9420,0.9630,0.7965,0.3765,0.2501,0.1800,0.6213,0.5867,0.2329,0.8436,0.5453,0.6114,0.6475,0.4548,0.3865,0.8574,0.3797,0.8292,0.6253,0.7074,0.9115,0.8106,0.4943,0.6107,0.6267,0.8865,0.9861,0.7398,0.5564,0.8373,0.6028,0.5146,0.1303,0.4294,0.1678,0.6636,0.8772
|
| 49 |
+
ViT-B-16,datacomp_xl_s13b_b90k,149.62,41.09,0.6147,0.7349,0.9380,0.9624,0.8212,0.3267,0.2461,0.2215,0.5793,0.5883,0.2970,0.9047,0.5523,0.6044,0.6598,0.4840,0.4285,0.8362,0.2883,0.7649,0.6350,0.7701,0.9254,0.8178,0.6002,0.5162,0.6535,0.8883,0.9811,0.7051,0.6272,0.7633,0.4880,0.4832,0.1181,0.4799,0.1504,0.6168,0.8990
|
| 50 |
+
ViT-B-16,dfn2b,149.62,41.09,0.6092,0.7624,0.9429,0.9672,0.8349,0.2327,0.2453,0.1955,0.5755,0.5402,0.2473,0.9130,0.4701,0.6204,0.6818,0.4820,0.4925,0.8310,0.1927,0.7814,0.6319,0.8201,0.9372,0.7884,0.5214,0.4876,0.6137,0.9073,0.9753,0.7143,0.5985,0.7726,0.5188,0.5417,0.1554,0.4993,0.1415,0.6250,0.8910
|
| 51 |
+
ViT-B-32-256,datacomp_s34b_b86k,151.29,17.46,0.6087,0.7281,0.9348,0.9653,0.8287,0.2489,0.2271,0.1968,0.6064,0.6469,0.3645,0.8909,0.5152,0.6065,0.6481,0.3757,0.4635,0.8344,0.2658,0.7939,0.5960,0.7822,0.9115,0.7880,0.5880,0.5294,0.6505,0.8990,0.9731,0.7021,0.6708,0.7486,0.4892,0.4300,0.0910,0.6252,0.0000,0.6238,0.8923
|
| 52 |
+
ViT-B-16-SigLIP-i18n-256,webli,370.63,57.84,0.6068,0.7513,0.9475,0.9118,0.7216,0.2552,0.1976,0.1593,0.6426,0.3826,0.3325,0.9171,0.5276,0.6588,0.6814,0.4585,0.3685,0.8920,0.3826,0.8301,0.5977,0.8387,0.9387,0.7536,0.5381,0.5700,0.5737,0.8926,0.9764,0.6978,0.4272,0.8088,0.5470,0.5710,0.1451,0.4899,0.1064,0.6472,0.9186
|
| 53 |
+
RN50x64,openai,623.26,552.65,0.6061,0.7391,0.9026,0.8510,0.5985,0.2254,0.1994,0.2981,0.5314,0.5765,0.3103,0.9205,0.4792,0.5593,0.6706,0.7077,0.3830,0.8441,0.3094,0.8583,0.6820,0.7745,0.9360,0.7398,0.5387,0.7106,0.6265,0.7581,0.9829,0.6661,0.6044,0.7794,0.4683,0.3936,0.1469,0.5280,0.1939,0.6472,0.8898
|
| 54 |
+
ViT-B-16-quickgelu,metaclip_fullcc,149.62,41.09,0.6041,0.7212,0.9328,0.9572,0.7891,0.2935,0.2260,0.2271,0.6223,0.5265,0.3059,0.8882,0.4659,0.6016,0.6505,0.4953,0.4150,0.8423,0.1871,0.6610,0.6138,0.7358,0.9175,0.7818,0.5915,0.5898,0.6744,0.8302,0.9841,0.6879,0.3909,0.7811,0.5035,0.5221,0.1227,0.6993,0.1932,0.6402,0.8868
|
| 55 |
+
ViT-L-14,laion400m_e32,427.62,175.33,0.5971,0.7277,0.9266,0.9464,0.7741,0.2421,0.2452,0.2302,0.6053,0.6233,0.2490,0.9007,0.4989,0.5964,0.6545,0.4647,0.4190,0.8467,0.1997,0.7612,0.5969,0.7306,0.9170,0.7561,0.4968,0.5601,0.6741,0.8962,0.9808,0.7258,0.4955,0.7891,0.5137,0.3932,0.1254,0.4555,0.1708,0.6168,0.8839
|
| 56 |
+
ViT-L-14,laion400m_e31,427.62,175.33,0.5964,0.7271,0.9259,0.9465,0.7738,0.2420,0.2452,0.2290,0.5973,0.6322,0.2462,0.9002,0.4965,0.5944,0.6547,0.4596,0.4225,0.8466,0.1997,0.7668,0.5962,0.7323,0.9154,0.7585,0.4877,0.5651,0.6710,0.8964,0.9804,0.7247,0.4956,0.7885,0.5129,0.3949,0.1239,0.4595,0.1651,0.6075,0.8831
|
| 57 |
+
EVA02-B-16,merged2b_s8b_b131k,149.69,41.09,0.5890,0.7472,0.9302,0.9846,0.8773,0.2125,0.2254,0.2136,0.5282,0.6635,0.2506,0.8943,0.4630,0.5771,0.6701,0.5396,0.3410,0.8244,0.2208,0.4729,0.6214,0.7245,0.9211,0.8019,0.5091,0.5415,0.6037,0.7855,0.9949,0.7064,0.2497,0.7873,0.5044,0.4722,0.1515,0.7095,0.1724,0.6086,0.8810
|
| 58 |
+
convnext_base_w_320,laion_aesthetic_s13b_b82k_augreg,179.39,71.94,0.5869,0.7128,0.9255,0.8823,0.6515,0.2825,0.2225,0.2243,0.6074,0.5124,0.2632,0.8947,0.4365,0.5646,0.6362,0.4157,0.5075,0.8136,0.2180,0.7219,0.5237,0.7524,0.9239,0.7530,0.5696,0.5508,0.6421,0.8918,0.9755,0.7037,0.4443,0.8009,0.5142,0.4293,0.1392,0.5502,0.1215,0.6297,0.8935
|
| 59 |
+
ViT-B-16,laion2b_s34b_b88k,149.62,41.09,0.5866,0.7023,0.9287,0.9494,0.7684,0.2149,0.2455,0.2029,0.5633,0.5346,0.2695,0.8663,0.4826,0.5608,0.6228,0.3823,0.4625,0.8061,0.1730,0.6577,0.5598,0.7084,0.9048,0.7886,0.5639,0.5969,0.6275,0.8848,0.9786,0.7085,0.5002,0.7807,0.5087,0.4601,0.1217,0.6249,0.1211,0.5841,0.8735
|
| 60 |
+
convnext_base_w,laion2b_s13b_b82k_augreg,179.39,49.38,0.5835,0.7147,0.9258,0.9561,0.8021,0.3307,0.2450,0.2016,0.6144,0.4828,0.2235,0.8675,0.4654,0.5890,0.6329,0.3817,0.5110,0.8253,0.2068,0.6441,0.5732,0.7017,0.9191,0.7979,0.4823,0.5925,0.6056,0.9126,0.9705,0.7113,0.5376,0.7985,0.5222,0.4390,0.1285,0.3801,0.0000,0.5935,0.8881
|
| 61 |
+
ViT-B-32,datacomp_xl_s13b_b90k,151.28,14.78,0.5795,0.6917,0.9230,0.9561,0.8031,0.1294,0.2423,0.1756,0.5713,0.5746,0.2463,0.8632,0.5185,0.5676,0.6075,0.3035,0.4975,0.7818,0.1632,0.8124,0.5510,0.7353,0.9002,0.8151,0.5284,0.4849,0.6343,0.8728,0.9654,0.6780,0.6240,0.7004,0.4534,0.4594,0.0863,0.6656,0.0000,0.5643,0.8731
|
| 62 |
+
ViT-B-16-quickgelu,metaclip_400m,149.62,41.09,0.5785,0.7080,0.9341,0.9014,0.6657,0.3010,0.2245,0.2260,0.5590,0.5572,0.2839,0.8725,0.4375,0.5789,0.6261,0.4700,0.3920,0.8177,0.2419,0.4794,0.5916,0.7229,0.9035,0.7217,0.6203,0.6046,0.6619,0.7421,0.9724,0.6678,0.2523,0.7668,0.4822,0.5113,0.1122,0.6769,0.1991,0.6063,0.8894
|
| 63 |
+
convnext_base_w,laion_aesthetic_s13b_b82k,179.39,49.38,0.5766,0.7099,0.9061,0.8305,0.6116,0.2960,0.1956,0.2228,0.6229,0.4519,0.2938,0.8847,0.4016,0.5546,0.6342,0.4123,0.4750,0.7986,0.2630,0.6739,0.5559,0.7170,0.9199,0.7548,0.5517,0.5579,0.6162,0.8661,0.9709,0.7143,0.2802,0.8093,0.5238,0.4764,0.1378,0.5859,0.1284,0.6343,0.8722
|
| 64 |
+
convnext_base_w,laion2b_s13b_b82k,179.39,49.38,0.5761,0.7078,0.9222,0.9383,0.7519,0.2385,0.1866,0.2018,0.5957,0.5678,0.2825,0.8711,0.4930,0.5712,0.6234,0.3993,0.4815,0.8070,0.1505,0.5435,0.5795,0.6955,0.9189,0.8038,0.4154,0.6041,0.6284,0.8957,0.9775,0.7128,0.3459,0.7992,0.5171,0.4706,0.1181,0.4812,0.1072,0.6075,0.8802
|
| 65 |
+
ViT-B-16-plus-240,laion400m_e32,208.38,64.03,0.5724,0.6919,0.9239,0.9273,0.7377,0.2387,0.2348,0.1894,0.5548,0.5820,0.1852,0.8734,0.4944,0.5442,0.6148,0.3689,0.4980,0.8049,0.2813,0.5709,0.5384,0.6886,0.9015,0.7636,0.5524,0.5799,0.6137,0.8448,0.9698,0.6985,0.3777,0.7730,0.4979,0.4069,0.1163,0.4876,0.1616,0.5923,0.8697
|
| 66 |
+
ViT-B-16-plus-240,laion400m_e31,208.38,64.03,0.5713,0.6904,0.9219,0.9247,0.7329,0.2413,0.2346,0.1884,0.5548,0.5702,0.1861,0.8735,0.4897,0.5443,0.6138,0.3676,0.5030,0.8038,0.2799,0.5722,0.5374,0.6825,0.9035,0.7634,0.5512,0.5859,0.6144,0.8450,0.9689,0.6991,0.3767,0.7675,0.4954,0.4093,0.1164,0.4837,0.1618,0.5841,0.8689
|
| 67 |
+
ViT-B-32,laion2b_s34b_b79k,151.28,14.78,0.5694,0.6656,0.9105,0.9358,0.7555,0.1535,0.2451,0.1667,0.5569,0.4806,0.2453,0.8269,0.4933,0.5366,0.5814,0.2627,0.4995,0.7643,0.2630,0.6996,0.4883,0.7024,0.9076,0.7910,0.5993,0.5728,0.6106,0.8607,0.9656,0.6872,0.4257,0.7544,0.4783,0.4479,0.0930,0.6392,0.1479,0.5666,0.8543
|
| 68 |
+
RN50x16,openai,290.98,162.69,0.5670,0.7072,0.8856,0.8134,0.5209,0.1953,0.2095,0.2437,0.5266,0.4328,0.2783,0.9051,0.3984,0.5063,0.6420,0.5724,0.4495,0.7933,0.2307,0.6798,0.6071,0.7188,0.8956,0.6800,0.6249,0.6771,0.5883,0.7286,0.9775,0.6391,0.4548,0.7552,0.4538,0.3946,0.1079,0.6248,0.1593,0.6121,0.8539
|
| 69 |
+
convnext_base_w_320,laion_aesthetic_s13b_b82k,179.39,71.94,0.5665,0.7167,0.9136,0.8613,0.5900,0.2283,0.2255,0.2237,0.5931,0.3519,0.2834,0.8930,0.4459,0.5639,0.6398,0.4225,0.4745,0.8054,0.0928,0.6647,0.5616,0.7165,0.9244,0.7240,0.4899,0.5541,0.6176,0.8821,0.9664,0.7161,0.2606,0.8236,0.5247,0.4610,0.1473,0.4729,0.1813,0.6273,0.8856
|
| 70 |
+
xlm-roberta-base-ViT-B-32,laion5b_s13b_b90k,366.12,105.87,0.5643,0.6236,0.9079,0.9366,0.7654,0.1675,0.2025,0.1896,0.6037,0.6006,0.2692,0.8010,0.4561,0.5071,0.5425,0.2355,0.4825,0.7410,0.1814,0.7407,0.4607,0.6235,0.8690,0.7856,0.6423,0.5354,0.6137,0.8556,0.9668,0.6785,0.5532,0.7359,0.4566,0.4827,0.0801,0.5770,0.1292,0.5771,0.8647
|
| 71 |
+
ViT-B-16,openai,149.62,41.09,0.5626,0.6834,0.8901,0.9077,0.6695,0.2123,0.2231,0.2282,0.4495,0.5594,0.2421,0.8872,0.4339,0.4824,0.6188,0.4995,0.4230,0.7770,0.2644,0.5135,0.5531,0.6907,0.8886,0.7831,0.5072,0.6068,0.5822,0.6477,0.9825,0.6435,0.5190,0.7218,0.4275,0.4316,0.1099,0.6808,0.1888,0.5876,0.8614
|
| 72 |
+
ViT-B-16,laion400m_e32,149.62,41.09,0.5621,0.6705,0.9131,0.9172,0.7116,0.2869,0.2451,0.1810,0.5133,0.5019,0.1765,0.8613,0.4346,0.5238,0.5963,0.3324,0.5075,0.7793,0.1814,0.6624,0.5152,0.6691,0.8917,0.7684,0.5960,0.5437,0.5852,0.8373,0.9698,0.6961,0.3413,0.7458,0.4688,0.4326,0.1028,0.5999,0.1546,0.5935,0.8534
|
| 73 |
+
ViT-B-16,laion400m_e31,149.62,41.09,0.5617,0.6698,0.9159,0.9169,0.7130,0.2889,0.2451,0.1804,0.5138,0.5033,0.1742,0.8587,0.4353,0.5233,0.5943,0.3327,0.5035,0.7777,0.1997,0.6531,0.5128,0.6693,0.8911,0.7678,0.5925,0.5459,0.5849,0.8365,0.9703,0.6958,0.3388,0.7451,0.4674,0.4225,0.1056,0.5976,0.1546,0.5946,0.8534
|
| 74 |
+
ViT-B-32-quickgelu,metaclip_fullcc,151.28,14.78,0.5577,0.6766,0.9290,0.9518,0.7767,0.1871,0.2307,0.1764,0.5883,0.4991,0.2705,0.8309,0.3922,0.5599,0.5957,0.2993,0.4825,0.7805,0.1871,0.4272,0.5286,0.6935,0.9087,0.7652,0.5596,0.5310,0.6124,0.7738,0.9630,0.6689,0.3447,0.7295,0.4662,0.5238,0.0915,0.5656,0.1588,0.6051,0.8610
|
| 75 |
+
convnext_base,laion400m_s13b_b51k,151.52,36.67,0.5576,0.6627,0.9151,0.8899,0.6462,0.2386,0.2209,0.1700,0.5404,0.4850,0.1556,0.8515,0.4551,0.5196,0.5859,0.3092,0.4925,0.7575,0.2925,0.6114,0.5058,0.6900,0.8853,0.7528,0.6116,0.5376,0.5683,0.8409,0.9656,0.6845,0.4038,0.7438,0.4615,0.4045,0.1095,0.6565,0.1589,0.5537,0.8530
|
| 76 |
+
coca_ViT-B-32,laion2b_s13b_b90k,253.56,33.34,0.5533,0.6331,0.9078,0.9387,0.7378,0.1831,0.2175,0.1450,0.5367,0.4602,0.1783,0.7893,0.4532,0.5121,0.5522,0.2149,0.4920,0.7376,0.2644,0.7097,0.4470,0.6226,0.8875,0.7832,0.5938,0.5766,0.5994,0.8397,0.9626,0.6736,0.5503,0.7248,0.4537,0.4698,0.0876,0.5749,0.1010,0.5724,0.8430
|
| 77 |
+
ViT-B-32,laion2b_e16,151.28,14.78,0.5483,0.6565,0.9104,0.9403,0.7544,0.1923,0.2310,0.1652,0.5383,0.5030,0.2298,0.8166,0.3655,0.5287,0.5739,0.2615,0.5030,0.7588,0.1758,0.6347,0.4877,0.6732,0.8903,0.7877,0.5072,0.5437,0.6190,0.8437,0.9653,0.6851,0.4164,0.7539,0.4768,0.4602,0.0971,0.4648,0.0000,0.5724,0.8526
|
| 78 |
+
roberta-ViT-B-32,laion2b_s12b_b32k,212.72,105.87,0.5411,0.6171,0.9039,0.9325,0.7505,0.1472,0.2007,0.1472,0.5920,0.5215,0.1725,0.7812,0.4082,0.4912,0.5331,0.2120,0.5075,0.7224,0.3854,0.6636,0.4499,0.5893,0.8670,0.7804,0.4985,0.5420,0.6117,0.8315,0.9564,0.6627,0.4526,0.7302,0.4590,0.4583,0.0606,0.4098,0.1161,0.5549,0.8426
|
| 79 |
+
ViT-B-32-quickgelu,metaclip_400m,151.28,14.78,0.5387,0.6558,0.9171,0.9125,0.7006,0.2175,0.2448,0.1716,0.5255,0.5239,0.2680,0.8106,0.3576,0.5330,0.5760,0.2863,0.4680,0.7477,0.2588,0.4144,0.5046,0.6811,0.8877,0.7081,0.6426,0.5338,0.5954,0.7060,0.9543,0.6345,0.2056,0.7007,0.4386,0.5097,0.0819,0.6443,0.0000,0.5970,0.8539
|
| 80 |
+
ViT-B-16,datacomp_l_s1b_b8k,149.62,41.09,0.5372,0.6310,0.8969,0.9381,0.7540,0.2314,0.2513,0.1434,0.4691,0.5011,0.1001,0.8311,0.4343,0.4976,0.5521,0.2545,0.4955,0.7177,0.4008,0.5400,0.5298,0.6261,0.8352,0.8089,0.4973,0.5294,0.5273,0.7718,0.9576,0.6431,0.4595,0.6428,0.4045,0.4465,0.0729,0.5000,0.0976,0.5748,0.8493
|
| 81 |
+
ViT-B-16,commonpool_l_clip_s1b_b8k,149.62,41.09,0.5294,0.5777,0.8853,0.9349,0.7313,0.2691,0.2313,0.1417,0.4500,0.4728,0.0822,0.7995,0.4657,0.4589,0.4995,0.2165,0.4950,0.6843,0.3755,0.7032,0.4914,0.5667,0.7561,0.7821,0.4962,0.5036,0.5295,0.8171,0.9496,0.6295,0.5985,0.5956,0.3658,0.4359,0.0741,0.4920,0.1257,0.5818,0.8501
|
| 82 |
+
ViT-B-32-quickgelu,laion400m_e32,151.28,14.78,0.5272,0.6293,0.9118,0.9074,0.7029,0.1624,0.2391,0.1475,0.5457,0.5143,0.1658,0.8086,0.4197,0.4939,0.5506,0.2172,0.5345,0.7342,0.2897,0.3733,0.4389,0.6620,0.8671,0.7582,0.5592,0.5228,0.5454,0.7926,0.9560,0.6700,0.3039,0.7025,0.4395,0.4072,0.0745,0.4709,0.1296,0.5491,0.8380
|
| 83 |
+
ViT-B-32-quickgelu,laion400m_e31,151.28,14.78,0.5263,0.6294,0.9121,0.9060,0.7021,0.1659,0.2397,0.1476,0.5447,0.5085,0.1675,0.8080,0.4230,0.4937,0.5487,0.2161,0.5335,0.7349,0.2911,0.3656,0.4374,0.6638,0.8629,0.7539,0.5543,0.5217,0.5446,0.7914,0.9553,0.6702,0.3144,0.7022,0.4395,0.4034,0.0788,0.4554,0.1310,0.5467,0.8363
|
| 84 |
+
ViT-B-32,openai,151.28,14.78,0.5245,0.6332,0.8758,0.8983,0.6423,0.2320,0.2335,0.1720,0.4436,0.5044,0.1953,0.8400,0.3258,0.4229,0.5592,0.3155,0.4775,0.6933,0.2743,0.4839,0.4431,0.6670,0.8700,0.7640,0.6224,0.5865,0.5362,0.5963,0.9713,0.6248,0.3159,0.6884,0.4028,0.4125,0.0732,0.6061,0.1676,0.5386,0.8217
|
| 85 |
+
ViT-B-32-quickgelu,openai,151.28,14.78,0.5245,0.6332,0.8758,0.8983,0.6423,0.2320,0.2335,0.1720,0.4436,0.5044,0.1953,0.8400,0.3258,0.4229,0.5592,0.3155,0.4775,0.6933,0.2743,0.4839,0.4431,0.6670,0.8700,0.7640,0.6224,0.5865,0.5362,0.5963,0.9713,0.6248,0.3159,0.6884,0.4028,0.4125,0.0732,0.6061,0.1676,0.5386,0.8217
|
| 86 |
+
RN50x4,openai,178.3,51.82,0.5188,0.6627,0.8661,0.7943,0.4514,0.2045,0.0905,0.2039,0.4862,0.3354,0.2102,0.8640,0.3622,0.4468,0.5944,0.4145,0.4955,0.7274,0.2335,0.4903,0.5141,0.6766,0.8829,0.6814,0.5675,0.6716,0.5338,0.6673,0.9658,0.6089,0.3190,0.7234,0.4318,0.3912,0.0870,0.5435,0.1130,0.5654,0.8376
|
| 87 |
+
nllb-clip-large-siglip,v1,1195.5,1804.22,0.5184,0.5175,0.8392,0.9651,0.7626,0.1737,0.2211,0.1549,0.4394,0.4941,0.0451,0.6312,0.4700,0.5050,0.4631,0.5611,0.1825,0.8325,0.4290,0.6203,0.6492,0.2846,0.4082,0.7823,0.5004,0.5601,0.5656,0.6451,0.9939,0.6355,0.4258,0.7803,0.4949,0.4035,0.0950,0.5000,0.1415,0.6390,0.8855
|
| 88 |
+
ViT-B-32,laion400m_e31,151.28,14.78,0.5077,0.6022,0.8916,0.8825,0.6781,0.1549,0.2261,0.1356,0.5218,0.4694,0.1437,0.7814,0.4082,0.4648,0.5234,0.1957,0.5085,0.7079,0.1224,0.4108,0.4281,0.6319,0.8541,0.7312,0.5495,0.5162,0.5108,0.7436,0.9494,0.6508,0.2891,0.6890,0.4327,0.4262,0.0745,0.4975,0.1076,0.5491,0.8328
|
| 89 |
+
ViT-B-32,laion400m_e32,151.28,14.78,0.5074,0.6024,0.8918,0.8840,0.6773,0.1536,0.2261,0.1349,0.5229,0.4754,0.1467,0.7817,0.4070,0.4646,0.5237,0.1953,0.5080,0.7084,0.1181,0.4000,0.4292,0.6323,0.8513,0.7328,0.5490,0.5206,0.5094,0.7454,0.9498,0.6509,0.2759,0.6866,0.4337,0.4265,0.0741,0.5084,0.1068,0.5444,0.8326
|
| 90 |
+
RN101,openai,119.69,25.5,0.5033,0.6228,0.8527,0.8078,0.4764,0.2437,0.0923,0.1693,0.4335,0.3131,0.1853,0.8367,0.3753,0.4106,0.5612,0.2944,0.5085,0.6817,0.2644,0.5254,0.4515,0.6532,0.8652,0.6512,0.5819,0.6403,0.5476,0.6100,0.9680,0.5803,0.3185,0.6852,0.4025,0.4130,0.0888,0.4723,0.1615,0.5631,0.8164
|
| 91 |
+
RN101-quickgelu,openai,119.69,25.5,0.5033,0.6228,0.8527,0.8078,0.4764,0.2437,0.0923,0.1693,0.4335,0.3131,0.1853,0.8367,0.3753,0.4106,0.5612,0.2944,0.5085,0.6817,0.2644,0.5254,0.4515,0.6532,0.8652,0.6512,0.5819,0.6403,0.5476,0.6100,0.9680,0.5803,0.3185,0.6852,0.4025,0.4130,0.0888,0.4723,0.1615,0.5631,0.8164
|
| 92 |
+
ViT-B-16,commonpool_l_laion_s1b_b8k,149.62,41.09,0.5011,0.5526,0.8766,0.9296,0.7184,0.2681,0.2173,0.1119,0.4144,0.4115,0.0714,0.7661,0.3296,0.4315,0.4790,0.2004,0.4930,0.6501,0.3432,0.4753,0.4638,0.5023,0.7769,0.7686,0.5158,0.5228,0.5314,0.6760,0.9409,0.6278,0.4301,0.6447,0.3924,0.4476,0.0490,0.5127,0.1026,0.5514,0.8463
|
| 93 |
+
ViT-B-16,commonpool_l_image_s1b_b8k,149.62,41.09,0.4812,0.5719,0.8856,0.9321,0.6955,0.2143,0.2453,0.1308,0.4170,0.3193,0.0735,0.7797,0.2514,0.4343,0.4872,0.2143,0.4725,0.6356,0.3826,0.2219,0.4793,0.4817,0.7784,0.7841,0.5002,0.4986,0.4622,0.6627,0.9489,0.6335,0.2673,0.6026,0.3622,0.4787,0.0424,0.5000,0.0000,0.5946,0.8422
|
| 94 |
+
RN50,openai,102.01,18.18,0.4810,0.5982,0.8329,0.7157,0.4030,0.2171,0.1623,0.1542,0.4154,0.4081,0.1703,0.8080,0.3510,0.3544,0.5284,0.2327,0.5720,0.6073,0.1730,0.5755,0.4141,0.6522,0.8529,0.6510,0.6393,0.5645,0.4521,0.5453,0.9419,0.5994,0.2883,0.6868,0.3869,0.3622,0.0623,0.5624,0.0000,0.5222,0.8129
|
| 95 |
+
RN50-quickgelu,openai,102.01,18.18,0.4810,0.5982,0.8329,0.7157,0.4030,0.2171,0.1623,0.1542,0.4154,0.4081,0.1703,0.8080,0.3510,0.3544,0.5284,0.2327,0.5720,0.6073,0.1730,0.5755,0.4141,0.6522,0.8529,0.6510,0.6393,0.5645,0.4521,0.5453,0.9419,0.5994,0.2883,0.6868,0.3869,0.3622,0.0623,0.5624,0.0000,0.5222,0.8129
|
| 96 |
+
ViT-B-16,commonpool_l_text_s1b_b8k,149.62,41.09,0.4760,0.5605,0.8720,0.9391,0.7054,0.1843,0.2373,0.0995,0.3941,0.3830,0.0451,0.7724,0.2317,0.4437,0.4835,0.2220,0.4770,0.6708,0.2686,0.2593,0.4911,0.5164,0.7049,0.7669,0.4857,0.4931,0.4663,0.6525,0.9523,0.6088,0.2122,0.6078,0.3730,0.4570,0.0623,0.5697,0.0000,0.5643,0.8564
|
| 97 |
+
ViT-B-16,commonpool_l_basic_s1b_b8k,149.62,41.09,0.4585,0.5155,0.8444,0.8289,0.5251,0.2061,0.2277,0.1173,0.4133,0.3820,0.0481,0.7461,0.2021,0.3932,0.4325,0.1913,0.4600,0.6087,0.3333,0.2809,0.4493,0.4357,0.6956,0.7151,0.5899,0.5387,0.4313,0.7216,0.9373,0.5974,0.1173,0.6015,0.3583,0.4812,0.0436,0.5712,0.0000,0.5421,0.8384
|
| 98 |
+
nllb-clip-base-siglip,v1,507.47,472.91,0.4451,0.3909,0.7507,0.9043,0.5939,0.1453,0.2254,0.0583,0.3617,0.3744,0.0090,0.4961,0.3429,0.3886,0.3439,0.3165,0.1695,0.6846,0.1927,0.5007,0.5001,0.1567,0.1868,0.7599,0.6692,0.5859,0.5049,0.4703,0.9818,0.5640,0.4033,0.7421,0.4716,0.3815,0.0694,0.6500,0.0956,0.6320,0.8392
|
| 99 |
+
ViT-B-16,commonpool_l_s1b_b8k,149.62,41.09,0.4370,0.4593,0.8089,0.9133,0.6421,0.1594,0.2203,0.1177,0.3383,0.3348,0.0316,0.6735,0.2766,0.3448,0.3914,0.1592,0.4335,0.5265,0.2686,0.3603,0.4126,0.3681,0.5587,0.7093,0.5516,0.5118,0.4154,0.6060,0.9339,0.5713,0.3047,0.4948,0.2855,0.4777,0.0399,0.5102,0.0000,0.5654,0.8305
|
| 100 |
+
nllb-clip-large,v1,1399.22,1468.46,0.4227,0.3672,0.7234,0.9634,0.6797,0.2389,0.2254,0.0691,0.3447,0.5454,0.0216,0.4447,0.2462,0.3316,0.3233,0.2632,0.1725,0.5624,0.3727,0.2716,0.5268,0.0978,0.1283,0.7551,0.5417,0.5585,0.4983,0.3865,0.9811,0.5512,0.1725,0.6625,0.4004,0.4299,0.0403,0.5181,0.1419,0.6752,0.8305
|
| 101 |
+
nllb-clip-base,v1,501.89,369.6,0.3351,0.2432,0.5914,0.8435,0.4839,0.1531,0.2254,0.0312,0.2782,0.4104,0.0185,0.2962,0.1852,0.1838,0.2029,0.0921,0.2195,0.3656,0.3741,0.1821,0.2874,0.0850,0.0784,0.6802,0.5509,0.5420,0.3603,0.1921,0.9514,0.4708,0.1441,0.5200,0.3081,0.3904,0.0463,0.4873,0.0000,0.5456,0.7136
|
| 102 |
+
ViT-B-32,datacomp_m_s128m_b4k,151.28,14.78,0.3281,0.2972,0.7159,0.8252,0.5476,0.1365,0.2249,0.0453,0.2133,0.3393,0.0304,0.4168,0.1366,0.1930,0.2440,0.0493,0.4085,0.3402,0.2110,0.1147,0.1971,0.2965,0.4311,0.5459,0.5862,0.5316,0.2778,0.2803,0.8365,0.3637,0.1500,0.2241,0.1407,0.3287,0.0142,0.6669,0.0000,0.4498,0.6559
|
| 103 |
+
ViT-B-32,commonpool_m_clip_s128m_b4k,151.28,14.78,0.3278,0.2725,0.6678,0.8405,0.5549,0.1402,0.2238,0.0458,0.2176,0.2589,0.0215,0.3999,0.1586,0.1844,0.2247,0.0420,0.3925,0.3297,0.3235,0.1778,0.2093,0.2551,0.3828,0.6074,0.5210,0.5014,0.2641,0.4123,0.8370,0.3875,0.1931,0.2465,0.1476,0.3581,0.0154,0.5369,0.0000,0.4451,0.6610
|
| 104 |
+
RN50-quickgelu,cc12m,102.01,18.18,0.3260,0.3647,0.6581,0.5404,0.2079,0.2063,0.1574,0.0431,0.1910,0.2146,0.0226,0.4392,0.1284,0.2412,0.3098,0.0759,0.4160,0.4468,0.3713,0.1261,0.2320,0.2383,0.5651,0.4394,0.5033,0.4789,0.2137,0.1837,0.8751,0.4442,0.0918,0.5373,0.2891,0.3876,0.0476,0.5000,0.0000,0.4883,0.7119
|
| 105 |
+
RN50,cc12m,102.01,18.18,0.3247,0.3591,0.6432,0.5241,0.2093,0.2076,0.1576,0.0422,0.2074,0.2202,0.0178,0.4241,0.1155,0.2354,0.3065,0.0763,0.4165,0.4466,0.3713,0.0919,0.2326,0.2465,0.5504,0.4700,0.5035,0.4871,0.2351,0.1818,0.8696,0.4440,0.0923,0.5357,0.2890,0.3828,0.0464,0.5000,0.0000,0.4907,0.7086
|
| 106 |
+
ViT-B-32,commonpool_m_image_s128m_b4k,151.28,14.78,0.3118,0.2678,0.6650,0.7815,0.5203,0.1298,0.2248,0.0466,0.1910,0.2261,0.0219,0.3553,0.1513,0.1623,0.2183,0.0385,0.3795,0.2959,0.2996,0.1079,0.1837,0.2383,0.3482,0.6147,0.5742,0.5266,0.2275,0.1593,0.8171,0.3706,0.1294,0.2303,0.1354,0.4026,0.0149,0.6905,0.0000,0.4638,0.6397
|
| 107 |
+
ViT-B-32,commonpool_m_text_s128m_b4k,151.28,14.78,0.3066,0.2548,0.6632,0.8164,0.5133,0.1891,0.2449,0.0355,0.1995,0.3587,0.0212,0.3568,0.1048,0.1655,0.2142,0.0431,0.3705,0.3107,0.2897,0.1034,0.1889,0.2184,0.2991,0.5355,0.5495,0.5008,0.2627,0.1935,0.7966,0.3535,0.1265,0.2386,0.1452,0.3618,0.0063,0.5336,0.0000,0.4544,0.6317
|
| 108 |
+
RN101-quickgelu,yfcc15m,119.69,25.5,0.2993,0.3487,0.5437,0.5298,0.2262,0.1609,0.2504,0.0683,0.1851,0.2030,0.0420,0.4686,0.0940,0.0888,0.3003,0.1568,0.3370,0.2643,0.2068,0.1239,0.1988,0.4942,0.2970,0.4603,0.5004,0.4992,0.2138,0.0373,0.8661,0.4085,0.0781,0.4422,0.2326,0.3147,0.0357,0.5000,0.0546,0.4930,0.6483
|
| 109 |
+
RN101,yfcc15m,119.69,25.5,0.2988,0.3407,0.5538,0.5048,0.2197,0.1369,0.2257,0.0699,0.1899,0.2076,0.0443,0.4729,0.1092,0.0888,0.2933,0.1611,0.3240,0.2629,0.2138,0.1086,0.1991,0.4886,0.3068,0.4886,0.5013,0.4920,0.2011,0.0381,0.8803,0.4235,0.1348,0.4426,0.2404,0.2987,0.0371,0.5000,0.0000,0.5035,0.6509
|
| 110 |
+
ViT-B-32,commonpool_m_laion_s128m_b4k,151.28,14.78,0.2919,0.2304,0.6312,0.7744,0.5009,0.1623,0.2261,0.0345,0.2043,0.1880,0.0169,0.3131,0.0906,0.1515,0.1895,0.0424,0.3480,0.2801,0.2827,0.1520,0.1763,0.2090,0.2973,0.5302,0.6225,0.4964,0.2470,0.2189,0.7774,0.3327,0.0881,0.2276,0.1353,0.3348,0.0167,0.5054,0.0000,0.4357,0.6234
|
| 111 |
+
ViT-B-32,commonpool_m_basic_s128m_b4k,151.28,14.78,0.2849,0.2255,0.6118,0.6321,0.3531,0.1417,0.2217,0.0423,0.1973,0.2191,0.0155,0.3165,0.1225,0.1434,0.1820,0.0383,0.3505,0.2684,0.2982,0.1229,0.1754,0.1853,0.2752,0.5323,0.5402,0.5014,0.2305,0.2900,0.7793,0.3490,0.0638,0.2187,0.1333,0.4015,0.0133,0.5137,0.0285,0.4591,0.6322
|
| 112 |
+
RN50,yfcc15m,102.01,18.18,0.2811,0.3238,0.5095,0.4943,0.1862,0.1315,0.2003,0.0642,0.1745,0.1811,0.0373,0.4304,0.0844,0.0729,0.2806,0.1371,0.3265,0.2231,0.2602,0.1004,0.1824,0.4680,0.2777,0.3888,0.5331,0.4992,0.1494,0.0429,0.8161,0.3999,0.0640,0.4106,0.2236,0.3023,0.0324,0.5256,0.0501,0.4673,0.6289
|
| 113 |
+
RN50-quickgelu,yfcc15m,102.01,18.18,0.2776,0.3275,0.5089,0.4919,0.2033,0.1305,0.1990,0.0637,0.1729,0.1596,0.0371,0.4493,0.0956,0.0715,0.2793,0.1373,0.3315,0.2220,0.2560,0.0924,0.1772,0.4718,0.2771,0.3845,0.5131,0.4992,0.1424,0.0407,0.7914,0.3919,0.0642,0.4045,0.2182,0.3130,0.0261,0.5058,0.0000,0.4638,0.6343
|
| 114 |
+
ViT-B-32,commonpool_m_s128m_b4k,151.28,14.78,0.2580,0.1755,0.5231,0.7459,0.4391,0.1263,0.2265,0.0362,0.1606,0.2537,0.0115,0.2342,0.0869,0.0952,0.1440,0.0388,0.2780,0.1983,0.2743,0.0933,0.1574,0.1128,0.1676,0.5448,0.5048,0.5003,0.1810,0.1332,0.7690,0.3066,0.0933,0.1599,0.0974,0.3983,0.0127,0.5015,0.0000,0.4276,0.5942
|
| 115 |
+
ViT-B-32,commonpool_s_clip_s13m_b4k,151.28,14.78,0.1731,0.0505,0.2483,0.4768,0.1937,0.1529,0.2313,0.0119,0.0782,0.2067,0.0083,0.0801,0.0732,0.0200,0.0380,0.0181,0.1380,0.0655,0.2785,0.0874,0.0506,0.0539,0.0796,0.3379,0.6367,0.5014,0.0806,0.0276,0.5353,0.1126,0.1166,0.0343,0.0224,0.2994,0.0004,0.6874,0.0000,0.2605,0.2827
|
| 116 |
+
ViT-B-32,commonpool_s_text_s13m_b4k,151.28,14.78,0.1573,0.0460,0.2231,0.4679,0.1844,0.1350,0.1899,0.0121,0.0670,0.0896,0.0139,0.0618,0.0411,0.0175,0.0398,0.0187,0.1270,0.0606,0.3980,0.0771,0.0494,0.0428,0.0581,0.2942,0.5027,0.5008,0.1029,0.0204,0.5019,0.1051,0.0933,0.0424,0.0214,0.3120,0.0015,0.5000,0.0000,0.2745,0.2843
|
| 117 |
+
ViT-B-32,commonpool_s_image_s13m_b4k,151.28,14.78,0.1449,0.0392,0.2238,0.3176,0.1329,0.1121,0.2217,0.0109,0.0521,0.1593,0.0120,0.0604,0.0579,0.0186,0.0308,0.0155,0.1055,0.0578,0.2883,0.0991,0.0436,0.0528,0.0474,0.2666,0.5273,0.4646,0.0794,0.0173,0.4601,0.0725,0.1305,0.0171,0.0130,0.2525,0.0033,0.5425,0.0085,0.2150,0.2752
|
| 118 |
+
ViT-B-32,datacomp_s_s13m_b4k,151.28,14.78,0.1449,0.0392,0.2238,0.3176,0.1329,0.1121,0.2217,0.0109,0.0521,0.1593,0.0120,0.0604,0.0579,0.0186,0.0308,0.0155,0.1055,0.0578,0.2883,0.0991,0.0436,0.0528,0.0474,0.2666,0.5273,0.4646,0.0794,0.0173,0.4601,0.0725,0.1305,0.0171,0.0130,0.2525,0.0033,0.5425,0.0085,0.2150,0.2752
|
| 119 |
+
ViT-B-32,commonpool_s_basic_s13m_b4k,151.28,14.78,0.1423,0.0377,0.1806,0.2664,0.1154,0.1245,0.2335,0.0120,0.0553,0.0587,0.0103,0.0588,0.0638,0.0151,0.0319,0.0203,0.0985,0.0499,0.3390,0.1085,0.0440,0.0351,0.0488,0.3081,0.5096,0.4986,0.0795,0.0200,0.4659,0.0879,0.0810,0.0328,0.0168,0.3033,0.0003,0.5001,0.0000,0.2325,0.2643
|
| 120 |
+
ViT-B-32,commonpool_s_s13m_b4k,151.28,14.78,0.1420,0.0270,0.1564,0.4079,0.1296,0.1305,0.2233,0.0126,0.0574,0.1487,0.0081,0.0473,0.0654,0.0108,0.0234,0.0141,0.1000,0.0404,0.3460,0.0708,0.0360,0.0338,0.0443,0.2235,0.5268,0.5008,0.0698,0.0143,0.4266,0.0766,0.1121,0.0257,0.0132,0.3126,0.0002,0.5124,0.0000,0.2290,0.2167
|
| 121 |
+
ViT-B-32,commonpool_s_laion_s13m_b4k,151.28,14.78,0.1332,0.0305,0.1549,0.3364,0.1347,0.1309,0.1299,0.0098,0.0553,0.1578,0.0134,0.0501,0.0538,0.0125,0.0271,0.0147,0.1015,0.0443,0.2518,0.1387,0.0369,0.0244,0.0399,0.3030,0.4216,0.4992,0.0583,0.0155,0.4874,0.0659,0.1473,0.0223,0.0121,0.2410,0.0017,0.3703,0.0000,0.2079,0.2580
|
| 122 |
+
coca_ViT-B-32,mscoco_finetuned_laion2b_s13b_b90k,253.56,33.34,0.1108,0.0079,0.0320,0.2564,0.0193,0.1245,0.2027,0.0044,0.0303,0.1157,0.0064,0.0159,0.0146,0.0028,0.0067,0.0121,0.0220,0.0199,0.3010,0.1506,0.0144,0.0054,0.0416,0.2023,0.5713,0.4992,0.0478,0.0056,0.2579,0.0204,0.1529,0.0092,0.0060,0.2329,0.0004,0.5681,0.0000,0.1729,0.0589
|
hlip/open_clip/docs/openclip_retrieval_results.csv
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name,pretrained,params (M),FLOPs (B),Average score,Flickr image retr. R@1,Flickr image retr. R@5,Flickr image retr. R@10,Flickr text retr. R@1,Flickr text retr. R@5,Flickr text retr. R@10,MSCOCO image retr. R@1,MSCOCO image retr. R@5,MSCOCO image retr. R@10,MSCOCO text retr. R@1,MSCOCO text retr. R@5,MSCOCO text retr. R@10,WinoGAViL avg jaccard score,WinoGAViL jaccard score 10,WinoGAViL jaccard score 10-12,WinoGAViL jaccard score 12,WinoGAViL jaccard score 5,WinoGAViL jaccard score 5-6,WinoGAViL jaccard score 6
|
| 2 |
+
ViT-SO400M-14-SigLIP-384,webli,877.96,723.48,0.7721,0.8296,0.9610,0.9804,0.9430,0.9970,0.9980,0.5421,0.7678,0.8424,0.7242,0.8998,0.9448,0.6181,0.5807,0.5754,0.5701,0.6427,0.6316,0.6210
|
| 3 |
+
ViT-H-14-378-quickgelu,dfn5b,986.71,1054.05,0.7719,0.8202,0.9598,0.9798,0.9400,0.9920,0.9960,0.5564,0.7920,0.8626,0.7188,0.9048,0.9496,0.6123,0.5668,0.5674,0.5679,0.6409,0.6265,0.6127
|
| 4 |
+
ViT-L-16-SigLIP-384,webli,652.48,422.91,0.7642,0.8142,0.9536,0.9748,0.9370,0.9920,0.9990,0.5391,0.7657,0.8399,0.7190,0.9006,0.9410,0.6070,0.5562,0.5550,0.5539,0.6422,0.6234,0.6056
|
| 5 |
+
ViT-H-14-quickgelu,dfn5b,986.11,381.68,0.7640,0.8012,0.9526,0.9738,0.9280,0.9940,0.9990,0.5391,0.7805,0.8553,0.7230,0.9024,0.9452,0.6022,0.5568,0.5561,0.5554,0.6315,0.6167,0.6028
|
| 6 |
+
ViT-L-16-SigLIP-256,webli,652.15,201.62,0.7619,0.7904,0.9446,0.9684,0.9180,0.9900,0.9980,0.5228,0.7580,0.8334,0.7080,0.8870,0.9374,0.6142,0.5877,0.5748,0.5619,0.6450,0.6267,0.6092
|
| 7 |
+
ViT-SO400M-14-SigLIP,webli,877.36,233.54,0.7567,0.7526,0.9226,0.9554,0.9100,0.9910,0.9980,0.5176,0.7527,0.8300,0.6966,0.8908,0.9348,0.6189,0.5736,0.5665,0.5594,0.6430,0.6354,0.6282
|
| 8 |
+
ViT-B-16-SigLIP-512,webli,203.79,227.26,0.7554,0.7906,0.9458,0.9690,0.9250,0.9920,0.9960,0.5055,0.7421,0.8217,0.6872,0.8786,0.9266,0.6070,0.5761,0.5696,0.5633,0.6291,0.6187,0.6088
|
| 9 |
+
ViT-B-16-SigLIP-384,webli,203.45,123.15,0.7542,0.7848,0.9416,0.9708,0.9270,0.9910,0.9980,0.4990,0.7366,0.8204,0.6774,0.8758,0.9258,0.6077,0.5730,0.5719,0.5709,0.6314,0.6190,0.6072
|
| 10 |
+
ViT-B-16-SigLIP-256,webli,203.2,57.84,0.7462,0.7504,0.9242,0.9626,0.9040,0.9830,0.9930,0.4834,0.7254,0.8099,0.6614,0.8634,0.9182,0.6113,0.5754,0.5715,0.5677,0.6373,0.6238,0.6110
|
| 11 |
+
ViT-B-16-SigLIP,webli,203.16,46.44,0.7442,0.7468,0.9230,0.9562,0.8910,0.9800,0.9930,0.4778,0.7244,0.8100,0.6574,0.8542,0.9126,0.6134,0.5726,0.5738,0.5750,0.6335,0.6259,0.6186
|
| 12 |
+
coca_ViT-L-14,mscoco_finetuned_laion2b_s13b_b90k,638.45,214.52,0.7432,0.7846,0.9452,0.9712,0.8900,0.9870,0.9950,0.5374,0.7779,0.8567,0.6682,0.8762,0.9242,0.5762,0.5265,0.5146,0.5028,0.5978,0.5956,0.5934
|
| 13 |
+
ViT-H-14-quickgelu,metaclip_fullcc,986.11,381.68,0.7412,0.7834,0.9464,0.9692,0.9180,0.9870,0.9970,0.4882,0.7323,0.8136,0.6622,0.8618,0.9188,0.5891,0.5316,0.5312,0.5308,0.6220,0.6073,0.5934
|
| 14 |
+
ViT-L-14-quickgelu,dfn2b,427.62,175.33,0.7406,0.7546,0.9280,0.9608,0.8960,0.9850,0.9930,0.4856,0.7381,0.8237,0.6560,0.8584,0.9120,0.5955,0.5688,0.5519,0.5351,0.6219,0.6093,0.5973
|
| 15 |
+
xlm-roberta-large-ViT-H-14,frozen_laion5b_s13b_b90k,1193.01,671.01,0.7363,0.7742,0.9392,0.9670,0.9180,0.9930,0.9980,0.4921,0.7305,0.8159,0.6596,0.8618,0.9184,0.5767,0.5277,0.5206,0.5135,0.6076,0.5943,0.5818
|
| 16 |
+
ViT-B-16-SigLIP-i18n-256,webli,370.63,57.84,0.7347,0.7216,0.9036,0.9470,0.8960,0.9820,0.9910,0.4492,0.6948,0.7837,0.6448,0.8434,0.9060,0.6113,0.5887,0.5710,0.5534,0.6303,0.6240,0.6180
|
| 17 |
+
ViT-L-14-quickgelu,metaclip_fullcc,427.62,175.33,0.7325,0.7642,0.9366,0.9646,0.9010,0.9850,0.9930,0.4709,0.7141,0.8026,0.6442,0.8504,0.9130,0.5817,0.5539,0.5357,0.5176,0.5990,0.5963,0.5937
|
| 18 |
+
ViT-H-14-CLIPA-336,laion2b,968.64,800.88,0.7289,0.7814,0.9392,0.9684,0.9230,0.9920,0.9970,0.5013,0.7387,0.8224,0.6752,0.8802,0.9308,0.5452,0.4970,0.4878,0.4786,0.5764,0.5633,0.5508
|
| 19 |
+
convnext_xxlarge,laion2b_s34b_b82k_augreg_rewind,1200.58,443.03,0.7238,0.7886,0.9438,0.9714,0.9110,0.9910,0.9970,0.5003,0.7407,0.8240,0.6740,0.8738,0.9264,0.5327,0.4826,0.4741,0.4656,0.5674,0.5512,0.5357
|
| 20 |
+
EVA02-L-14-336,merged2b_s6b_b61k,428.08,395.16,0.7235,0.7802,0.9432,0.9684,0.8960,0.9890,0.9960,0.4794,0.7172,0.7999,0.6416,0.8522,0.9084,0.5532,0.5081,0.5053,0.5025,0.5719,0.5683,0.5649
|
| 21 |
+
convnext_xxlarge,laion2b_s34b_b82k_augreg_soup,1200.58,443.03,0.7232,0.7902,0.9460,0.9706,0.9140,0.9920,0.9970,0.4997,0.7403,0.8227,0.6736,0.8722,0.9260,0.5316,0.4790,0.4702,0.4615,0.5651,0.5509,0.5374
|
| 22 |
+
EVA01-g-14-plus,merged2b_s11b_b114k,1366.62,581.15,0.7231,0.7900,0.9448,0.9692,0.9170,0.9930,0.9970,0.5033,0.7398,0.8206,0.6816,0.8750,0.9250,0.5298,0.4787,0.4684,0.4582,0.5655,0.5491,0.5336
|
| 23 |
+
ViT-bigG-14-CLIPA-336,datacomp1b,2517.76,2271.58,0.7220,0.7828,0.9408,0.9674,0.9220,0.9940,0.9980,0.5042,0.7432,0.8238,0.6776,0.8792,0.9306,0.5323,0.4624,0.4487,0.4350,0.5619,0.5587,0.5556
|
| 24 |
+
ViT-bigG-14,laion2b_s39b_b160k,2539.57,1065.36,0.7213,0.7956,0.9498,0.9714,0.9290,0.9930,0.9980,0.5137,0.7490,0.8300,0.6738,0.8686,0.9266,0.5224,0.4714,0.4488,0.4263,0.5588,0.5456,0.5330
|
| 25 |
+
EVA02-L-14,merged2b_s4b_b131k,427.76,175.3,0.7207,0.7732,0.9374,0.9678,0.8970,0.9850,0.9910,0.4747,0.7123,0.7971,0.6366,0.8434,0.9038,0.5518,0.5128,0.5081,0.5034,0.5767,0.5656,0.5551
|
| 26 |
+
ViT-L-14,commonpool_xl_laion_s13b_b90k,427.62,175.33,0.7206,0.7490,0.9308,0.9630,0.8770,0.9900,0.9950,0.4677,0.7142,0.8042,0.6350,0.8458,0.9122,0.5635,0.5193,0.4966,0.4740,0.6023,0.5846,0.5677
|
| 27 |
+
convnext_xxlarge,laion2b_s34b_b82k_augreg,1200.58,443.03,0.7201,0.7902,0.9414,0.9726,0.9160,0.9920,0.9970,0.4970,0.7400,0.8199,0.6698,0.8744,0.9236,0.5290,0.4730,0.4536,0.4343,0.5622,0.5527,0.5437
|
| 28 |
+
ViT-H-14-CLIPA-336,datacomp1b,968.64,800.88,0.7192,0.7652,0.9350,0.9630,0.9060,0.9920,0.9950,0.4928,0.7309,0.8144,0.6716,0.8746,0.9276,0.5365,0.4801,0.4587,0.4375,0.5658,0.5610,0.5566
|
| 29 |
+
EVA02-E-14-plus,laion2b_s9b_b144k,5044.89,2362.19,0.7188,0.7886,0.9434,0.9698,0.9410,0.9930,0.9980,0.5110,0.7492,0.8276,0.6872,0.8760,0.9274,0.5134,0.4576,0.4403,0.4232,0.5470,0.5364,0.5263
|
| 30 |
+
ViT-H-14-CLIPA,datacomp1b,968.24,354.02,0.7178,0.7588,0.9330,0.9628,0.9100,0.9900,0.9960,0.4910,0.7291,0.8140,0.6698,0.8730,0.9272,0.5343,0.4793,0.4578,0.4365,0.5641,0.5584,0.5529
|
| 31 |
+
ViT-bigG-14-CLIPA,datacomp1b,2517.22,1007.93,0.7175,0.7786,0.9374,0.9650,0.9190,0.9930,0.9980,0.4996,0.7414,0.8214,0.6780,0.8742,0.9312,0.5247,0.4461,0.4383,0.4306,0.5552,0.5519,0.5488
|
| 32 |
+
ViT-B-16,dfn2b,149.62,41.09,0.7158,0.6912,0.8982,0.9406,0.8540,0.9780,0.9860,0.4339,0.6924,0.7882,0.6038,0.8310,0.8946,0.5852,0.5509,0.5417,0.5327,0.6058,0.5989,0.5923
|
| 33 |
+
EVA02-E-14,laion2b_s4b_b115k,4704.59,2311.42,0.7152,0.7810,0.9438,0.9700,0.9220,0.9950,0.9970,0.5037,0.7429,0.8224,0.6746,0.8738,0.9256,0.5110,0.4316,0.4429,0.4542,0.5485,0.5325,0.5173
|
| 34 |
+
convnext_large_d_320,laion2b_s29b_b131k_ft_soup,351.77,157.98,0.7148,0.7704,0.9394,0.9648,0.9230,0.9890,0.9980,0.4829,0.7251,0.8103,0.6502,0.8608,0.9180,0.5285,0.4574,0.4549,0.4525,0.5650,0.5517,0.5391
|
| 35 |
+
ViT-L-14-quickgelu,metaclip_400m,427.62,175.33,0.7137,0.7342,0.9228,0.9574,0.8620,0.9800,0.9960,0.4381,0.6862,0.7780,0.6000,0.8290,0.8934,0.5701,0.5322,0.5175,0.5029,0.5941,0.5867,0.5796
|
| 36 |
+
convnext_large_d_320,laion2b_s29b_b131k_ft,351.77,157.98,0.7122,0.7690,0.9364,0.9668,0.9140,0.9890,0.9980,0.4814,0.7232,0.8103,0.6384,0.8558,0.9168,0.5250,0.4727,0.4558,0.4389,0.5623,0.5468,0.5321
|
| 37 |
+
convnext_large_d,laion2b_s26b_b102k_augreg,351.77,107.5,0.7102,0.7588,0.9310,0.9652,0.9180,0.9850,0.9940,0.4701,0.7139,0.8013,0.6400,0.8506,0.9140,0.5252,0.4835,0.4646,0.4457,0.5571,0.5443,0.5322
|
| 38 |
+
ViT-L-14-CLIPA-336,datacomp1b,414.54,387.39,0.7092,0.7462,0.9240,0.9590,0.9040,0.9920,0.9980,0.4715,0.7159,0.8024,0.6564,0.8636,0.9180,0.5276,0.4601,0.4449,0.4297,0.5611,0.5537,0.5467
|
| 39 |
+
ViT-L-14,datacomp_xl_s13b_b90k,427.62,175.33,0.7091,0.7338,0.9174,0.9554,0.8900,0.9860,0.9970,0.4573,0.7003,0.7916,0.6330,0.8414,0.9040,0.5471,0.4836,0.4666,0.4497,0.5912,0.5724,0.5546
|
| 40 |
+
ViT-g-14,laion2b_s12b_b42k,1366.68,581.15,0.7085,0.7642,0.9364,0.9624,0.9090,0.9910,0.9980,0.4802,0.7238,0.8079,0.6492,0.8530,0.9152,0.5178,0.4498,0.4427,0.4357,0.5589,0.5414,0.5249
|
| 41 |
+
coca_ViT-L-14,laion2b_s13b_b90k,638.45,214.52,0.7085,0.7428,0.9202,0.9542,0.8840,0.9930,0.9990,0.4565,0.7042,0.7921,0.6292,0.8370,0.9038,0.5403,0.4800,0.4739,0.4677,0.5704,0.5612,0.5525
|
| 42 |
+
ViT-B-16-quickgelu,metaclip_fullcc,149.62,41.09,0.7077,0.7072,0.9082,0.9454,0.8550,0.9740,0.9890,0.4134,0.6718,0.7696,0.5936,0.8058,0.8784,0.5787,0.5391,0.5221,0.5052,0.6064,0.5965,0.5871
|
| 43 |
+
ViT-H-14,laion2b_s32b_b79k,986.11,381.68,0.7057,0.7764,0.9418,0.9660,0.9070,0.9920,0.9970,0.4948,0.7338,0.8151,0.6592,0.8606,0.9188,0.4998,0.4289,0.4247,0.4206,0.5462,0.5234,0.5018
|
| 44 |
+
convnext_base_w,laion_aesthetic_s13b_b82k,179.39,49.38,0.7047,0.7306,0.9160,0.9532,0.8880,0.9820,0.9930,0.4355,0.6858,0.7808,0.6120,0.8338,0.8978,0.5461,0.4937,0.4764,0.4592,0.5829,0.5681,0.5540
|
| 45 |
+
ViT-L-14-CLIPA,datacomp1b,414.21,167.5,0.7044,0.7356,0.9206,0.9550,0.9020,0.9860,0.9930,0.4695,0.7084,0.7981,0.6512,0.8544,0.9150,0.5244,0.4495,0.4388,0.4282,0.5583,0.5514,0.5449
|
| 46 |
+
ViT-g-14,laion2b_s34b_b88k,1366.68,581.15,0.7038,0.7772,0.9416,0.9690,0.9140,0.9930,0.9960,0.4878,0.7334,0.8151,0.6638,0.8598,0.9184,0.4973,0.4207,0.4104,0.4001,0.5458,0.5247,0.5047
|
| 47 |
+
convnext_base_w_320,laion_aesthetic_s13b_b82k,179.39,71.94,0.7030,0.7402,0.9200,0.9524,0.9070,0.9830,0.9920,0.4387,0.6920,0.7824,0.6106,0.8312,0.8964,0.5385,0.4742,0.4610,0.4478,0.5695,0.5630,0.5567
|
| 48 |
+
ViT-L-14,laion2b_s32b_b82k,427.62,175.33,0.7010,0.7552,0.9286,0.9594,0.8950,0.9870,0.9940,0.4651,0.7108,0.7980,0.6336,0.8398,0.9074,0.5142,0.4448,0.4385,0.4322,0.5507,0.5381,0.5261
|
| 49 |
+
EVA01-g-14,laion400m_s11b_b41k,1136.44,547.36,0.7003,0.7264,0.9162,0.9510,0.8810,0.9830,0.9930,0.4406,0.6849,0.7732,0.6180,0.8328,0.8998,0.5363,0.4646,0.4640,0.4634,0.5665,0.5591,0.5521
|
| 50 |
+
convnext_base_w,laion2b_s13b_b82k,179.39,49.38,0.6976,0.7214,0.9152,0.9538,0.8770,0.9800,0.9930,0.4285,0.6805,0.7770,0.6058,0.8324,0.8954,0.5311,0.4926,0.4706,0.4488,0.5648,0.5501,0.5362
|
| 51 |
+
ViT-B-16-quickgelu,metaclip_400m,149.62,41.09,0.6962,0.6766,0.8960,0.9414,0.8570,0.9720,0.9870,0.3997,0.6536,0.7530,0.5648,0.7988,0.8714,0.5675,0.4984,0.5113,0.5242,0.5916,0.5853,0.5792
|
| 52 |
+
ViT-L-14,commonpool_xl_clip_s13b_b90k,427.62,175.33,0.6956,0.6886,0.8996,0.9424,0.8650,0.9740,0.9920,0.4273,0.6761,0.7700,0.6040,0.8190,0.8858,0.5460,0.4833,0.4728,0.4622,0.5821,0.5691,0.5566
|
| 53 |
+
convnext_base_w,laion2b_s13b_b82k_augreg,179.39,49.38,0.6922,0.7240,0.9144,0.9514,0.8730,0.9830,0.9920,0.4303,0.6786,0.7750,0.6140,0.8308,0.8964,0.5229,0.4504,0.4390,0.4276,0.5567,0.5494,0.5424
|
| 54 |
+
EVA02-B-16,merged2b_s8b_b131k,149.69,41.09,0.6904,0.7146,0.9114,0.9468,0.8600,0.9660,0.9880,0.4215,0.6686,0.7629,0.5874,0.8056,0.8812,0.5325,0.4686,0.4722,0.4758,0.5522,0.5515,0.5509
|
| 55 |
+
ViT-B-16,laion2b_s34b_b88k,149.62,41.09,0.6884,0.6984,0.9038,0.9456,0.8630,0.9790,0.9940,0.4231,0.6770,0.7706,0.5944,0.8178,0.8862,0.5220,0.4628,0.4601,0.4575,0.5549,0.5415,0.5288
|
| 56 |
+
ViT-B-32-quickgelu,metaclip_fullcc,151.28,14.78,0.6879,0.6510,0.8766,0.9274,0.8080,0.9530,0.9730,0.3806,0.6411,0.7430,0.5518,0.7890,0.8650,0.5729,0.5351,0.5238,0.5126,0.5983,0.5883,0.5788
|
| 57 |
+
convnext_base_w_320,laion_aesthetic_s13b_b82k_augreg,179.39,71.94,0.6870,0.7108,0.9032,0.9452,0.8910,0.9740,0.9900,0.4243,0.6722,0.7680,0.6040,0.8276,0.8912,0.5192,0.4599,0.4293,0.3989,0.5686,0.5475,0.5274
|
| 58 |
+
ViT-B-16,datacomp_xl_s13b_b90k,149.62,41.09,0.6867,0.6756,0.8834,0.9300,0.8510,0.9720,0.9840,0.4016,0.6595,0.7562,0.5744,0.8086,0.8830,0.5408,0.4966,0.4832,0.4699,0.5730,0.5590,0.5457
|
| 59 |
+
ViT-L-14,commonpool_xl_s13b_b90k,427.62,175.33,0.6817,0.6478,0.8656,0.9210,0.8200,0.9500,0.9740,0.3859,0.6310,0.7328,0.5446,0.7712,0.8484,0.5697,0.5115,0.5072,0.5030,0.5932,0.5894,0.5858
|
| 60 |
+
ViT-B-32,laion2b_e16,151.28,14.78,0.6777,0.6638,0.8830,0.9322,0.8440,0.9650,0.9840,0.3913,0.6467,0.7481,0.5624,0.7956,0.8708,0.5343,0.4800,0.4602,0.4404,0.5669,0.5577,0.5490
|
| 61 |
+
xlm-roberta-base-ViT-B-32,laion5b_s13b_b90k,366.12,105.87,0.6759,0.6448,0.8628,0.9168,0.8270,0.9640,0.9780,0.3778,0.6344,0.7348,0.5354,0.7798,0.8640,0.5519,0.4912,0.4827,0.4742,0.5834,0.5737,0.5645
|
| 62 |
+
ViT-B-32,laion2b_s34b_b79k,151.28,14.78,0.6750,0.6678,0.8838,0.9310,0.8410,0.9620,0.9830,0.3934,0.6543,0.7561,0.5632,0.7984,0.8712,0.5254,0.4603,0.4479,0.4356,0.5603,0.5498,0.5398
|
| 63 |
+
nllb-clip-large-siglip,v1,1195.5,1804.22,0.6738,0.7276,0.9224,0.9560,0.8330,0.9710,0.9910,0.4513,0.7084,0.8016,0.5386,0.7920,0.8712,0.4871,0.4138,0.4035,0.3933,0.5230,0.5135,0.5045
|
| 64 |
+
ViT-L-14,laion400m_e32,427.62,175.33,0.6734,0.7022,0.9094,0.9458,0.8760,0.9780,0.9950,0.4300,0.6803,0.7740,0.5974,0.8218,0.8938,0.4815,0.4006,0.3932,0.3858,0.5245,0.5094,0.4950
|
| 65 |
+
ViT-L-14,laion400m_e31,427.62,175.33,0.6728,0.7050,0.9068,0.9464,0.8720,0.9760,0.9950,0.4284,0.6797,0.7731,0.5974,0.8216,0.8934,0.4805,0.4022,0.3949,0.3877,0.5262,0.5075,0.4897
|
| 66 |
+
ViT-B-32-256,datacomp_s34b_b86k,151.29,17.46,0.6712,0.6492,0.8722,0.9216,0.8480,0.9670,0.9850,0.3993,0.6543,0.7524,0.5792,0.8056,0.8810,0.5165,0.4554,0.4300,0.4048,0.5428,0.5437,0.5446
|
| 67 |
+
ViT-B-32-quickgelu,metaclip_400m,151.28,14.78,0.6710,0.6234,0.8558,0.9152,0.7780,0.9350,0.9700,0.3591,0.6179,0.7209,0.5182,0.7640,0.8466,0.5657,0.5279,0.5097,0.4916,0.5907,0.5834,0.5764
|
| 68 |
+
coca_ViT-B-32,laion2b_s13b_b90k,253.56,33.34,0.6689,0.6336,0.8566,0.9144,0.8160,0.9570,0.9740,0.3618,0.6136,0.7176,0.5456,0.7788,0.8556,0.5499,0.4924,0.4698,0.4472,0.5778,0.5751,0.5725
|
| 69 |
+
ViT-B-16-plus-240,laion400m_e32,208.38,64.03,0.6676,0.6810,0.8888,0.9406,0.8650,0.9720,0.9880,0.4100,0.6619,0.7611,0.5858,0.8108,0.8806,0.4856,0.4146,0.4069,0.3993,0.5250,0.5104,0.4964
|
| 70 |
+
ViT-B-16-plus-240,laion400m_e31,208.38,64.03,0.6671,0.6790,0.8878,0.9392,0.8560,0.9730,0.9860,0.4075,0.6604,0.7594,0.5834,0.8082,0.8796,0.4882,0.4206,0.4093,0.3980,0.5290,0.5131,0.4981
|
| 71 |
+
ViT-L-14-336,openai,427.94,395.22,0.6666,0.6690,0.8900,0.9334,0.8770,0.9850,0.9940,0.3709,0.6162,0.7147,0.5794,0.8120,0.8792,0.5041,0.4201,0.4145,0.4089,0.5403,0.5324,0.5249
|
| 72 |
+
roberta-ViT-B-32,laion2b_s12b_b32k,212.72,105.87,0.6641,0.6434,0.8674,0.9250,0.8170,0.9490,0.9720,0.3744,0.6309,0.7355,0.5436,0.7774,0.8568,0.5224,0.4602,0.4583,0.4564,0.5531,0.5426,0.5325
|
| 73 |
+
ViT-B-16,laion400m_e32,149.62,41.09,0.6638,0.6566,0.8828,0.9300,0.8350,0.9680,0.9850,0.3835,0.6362,0.7386,0.5542,0.7964,0.8688,0.5033,0.4380,0.4326,0.4272,0.5294,0.5256,0.5219
|
| 74 |
+
ViT-B-16,laion400m_e31,149.62,41.09,0.6621,0.6572,0.8808,0.9314,0.8330,0.9660,0.9840,0.3834,0.6366,0.7383,0.5514,0.7960,0.8688,0.5024,0.4255,0.4225,0.4195,0.5323,0.5276,0.5232
|
| 75 |
+
ViT-B-32,datacomp_xl_s13b_b90k,151.28,14.78,0.6594,0.6108,0.8492,0.9092,0.7900,0.9390,0.9620,0.3714,0.6235,0.7268,0.5354,0.7778,0.8604,0.5317,0.4772,0.4594,0.4418,0.5589,0.5544,0.5502
|
| 76 |
+
ViT-L-14,openai,427.62,175.33,0.6588,0.6496,0.8724,0.9204,0.8520,0.9740,0.9920,0.3651,0.6106,0.7113,0.5634,0.7938,0.8660,0.5047,0.4307,0.4136,0.3966,0.5457,0.5334,0.5218
|
| 77 |
+
RN50x64,openai,623.26,552.65,0.6563,0.6898,0.8990,0.9432,0.8690,0.9820,0.9920,0.3524,0.5992,0.7033,0.5842,0.8046,0.8786,0.4779,0.4149,0.3936,0.3725,0.5280,0.5044,0.4820
|
| 78 |
+
nllb-clip-base-siglip,v1,507.47,472.91,0.6545,0.6922,0.9002,0.9424,0.7920,0.9500,0.9820,0.4315,0.6913,0.7852,0.5116,0.7776,0.8628,0.4715,0.3776,0.3815,0.3854,0.5113,0.4999,0.4890
|
| 79 |
+
convnext_base,laion400m_s13b_b51k,151.52,36.67,0.6541,0.6496,0.8814,0.9304,0.8380,0.9710,0.9910,0.3760,0.6315,0.7337,0.5470,0.7990,0.8676,0.4811,0.4146,0.4045,0.3944,0.5145,0.5052,0.4964
|
| 80 |
+
RN50x16,openai,290.98,162.69,0.6518,0.6534,0.8710,0.9178,0.8570,0.9700,0.9880,0.3541,0.6002,0.7014,0.5536,0.7876,0.8670,0.4957,0.4311,0.3946,0.3584,0.5419,0.5275,0.5138
|
| 81 |
+
ViT-B-16,openai,149.62,41.09,0.6507,0.6216,0.8572,0.9192,0.8220,0.9660,0.9900,0.3309,0.5842,0.6899,0.5242,0.7670,0.8462,0.5171,0.4487,0.4316,0.4146,0.5550,0.5441,0.5337
|
| 82 |
+
ViT-B-32,laion400m_e31,151.28,14.78,0.6412,0.5970,0.8398,0.9036,0.7810,0.9380,0.9660,0.3420,0.6001,0.7059,0.5234,0.7634,0.8432,0.5059,0.4283,0.4262,0.4242,0.5477,0.5310,0.5152
|
| 83 |
+
ViT-B-32,laion400m_e32,151.28,14.78,0.6412,0.5962,0.8396,0.9020,0.7770,0.9410,0.9680,0.3431,0.6000,0.7054,0.5244,0.7642,0.8454,0.5055,0.4272,0.4265,0.4258,0.5476,0.5304,0.5139
|
| 84 |
+
ViT-B-32-quickgelu,laion400m_e32,151.28,14.78,0.6394,0.6170,0.8546,0.9086,0.7880,0.9400,0.9700,0.3533,0.6089,0.7165,0.5258,0.7672,0.8464,0.4884,0.4097,0.4072,0.4047,0.5280,0.5140,0.5006
|
| 85 |
+
ViT-B-32-quickgelu,laion400m_e31,151.28,14.78,0.6389,0.6174,0.8548,0.9078,0.7870,0.9400,0.9730,0.3535,0.6100,0.7177,0.5254,0.7702,0.8490,0.4860,0.4054,0.4034,0.4015,0.5273,0.5120,0.4974
|
| 86 |
+
RN50x4,openai,178.3,51.82,0.6373,0.6258,0.8476,0.9018,0.8210,0.9630,0.9830,0.3339,0.5812,0.6830,0.5296,0.7662,0.8490,0.4893,0.4104,0.3912,0.3720,0.5354,0.5202,0.5058
|
| 87 |
+
nllb-clip-large,v1,1399.22,1468.46,0.6346,0.6090,0.8576,0.9202,0.7160,0.9220,0.9600,0.3617,0.6250,0.7304,0.4392,0.7086,0.8036,0.5097,0.4334,0.4299,0.4265,0.5395,0.5348,0.5304
|
| 88 |
+
ViT-B-32,openai,151.28,14.78,0.6321,0.5878,0.8356,0.9002,0.7890,0.9490,0.9820,0.3044,0.5594,0.6687,0.5012,0.7500,0.8352,0.5054,0.4454,0.4125,0.3798,0.5492,0.5347,0.5210
|
| 89 |
+
ViT-B-32-quickgelu,openai,151.28,14.78,0.6321,0.5878,0.8356,0.9002,0.7890,0.9490,0.9820,0.3044,0.5594,0.6687,0.5012,0.7500,0.8352,0.5054,0.4454,0.4125,0.3798,0.5492,0.5347,0.5210
|
| 90 |
+
ViT-B-16,commonpool_l_laion_s1b_b8k,149.62,41.09,0.6274,0.5664,0.8114,0.8836,0.7230,0.9100,0.9510,0.3195,0.5756,0.6848,0.4652,0.7170,0.8088,0.5227,0.4558,0.4476,0.4395,0.5563,0.5463,0.5369
|
| 91 |
+
ViT-B-16,datacomp_l_s1b_b8k,149.62,41.09,0.6267,0.5536,0.8090,0.8768,0.7320,0.9170,0.9480,0.3218,0.5747,0.6858,0.4872,0.7292,0.8246,0.5113,0.4613,0.4465,0.4318,0.5404,0.5317,0.5235
|
| 92 |
+
RN101,openai,119.69,25.5,0.6249,0.5804,0.8228,0.8852,0.7900,0.9490,0.9740,0.3069,0.5546,0.6603,0.4982,0.7448,0.8250,0.4920,0.4347,0.4130,0.3913,0.5272,0.5170,0.5072
|
| 93 |
+
RN101-quickgelu,openai,119.69,25.5,0.6249,0.5804,0.8228,0.8852,0.7900,0.9490,0.9740,0.3069,0.5546,0.6603,0.4982,0.7448,0.8250,0.4920,0.4347,0.4130,0.3913,0.5272,0.5170,0.5072
|
| 94 |
+
ViT-B-16,commonpool_l_image_s1b_b8k,149.62,41.09,0.6164,0.5162,0.7908,0.8700,0.6890,0.8830,0.9270,0.2907,0.5449,0.6628,0.4338,0.6882,0.7902,0.5339,0.4932,0.4787,0.4643,0.5609,0.5513,0.5421
|
| 95 |
+
ViT-B-16,commonpool_l_basic_s1b_b8k,149.62,41.09,0.6132,0.5250,0.7880,0.8670,0.6780,0.8780,0.9330,0.2862,0.5411,0.6535,0.4304,0.6844,0.7826,0.5285,0.4872,0.4812,0.4753,0.5517,0.5434,0.5355
|
| 96 |
+
ViT-B-16,commonpool_l_text_s1b_b8k,149.62,41.09,0.6126,0.5336,0.7954,0.8650,0.6820,0.8880,0.9320,0.3020,0.5538,0.6674,0.4440,0.7012,0.7906,0.5147,0.4815,0.4570,0.4326,0.5394,0.5329,0.5266
|
| 97 |
+
RN50,openai,102.01,18.18,0.6124,0.5736,0.8318,0.9004,0.8000,0.9500,0.9790,0.2854,0.5291,0.6459,0.4884,0.7278,0.8212,0.4766,0.3682,0.3622,0.3562,0.5318,0.5127,0.4945
|
| 98 |
+
RN50-quickgelu,openai,102.01,18.18,0.6124,0.5736,0.8318,0.9004,0.8000,0.9500,0.9790,0.2854,0.5291,0.6459,0.4884,0.7278,0.8212,0.4766,0.3682,0.3622,0.3562,0.5318,0.5127,0.4945
|
| 99 |
+
ViT-B-16,commonpool_l_clip_s1b_b8k,149.62,41.09,0.6054,0.5102,0.7764,0.8564,0.6810,0.8940,0.9430,0.2880,0.5368,0.6492,0.4436,0.6938,0.7954,0.5133,0.4493,0.4359,0.4225,0.5472,0.5377,0.5287
|
| 100 |
+
ViT-B-16,commonpool_l_s1b_b8k,149.62,41.09,0.5635,0.4186,0.7040,0.7952,0.5710,0.8260,0.8940,0.2224,0.4565,0.5694,0.3486,0.6026,0.7096,0.5272,0.5029,0.4777,0.4526,0.5532,0.5428,0.5329
|
| 101 |
+
nllb-clip-base,v1,501.89,369.6,0.5562,0.4740,0.7554,0.8350,0.5660,0.8210,0.8920,0.2649,0.5150,0.6321,0.3514,0.6100,0.7204,0.4708,0.3890,0.3904,0.3919,0.5085,0.4962,0.4844
|
| 102 |
+
RN50-quickgelu,cc12m,102.01,18.18,0.5531,0.4696,0.7432,0.8284,0.6050,0.8600,0.9100,0.2412,0.4868,0.6024,0.3370,0.6136,0.7180,0.4644,0.4136,0.3876,0.3617,0.4970,0.4887,0.4807
|
| 103 |
+
RN50,cc12m,102.01,18.18,0.5475,0.4594,0.7336,0.8234,0.6120,0.8540,0.9070,0.2367,0.4787,0.5947,0.3412,0.6072,0.7154,0.4553,0.4081,0.3828,0.3577,0.4918,0.4782,0.4653
|
| 104 |
+
RN101-quickgelu,yfcc15m,119.69,25.5,0.4846,0.3474,0.6126,0.7192,0.5370,0.8030,0.8900,0.1779,0.3908,0.5043,0.2872,0.5456,0.6544,0.4226,0.3363,0.3147,0.2933,0.4723,0.4566,0.4416
|
| 105 |
+
RN101,yfcc15m,119.69,25.5,0.4796,0.3402,0.6034,0.7124,0.5450,0.8010,0.8810,0.1772,0.3895,0.5040,0.3036,0.5536,0.6652,0.4088,0.3252,0.2987,0.2724,0.4643,0.4435,0.4239
|
| 106 |
+
RN50-quickgelu,yfcc15m,102.01,18.18,0.4716,0.3180,0.5876,0.6968,0.4910,0.7840,0.8870,0.1645,0.3758,0.4891,0.2720,0.5260,0.6442,0.4209,0.3393,0.3130,0.2867,0.4634,0.4549,0.4469
|
| 107 |
+
RN50,yfcc15m,102.01,18.18,0.4709,0.3092,0.5884,0.6952,0.5120,0.8040,0.8850,0.1645,0.3747,0.4894,0.2826,0.5350,0.6546,0.4106,0.3249,0.3023,0.2799,0.4536,0.4448,0.4364
|
| 108 |
+
ViT-B-32,commonpool_m_image_s128m_b4k,151.28,14.78,0.3976,0.1896,0.4156,0.5312,0.2710,0.5300,0.6360,0.1054,0.2710,0.3703,0.1654,0.3758,0.4898,0.4804,0.4206,0.4026,0.3847,0.5261,0.5050,0.4849
|
| 109 |
+
ViT-B-32,commonpool_m_clip_s128m_b4k,151.28,14.78,0.3923,0.1890,0.4106,0.5238,0.3040,0.5540,0.6590,0.1127,0.2718,0.3719,0.1826,0.3960,0.5070,0.4519,0.3685,0.3581,0.3478,0.4947,0.4815,0.4689
|
| 110 |
+
ViT-B-32,commonpool_m_text_s128m_b4k,151.28,14.78,0.3917,0.1872,0.4200,0.5344,0.2900,0.5350,0.6590,0.1086,0.2712,0.3731,0.1818,0.3920,0.5008,0.4540,0.3863,0.3618,0.3373,0.5038,0.4831,0.4635
|
| 111 |
+
ViT-B-32,commonpool_m_basic_s128m_b4k,151.28,14.78,0.3907,0.1874,0.4172,0.5350,0.2500,0.5190,0.6530,0.1007,0.2559,0.3578,0.1658,0.3528,0.4654,0.4727,0.4245,0.4015,0.3786,0.5182,0.4951,0.4732
|
| 112 |
+
ViT-B-32,datacomp_m_s128m_b4k,151.28,14.78,0.3756,0.1812,0.4036,0.5188,0.2670,0.5200,0.6320,0.1100,0.2699,0.3750,0.1714,0.3770,0.4886,0.4337,0.3570,0.3287,0.3005,0.4914,0.4667,0.4433
|
| 113 |
+
ViT-B-32,commonpool_m_laion_s128m_b4k,151.28,14.78,0.3741,0.1792,0.3964,0.5120,0.2760,0.5330,0.6220,0.1052,0.2606,0.3637,0.1654,0.3592,0.4660,0.4409,0.3585,0.3348,0.3113,0.4894,0.4743,0.4600
|
| 114 |
+
ViT-B-32,commonpool_m_s128m_b4k,151.28,14.78,0.3449,0.1268,0.3164,0.4252,0.1930,0.4140,0.5360,0.0701,0.1941,0.2803,0.1246,0.3002,0.3996,0.4759,0.4354,0.3983,0.3614,0.5273,0.5003,0.4747
|
| 115 |
+
ViT-B-32,commonpool_s_text_s13m_b4k,151.28,14.78,0.1922,0.0278,0.0950,0.1462,0.0570,0.1300,0.2000,0.0170,0.0551,0.0906,0.0258,0.0814,0.1234,0.3964,0.3312,0.3120,0.2929,0.4487,0.4231,0.3987
|
| 116 |
+
ViT-B-32,commonpool_s_basic_s13m_b4k,151.28,14.78,0.1874,0.0256,0.0924,0.1466,0.0400,0.1220,0.2000,0.0144,0.0487,0.0782,0.0192,0.0646,0.1024,0.4008,0.3164,0.3033,0.2903,0.4526,0.4315,0.4115
|
| 117 |
+
ViT-B-32,commonpool_s_clip_s13m_b4k,151.28,14.78,0.1857,0.0286,0.0938,0.1454,0.0400,0.1370,0.2070,0.0157,0.0515,0.0847,0.0292,0.0794,0.1206,0.3801,0.3282,0.2994,0.2708,0.4299,0.4055,0.3823
|
| 118 |
+
ViT-B-32,commonpool_s_s13m_b4k,151.28,14.78,0.1789,0.0214,0.0690,0.1138,0.0300,0.1080,0.1760,0.0088,0.0351,0.0601,0.0176,0.0568,0.0902,0.3979,0.3338,0.3126,0.2914,0.4484,0.4249,0.4025
|
| 119 |
+
ViT-B-32,commonpool_s_image_s13m_b4k,151.28,14.78,0.1536,0.0142,0.0594,0.0960,0.0200,0.0740,0.1160,0.0109,0.0385,0.0641,0.0150,0.0500,0.0842,0.3552,0.2669,0.2525,0.2382,0.4123,0.3875,0.3640
|
| 120 |
+
ViT-B-32,datacomp_s_s13m_b4k,151.28,14.78,0.1536,0.0142,0.0594,0.0960,0.0200,0.0740,0.1160,0.0109,0.0385,0.0641,0.0150,0.0500,0.0842,0.3552,0.2669,0.2525,0.2382,0.4123,0.3875,0.3640
|
| 121 |
+
ViT-B-32,commonpool_s_laion_s13m_b4k,151.28,14.78,0.1527,0.0176,0.0678,0.1056,0.0270,0.0870,0.1440,0.0102,0.0363,0.0607,0.0140,0.0442,0.0770,0.3463,0.2607,0.2410,0.2215,0.4049,0.3795,0.3554
|
| 122 |
+
coca_ViT-B-32,mscoco_finetuned_laion2b_s13b_b90k,253.56,33.34,0.1306,0.0074,0.0214,0.0436,0.0110,0.0490,0.0990,0.0033,0.0137,0.0249,0.0088,0.0338,0.0552,0.3299,0.2484,0.2329,0.2175,0.3873,0.3604,0.3348
|
hlip/open_clip/docs/scaling.png
ADDED
|
Git LFS Details
|
hlip/open_clip/docs/script_examples/clipa/vit_b16/i50_t16_finetune.sh
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torchrun --nproc_per_node 8 -m open_clip_train.main \
|
| 2 |
+
--save-frequency 1 \
|
| 3 |
+
--save-most-recent \
|
| 4 |
+
--zeroshot-frequency 1 \
|
| 5 |
+
--train-data '/path/to/laion-400m' \
|
| 6 |
+
--dataset-type webdataset \
|
| 7 |
+
--lr "2.56e-5" \
|
| 8 |
+
--beta1 0.9 \
|
| 9 |
+
--beta2 0.95 \
|
| 10 |
+
--warmup 3072 \
|
| 11 |
+
--wd 0.2 \
|
| 12 |
+
--batch-size 1024 \
|
| 13 |
+
--aug-cfg scale='(0.4, 1.0)' \
|
| 14 |
+
--epochs 1 \
|
| 15 |
+
--train-num-samples 131072000 \
|
| 16 |
+
--workers 6 \
|
| 17 |
+
--model ViT-B-16-CL16 \
|
| 18 |
+
--pretrained '/path/to/ckpt' \
|
| 19 |
+
--precision 'amp_bf16' \
|
| 20 |
+
--ddp-static-graph \
|
| 21 |
+
--local-loss \
|
| 22 |
+
--gather-with-grad \
|
| 23 |
+
--grad-checkpointing \
|
| 24 |
+
--log-every-n-steps 256 \
|
| 25 |
+
--seed 0 \
|
| 26 |
+
--logs ./logs/ \
|
| 27 |
+
--imagenet-val '/path/to/imagenet/val'
|
hlip/open_clip/docs/script_examples/clipa/vit_b16/i50_t16_pretrain.sh
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torchrun --nproc_per_node 8 -m open_clip_train.main \
|
| 2 |
+
--save-frequency 1 \
|
| 3 |
+
--save-most-recent \
|
| 4 |
+
--zeroshot-frequency 1 \
|
| 5 |
+
--train-data '/path/to/laion-400m' \
|
| 6 |
+
--dataset-type webdataset \
|
| 7 |
+
--lr "2.048e-3" \
|
| 8 |
+
--beta1 0.9 \
|
| 9 |
+
--beta2 0.95 \
|
| 10 |
+
--warmup 782 \
|
| 11 |
+
--wd 0.2 \
|
| 12 |
+
--batch-size 8192 \
|
| 13 |
+
--aug-cfg scale='(0.4, 1.0)' \
|
| 14 |
+
--epochs 6 \
|
| 15 |
+
--workers 6 \
|
| 16 |
+
--model ViT-B-16-CL16 \
|
| 17 |
+
--precision 'amp_bf16' \
|
| 18 |
+
--ddp-static-graph \
|
| 19 |
+
--local-loss \
|
| 20 |
+
--gather-with-grad \
|
| 21 |
+
--force-image-size 112 \
|
| 22 |
+
--grad-checkpointing \
|
| 23 |
+
--log-every-n-steps 32 \
|
| 24 |
+
--seed 0 \
|
| 25 |
+
--logs ./logs/ \
|
| 26 |
+
--imagenet-val '/path/to/imagenet/val'
|
hlip/open_clip/docs/script_examples/clipa/vit_l16/i17_t16_finetune.sh
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torchrun --nproc_per_node 8 -m open_clip_train.main \
|
| 2 |
+
--save-frequency 1 \
|
| 3 |
+
--save-most-recent \
|
| 4 |
+
--zeroshot-frequency 1 \
|
| 5 |
+
--train-data '/path/to/laion-400m' \
|
| 6 |
+
--dataset-type webdataset \
|
| 7 |
+
--lr "2.24e-5" \
|
| 8 |
+
--beta1 0.9 \
|
| 9 |
+
--beta2 0.95 \
|
| 10 |
+
--warmup 3571 \
|
| 11 |
+
--wd 0.2 \
|
| 12 |
+
--batch-size 896 \
|
| 13 |
+
--aug-cfg scale='(0.4, 1.0)' color_jitter='(0.32, 0.32, 0.32, 0.08)' color_jitter_prob=0.8 gray_scale_prob=0.2 \
|
| 14 |
+
--epochs 1 \
|
| 15 |
+
--train-num-samples 131072000 \
|
| 16 |
+
--workers 6 \
|
| 17 |
+
--model ViT-L-16-CL16-GAP \
|
| 18 |
+
--pretrained '/path/to/ckpt' \
|
| 19 |
+
--precision 'amp_bf16' \
|
| 20 |
+
--ddp-static-graph \
|
| 21 |
+
--local-loss \
|
| 22 |
+
--gather-with-grad \
|
| 23 |
+
--grad-checkpointing \
|
| 24 |
+
--log-every-n-steps 293 \
|
| 25 |
+
--seed 0 \
|
| 26 |
+
--logs ./logs/ \
|
| 27 |
+
--imagenet-val '/path/to/imagenet/val'
|
hlip/open_clip/docs/script_examples/clipa/vit_l16/i17_t16_pretrain.sh
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torchrun --nproc_per_node 8 -m open_clip_train.main \
|
| 2 |
+
--save-frequency 1 \
|
| 3 |
+
--save-most-recent \
|
| 4 |
+
--zeroshot-frequency 1 \
|
| 5 |
+
--train-data '/path/to/laion-400m' \
|
| 6 |
+
--dataset-type webdataset \
|
| 7 |
+
--lr "1.024e-3" \
|
| 8 |
+
--beta1 0.9 \
|
| 9 |
+
--beta2 0.95 \
|
| 10 |
+
--warmup 1563 \
|
| 11 |
+
--wd 0.2 \
|
| 12 |
+
--batch-size 4096 \
|
| 13 |
+
--aug-cfg scale='(0.4, 1.0)' color_jitter='(0.32, 0.32, 0.32, 0.08)' color_jitter_prob=0.8 gray_scale_prob=0.2 \
|
| 14 |
+
--epochs 6 \
|
| 15 |
+
--workers 6 \
|
| 16 |
+
--model ViT-L-16-CL16-GAP \
|
| 17 |
+
--precision 'amp_bf16' \
|
| 18 |
+
--ddp-static-graph \
|
| 19 |
+
--local-loss \
|
| 20 |
+
--gather-with-grad \
|
| 21 |
+
--force-image-size 64 \
|
| 22 |
+
--grad-checkpointing \
|
| 23 |
+
--log-every-n-steps 64 \
|
| 24 |
+
--seed 0 \
|
| 25 |
+
--logs ./logs/ \
|
| 26 |
+
--imagenet-val '/path/to/imagenet/val'
|
hlip/open_clip/docs/script_examples/clipa/vit_l16/i37_t8_finetune.sh
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torchrun --nproc_per_node 8 -m open_clip_train.main \
|
| 2 |
+
--save-frequency 1 \
|
| 3 |
+
--save-most-recent \
|
| 4 |
+
--zeroshot-frequency 1 \
|
| 5 |
+
--train-data '/path/to/laion-400m' \
|
| 6 |
+
--dataset-type webdataset \
|
| 7 |
+
--lr "2.24e-5" \
|
| 8 |
+
--beta1 0.9 \
|
| 9 |
+
--beta2 0.95 \
|
| 10 |
+
--warmup 3571 \
|
| 11 |
+
--wd 0.2 \
|
| 12 |
+
--batch-size 896 \
|
| 13 |
+
--aug-cfg scale='(0.4, 1.0)' color_jitter='(0.32, 0.32, 0.32, 0.08)' color_jitter_prob=0.8 gray_scale_prob=0.2 \
|
| 14 |
+
--epochs 1 \
|
| 15 |
+
--train-num-samples 131072000 \
|
| 16 |
+
--workers 6 \
|
| 17 |
+
--model ViT-L-16-CL32-GAP \
|
| 18 |
+
--pretrained '/path/to/ckpt' \
|
| 19 |
+
--precision 'amp_bf16' \
|
| 20 |
+
--ddp-static-graph \
|
| 21 |
+
--local-loss \
|
| 22 |
+
--gather-with-grad \
|
| 23 |
+
--grad-checkpointing \
|
| 24 |
+
--log-every-n-steps 293 \
|
| 25 |
+
--seed 0 \
|
| 26 |
+
--logs ./logs/ \
|
| 27 |
+
--imagenet-val '/path/to/imagenet/val'
|
hlip/open_clip/docs/script_examples/clipa/vit_l16/i37_t8_pretrain.sh
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torchrun --nproc_per_node 8 -m open_clip_train.main \
|
| 2 |
+
--save-frequency 1 \
|
| 3 |
+
--save-most-recent \
|
| 4 |
+
--zeroshot-frequency 1 \
|
| 5 |
+
--train-data '/path/to/laion-400m' \
|
| 6 |
+
--dataset-type webdataset \
|
| 7 |
+
--lr "1.024e-3" \
|
| 8 |
+
--beta1 0.9 \
|
| 9 |
+
--beta2 0.95 \
|
| 10 |
+
--warmup 1563 \
|
| 11 |
+
--wd 0.2 \
|
| 12 |
+
--batch-size 4096 \
|
| 13 |
+
--aug-cfg scale='(0.4, 1.0)' color_jitter='(0.32, 0.32, 0.32, 0.08)' color_jitter_prob=0.8 gray_scale_prob=0.2 \
|
| 14 |
+
--epochs 6 \
|
| 15 |
+
--workers 6 \
|
| 16 |
+
--model ViT-L-16-CL8-Syntax-GAP \
|
| 17 |
+
--precision 'amp_bf16' \
|
| 18 |
+
--ddp-static-graph \
|
| 19 |
+
--local-loss \
|
| 20 |
+
--gather-with-grad \
|
| 21 |
+
--force-image-size 96 \
|
| 22 |
+
--grad-checkpointing \
|
| 23 |
+
--log-every-n-steps 64 \
|
| 24 |
+
--seed 0 \
|
| 25 |
+
--logs ./logs/ \
|
| 26 |
+
--imagenet-val '/path/to/imagenet/val'
|
hlip/open_clip/docs/script_examples/clipav2/vit_h14/i257_t32_finetunex4.sh
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# have not been tested. use it at your own discretion
|
| 2 |
+
# the original experiment was run on tpu v3-256.
|
| 3 |
+
# this example script assumes 8 gpus, each with huge memory. Tune batchsize, warmup, and lr accordingly if you have different machine setups.
|
| 4 |
+
torchrun --nproc_per_node 8 -m open_clip_train.main \
|
| 5 |
+
--save-frequency 1 \
|
| 6 |
+
--save-most-recent \
|
| 7 |
+
--zeroshot-frequency 1 \
|
| 8 |
+
--train-data '/path/to/laion2b_or_datacomp1b' \
|
| 9 |
+
--train-num-samples 131072000 \
|
| 10 |
+
--dataset-type webdataset \
|
| 11 |
+
--lr "5.12e-5" \
|
| 12 |
+
--beta1 0.9 \
|
| 13 |
+
--beta2 0.95 \
|
| 14 |
+
--warmup 800 \
|
| 15 |
+
--wd 0.2 \
|
| 16 |
+
--batch-size 4096 \
|
| 17 |
+
--aug-cfg scale='(0.4, 1.0)' color_jitter='(0.32, 0.32, 0.32, 0.08)' color_jitter_prob=0.8 gray_scale_prob=0.2 \
|
| 18 |
+
--epochs 4 \
|
| 19 |
+
--workers 6 \
|
| 20 |
+
--model ViT-H-14-CL32-GAP \
|
| 21 |
+
--pretrained '/path/to/pretrain84_ckpt' \
|
| 22 |
+
--precision 'amp_bf16' \
|
| 23 |
+
--ddp-static-graph \
|
| 24 |
+
--local-loss \
|
| 25 |
+
--gather-with-grad \
|
| 26 |
+
--force-image-size 224 \
|
| 27 |
+
--force-patch-dropout 0.3 \
|
| 28 |
+
--grad-checkpointing \
|
| 29 |
+
--log-every-n-steps 64 \
|
| 30 |
+
--seed 0 \
|
| 31 |
+
--logs ./logs/ \
|
| 32 |
+
--imagenet-val '/path/to/imagenet/val'
|
hlip/open_clip/docs/script_examples/clipav2/vit_h14/i50_t8_pretrain.sh
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# have not been tested. use it at your own discretion
|
| 2 |
+
# the original experiment was run on tpu v3-256.
|
| 3 |
+
# this example script assumes 8 gpus, each with huge memory. Tune batchsize, warmup, and lr accordingly if you have different machine setups.
|
| 4 |
+
torchrun --nproc_per_node 8 -m open_clip_train.main \
|
| 5 |
+
--save-frequency 1 \
|
| 6 |
+
--save-most-recent \
|
| 7 |
+
--zeroshot-frequency 1 \
|
| 8 |
+
--train-data '/path/to/laion2b_or_datacomp1b' \
|
| 9 |
+
--train-num-samples 4e8 \
|
| 10 |
+
--dataset-type webdataset \
|
| 11 |
+
--lr "2.048e-3" \
|
| 12 |
+
--beta1 0.9 \
|
| 13 |
+
--beta2 0.95 \
|
| 14 |
+
--warmup 3200 \
|
| 15 |
+
--wd 0.2 \
|
| 16 |
+
--batch-size 8192 \
|
| 17 |
+
--aug-cfg scale='(0.4, 1.0)' color_jitter='(0.32, 0.32, 0.32, 0.08)' color_jitter_prob=0.8 gray_scale_prob=0.2 \
|
| 18 |
+
--epochs 32 \
|
| 19 |
+
--workers 6 \
|
| 20 |
+
--model ViT-H-14-CL8-Syntax-GAP \
|
| 21 |
+
--precision 'amp_bf16' \
|
| 22 |
+
--ddp-static-graph \
|
| 23 |
+
--local-loss \
|
| 24 |
+
--gather-with-grad \
|
| 25 |
+
--force-image-size 84 \
|
| 26 |
+
--grad-checkpointing \
|
| 27 |
+
--log-every-n-steps 32 \
|
| 28 |
+
--seed 0 \
|
| 29 |
+
--logs ./logs/ \
|
| 30 |
+
--imagenet-val '/path/to/imagenet/val'
|
hlip/open_clip/docs/script_examples/clipav2/vit_h14/i577_t32_finetunex1.sh
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# have not been tested. use it at your own discretion
|
| 2 |
+
# the original experiment was run on tpu v3-256.
|
| 3 |
+
# this example script assumes 8 gpus, each with huge memory. Tune batchsize, warmup, and lr accordingly if you have different machine setups.
|
| 4 |
+
torchrun --nproc_per_node 8 -m open_clip_train.main \
|
| 5 |
+
--save-frequency 1 \
|
| 6 |
+
--save-most-recent \
|
| 7 |
+
--zeroshot-frequency 1 \
|
| 8 |
+
--train-data '/path/to/laion2b_or_datacomp1b' \
|
| 9 |
+
--train-num-samples 131072000 \
|
| 10 |
+
--dataset-type webdataset \
|
| 11 |
+
--lr "6.4e-6" \
|
| 12 |
+
--beta1 0.9 \
|
| 13 |
+
--beta2 0.95 \
|
| 14 |
+
--warmup 1600 \
|
| 15 |
+
--wd 0.2 \
|
| 16 |
+
--batch-size 2048 \
|
| 17 |
+
--aug-cfg scale='(0.4, 1.0)' color_jitter='(0.32, 0.32, 0.32, 0.08)' color_jitter_prob=0.8 gray_scale_prob=0.2 \
|
| 18 |
+
--epochs 1 \
|
| 19 |
+
--workers 6 \
|
| 20 |
+
--model ViT-H-14-CL32-GAP \
|
| 21 |
+
--pretrained '/path/to/finetune224_ckpt' \
|
| 22 |
+
--precision 'amp_bf16' \
|
| 23 |
+
--ddp-static-graph \
|
| 24 |
+
--local-loss \
|
| 25 |
+
--gather-with-grad \
|
| 26 |
+
--force-image-size 336 \
|
| 27 |
+
--force-patch-dropout 0.4 \
|
| 28 |
+
--grad-checkpointing \
|
| 29 |
+
--log-every-n-steps 64 \
|
| 30 |
+
--seed 0 \
|
| 31 |
+
--logs ./logs/ \
|
| 32 |
+
--imagenet-val '/path/to/imagenet/val'
|
hlip/open_clip/docs/script_examples/stability_example.sh
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
#SBATCH --partition=g40423
|
| 3 |
+
#SBATCH --job-name=testopenclip
|
| 4 |
+
#SBATCH --nodes 30
|
| 5 |
+
#SBATCH --ntasks-per-node=8
|
| 6 |
+
#SBATCH --cpus-per-task=12
|
| 7 |
+
#SBATCH --output=%x_%j.out
|
| 8 |
+
#SBATCH --comment=laion
|
| 9 |
+
#SBATCH --open-mode=append
|
| 10 |
+
#SBATCH --exclusive
|
| 11 |
+
|
| 12 |
+
module load openmpi
|
| 13 |
+
module load cuda/11.7
|
| 14 |
+
|
| 15 |
+
export MASTER_ADDR=`hostname`
|
| 16 |
+
export MASTER_PORT=12802
|
| 17 |
+
export NCCL_PROTO=simple
|
| 18 |
+
export FI_EFA_FORK_SAFE=1
|
| 19 |
+
export FI_LOG_LEVEL=1
|
| 20 |
+
export FI_EFA_USE_DEVICE_RDMA=1
|
| 21 |
+
export NCCL_DEBUG=info
|
| 22 |
+
|
| 23 |
+
export PYTHONFAULTHANDLER=1
|
| 24 |
+
|
| 25 |
+
export CUDA_LAUNCH_BLOCKING=0
|
| 26 |
+
export OMPI_MCA_mtl_base_verbose=1
|
| 27 |
+
export FI_EFA_ENABLE_SHM_TRANSFER=0
|
| 28 |
+
export FI_PROVIDER=efa
|
| 29 |
+
export FI_EFA_TX_MIN_CREDITS=64
|
| 30 |
+
export NCCL_TREE_THRESHOLD=0
|
| 31 |
+
|
| 32 |
+
cd /admin/home-mitchellw/open_clip/src
|
| 33 |
+
export PYTHONPATH="$PYTHONPATH:/admin/home-mitchellw/open_clip/src"
|
| 34 |
+
|
| 35 |
+
EXP_NAME="test-B-32-laion5b-lr1e-3-bs90k"
|
| 36 |
+
|
| 37 |
+
srun --comment laion --cpu_bind=v --accel-bind=gn python -m open_clip_train.main \
|
| 38 |
+
--save-frequency 1 \
|
| 39 |
+
--train-data="pipe:aws s3 cp s3://s-datasets/laion5b/{laion2B-data/{000000..231349}.tar,laion2B-multi-data/{000000..226687}.tar,laion1B-nolang-data/{000000..127231}.tar} -" \
|
| 40 |
+
--train-num-samples 135646078 \
|
| 41 |
+
--dataset-type webdataset \
|
| 42 |
+
--dataset-resampled \
|
| 43 |
+
--warmup 2000 \
|
| 44 |
+
--batch-size=375 \
|
| 45 |
+
--epochs=97 \
|
| 46 |
+
--lr 1e-3 \
|
| 47 |
+
--workers=8 \
|
| 48 |
+
--report-to wandb \
|
| 49 |
+
--name ${EXP_NAME} \
|
| 50 |
+
--logs /scratch/logs/ \
|
| 51 |
+
--model ViT-B-32 \
|
| 52 |
+
--seed 0 \
|
| 53 |
+
--ddp-static-graph \
|
| 54 |
+
--local-loss \
|
| 55 |
+
--gather-with-grad \
|
| 56 |
+
--grad-checkpointing \
|
| 57 |
+
--precision amp_bfloat16 \
|
| 58 |
+
--wandb-project-name open_clip6 \
|
| 59 |
+
--resume "latest" \
|
| 60 |
+
--remote-sync s3://s-laion/mitchellw/logs
|
hlip/open_clip/pyproject.toml
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[build-system]
|
| 2 |
+
requires = ["pdm-backend"]
|
| 3 |
+
build-backend = "pdm.backend"
|
| 4 |
+
|
| 5 |
+
[project]
|
| 6 |
+
name = "open_clip_torch"
|
| 7 |
+
# NOTE for full list of authors see https://github.com/mlfoundations/open_clip?tab=readme-ov-file#citing
|
| 8 |
+
# below covers most active / recent maintainers
|
| 9 |
+
authors = [
|
| 10 |
+
{name = "Ross Wightman", email = "ross@huggingface.co"},
|
| 11 |
+
{name = "Gabriel Ilharco"},
|
| 12 |
+
{name = "Mitchell Wortsman"},
|
| 13 |
+
{name = "Romain Beaumont"},
|
| 14 |
+
]
|
| 15 |
+
description = "Open reproduction of consastive language-image pretraining (CLIP) and related."
|
| 16 |
+
readme = "README.md"
|
| 17 |
+
requires-python = ">=3.9"
|
| 18 |
+
keywords = ["pytorch", "clip", "image-text", "language-image", "multimodal"]
|
| 19 |
+
license = {text = "MIT"}
|
| 20 |
+
classifiers = [
|
| 21 |
+
'Development Status :: 4 - Beta',
|
| 22 |
+
'Intended Audience :: Education',
|
| 23 |
+
'Intended Audience :: Science/Research',
|
| 24 |
+
'License :: OSI Approved :: MIT License',
|
| 25 |
+
'Programming Language :: Python :: 3.9',
|
| 26 |
+
'Programming Language :: Python :: 3.10',
|
| 27 |
+
'Programming Language :: Python :: 3.11',
|
| 28 |
+
'Programming Language :: Python :: 3.12',
|
| 29 |
+
'Topic :: Scientific/Engineering',
|
| 30 |
+
'Topic :: Scientific/Engineering :: Artificial Intelligence',
|
| 31 |
+
'Topic :: Software Development',
|
| 32 |
+
'Topic :: Software Development :: Libraries',
|
| 33 |
+
'Topic :: Software Development :: Libraries :: Python Modules',
|
| 34 |
+
]
|
| 35 |
+
dependencies = [
|
| 36 |
+
'torch>=2.0',
|
| 37 |
+
'torchvision',
|
| 38 |
+
'regex',
|
| 39 |
+
'ftfy',
|
| 40 |
+
'tqdm',
|
| 41 |
+
'huggingface-hub',
|
| 42 |
+
'safetensors',
|
| 43 |
+
'timm>=1.0.17',
|
| 44 |
+
]
|
| 45 |
+
dynamic = ["version"]
|
| 46 |
+
|
| 47 |
+
[project.optional-dependencies]
|
| 48 |
+
training = [
|
| 49 |
+
'torch>=2.0',
|
| 50 |
+
'webdataset>=0.2.5,<=0.2.86',
|
| 51 |
+
'pandas',
|
| 52 |
+
'transformers[sentencepiece]',
|
| 53 |
+
'timm>=1.0.17',
|
| 54 |
+
'fsspec',
|
| 55 |
+
]
|
| 56 |
+
test = [
|
| 57 |
+
'pytest-split',
|
| 58 |
+
'pytest',
|
| 59 |
+
'open_clip_torch[training]'
|
| 60 |
+
]
|
| 61 |
+
|
| 62 |
+
[project.urls]
|
| 63 |
+
homepage = "https://github.com/mlfoundations/open_clip"
|
| 64 |
+
repository = "https://github.com/mlfoundations/open_clip"
|
| 65 |
+
|
| 66 |
+
[tool.pdm.version]
|
| 67 |
+
source = "file"
|
| 68 |
+
path = "src/open_clip/version.py"
|
| 69 |
+
|
| 70 |
+
[tool.pdm.build]
|
| 71 |
+
excludes = ["./**/.git", "./**/logs/*"]
|
| 72 |
+
package-dir = "src"
|
| 73 |
+
includes = ["src/open_clip", "src/open_clip_train"]
|
| 74 |
+
|
| 75 |
+
[tool.pytest.ini_options]
|
| 76 |
+
testpaths = ['tests']
|
| 77 |
+
markers = [
|
| 78 |
+
'regression_test'
|
| 79 |
+
]
|
hlip/open_clip/pytest.ini
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[pytest]
|
| 2 |
+
markers =
|
| 3 |
+
regression_test
|
hlip/open_clip/requirements-test.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pytest-split==0.8.0
|
| 2 |
+
pytest==7.2.0
|
| 3 |
+
transformers[sentencepiece]
|
| 4 |
+
timm>=1.0.17
|
hlip/open_clip/requirements-training.txt
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch>=2.0
|
| 2 |
+
torchvision
|
| 3 |
+
webdataset>=0.2.5,<=0.2.86
|
| 4 |
+
regex
|
| 5 |
+
ftfy
|
| 6 |
+
tqdm
|
| 7 |
+
pandas
|
| 8 |
+
braceexpand
|
| 9 |
+
huggingface_hub
|
| 10 |
+
safetensors
|
| 11 |
+
transformers[sentencepiece]
|
| 12 |
+
timm>=1.0.17
|
| 13 |
+
fsspec
|
hlip/open_clip/requirements.txt
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch>=2.0
|
| 2 |
+
torchvision
|
| 3 |
+
regex
|
| 4 |
+
ftfy
|
| 5 |
+
tqdm
|
| 6 |
+
huggingface_hub
|
| 7 |
+
safetensors
|
| 8 |
+
timm
|
hlip/open_clip/scripts/clipav1_vit_l16_i37_t8.sh
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# eval on a single gpu
|
| 2 |
+
CUDA_VISIBLE_DEVICES=2 TORCH_CUDNN_V8_API_ENABLED=1 TFDS_PREFETCH_SIZE=8192 python3 -m open_clip_train.main \
|
| 3 |
+
--model ViT-L-16-CL32-GAP \
|
| 4 |
+
--pretrained "/path/to/clipa_vit_l16_i37_t8.pt" \
|
| 5 |
+
--seed 0 \
|
| 6 |
+
--imagenet-val '/path/to/ImageNet/val'
|
hlip/open_clip/scripts/clipav2_vit_h14_i84_224_336_cl32_gap_datacomp1b.sh
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
CUDA_VISIBLE_DEVICES=1 python3 -m open_clip_train.main \
|
| 2 |
+
--model ViT-H-14-CL32-GAP-BigVision \
|
| 3 |
+
--pretrained "/path/to/vit_h14_i84_224_336_cl32_gap_datacomp1b.pt" \
|
| 4 |
+
--force-image-size 336 \
|
| 5 |
+
--square-resize-only \
|
| 6 |
+
--interpolation 'bilinear' \
|
| 7 |
+
--image-mean 0.485 0.456 0.406 \
|
| 8 |
+
--image-std 0.229 0.224 0.225 \
|
| 9 |
+
--seed 0 \
|
| 10 |
+
--imagenet-val '/path/to/ImageNet/val'
|
hlip/open_clip/scripts/h14_224_32_finetune.sh
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 64k batchsize for 2.048e-3 lr
|
| 2 |
+
TORCH_CUDNN_V8_API_ENABLED=1 torchrun --nproc_per_node 8 -m open_clip_train.main \
|
| 3 |
+
--save-frequency 1 \
|
| 4 |
+
--save-most-recent \
|
| 5 |
+
--zeroshot-frequency 1 \
|
| 6 |
+
--train-data '/path/to/laion' \
|
| 7 |
+
--dataset-type webdataset \
|
| 8 |
+
--lr "2.048e-3" \
|
| 9 |
+
--beta1 0.9 \
|
| 10 |
+
--beta2 0.95 \
|
| 11 |
+
--warmup 782 \
|
| 12 |
+
--wd 0.2 \
|
| 13 |
+
--batch-size 4096 \
|
| 14 |
+
--aug-cfg scale='(0.4, 1.0)' color_jitter='(0.32, 0.32, 0.32, 0.08)' color_jitter_prob=0.8 gray_scale_prob=0.2 \
|
| 15 |
+
--epochs=7 \
|
| 16 |
+
--workers=6 \
|
| 17 |
+
--model ViT-H-14-CL32-GAP \
|
| 18 |
+
--precision 'amp_bf16' \
|
| 19 |
+
--local-loss \
|
| 20 |
+
--gather-with-grad \
|
| 21 |
+
--force-image-size 224 \
|
| 22 |
+
--grad-checkpointing \
|
| 23 |
+
--log-every-n-steps 32 \
|
| 24 |
+
--seed 0 \
|
| 25 |
+
--logs ./logs/ \
|
| 26 |
+
--imagenet-val '/path/to/ImageNet/val' \
|
| 27 |
+
--name 'name' \
|
| 28 |
+
--report-to "wandb" \
|
| 29 |
+
--wandb-project-name "project_name"
|
| 30 |
+
|
| 31 |
+
|
hlip/open_clip/scripts/h14_84_8_pretrain.sh
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 64k batchsize for 2.048e-3 lr
|
| 2 |
+
TORCH_CUDNN_V8_API_ENABLED=1 torchrun --nproc_per_node 8 -m open_clip_train.main \
|
| 3 |
+
--save-frequency 1 \
|
| 4 |
+
--save-most-recent \
|
| 5 |
+
--zeroshot-frequency 1 \
|
| 6 |
+
--train-data '/path/to/laion' \
|
| 7 |
+
--dataset-type webdataset \
|
| 8 |
+
--lr "2.048e-3" \
|
| 9 |
+
--beta1 0.9 \
|
| 10 |
+
--beta2 0.95 \
|
| 11 |
+
--warmup 782 \
|
| 12 |
+
--wd 0.2 \
|
| 13 |
+
--batch-size 4096 \
|
| 14 |
+
--aug-cfg scale='(0.4, 1.0)' color_jitter='(0.32, 0.32, 0.32, 0.08)' color_jitter_prob=0.8 gray_scale_prob=0.2 \
|
| 15 |
+
--epochs=7 \
|
| 16 |
+
--workers=6 \
|
| 17 |
+
--model ViT-H-14-CL8-SyntaxMask-GAP \
|
| 18 |
+
--precision 'amp_bf16' \
|
| 19 |
+
--local-loss \
|
| 20 |
+
--gather-with-grad \
|
| 21 |
+
--force-image-size 84 \
|
| 22 |
+
--grad-checkpointing \
|
| 23 |
+
--log-every-n-steps 32 \
|
| 24 |
+
--seed 0 \
|
| 25 |
+
--logs ./logs/ \
|
| 26 |
+
--imagenet-val '/path/to/ImageNet/val' \
|
| 27 |
+
--name 'name' \
|
| 28 |
+
--report-to "wandb" \
|
| 29 |
+
--wandb-project-name "project_name"
|
| 30 |
+
|
| 31 |
+
|
hlip/open_clip/src/open_clip/__init__.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from .version import __version__
|
| 2 |
+
|
| 3 |
+
from .coca_model import CoCa
|
| 4 |
+
from .constants import OPENAI_DATASET_MEAN, OPENAI_DATASET_STD
|
| 5 |
+
from .factory import create_model, create_model_and_transforms, create_model_from_pretrained, get_tokenizer, create_loss
|
| 6 |
+
from .factory import list_models, add_model_config, get_model_config, load_checkpoint
|
| 7 |
+
from .loss import ClipLoss, DistillClipLoss, CoCaLoss
|
| 8 |
+
from .model import CLIP, CustomTextCLIP, CLIPTextCfg, CLIPVisionCfg, \
|
| 9 |
+
convert_weights_to_lp, convert_weights_to_fp16, trace_model, get_cast_dtype, get_input_dtype, \
|
| 10 |
+
get_model_tokenize_cfg, get_model_preprocess_cfg, set_model_preprocess_cfg
|
| 11 |
+
from .openai import load_openai_model, list_openai_models
|
| 12 |
+
from .pretrained import list_pretrained, list_pretrained_models_by_tag, list_pretrained_tags_by_model, \
|
| 13 |
+
get_pretrained_url, download_pretrained_from_url, is_pretrained_cfg, get_pretrained_cfg, download_pretrained
|
| 14 |
+
from .push_to_hf_hub import push_pretrained_to_hf_hub, push_to_hf_hub
|
| 15 |
+
from .tokenizer import SimpleTokenizer, tokenize, decode
|
| 16 |
+
from .transform import image_transform, AugmentationCfg
|
| 17 |
+
from .zero_shot_classifier import build_zero_shot_classifier, build_zero_shot_classifier_legacy
|
| 18 |
+
from .zero_shot_metadata import OPENAI_IMAGENET_TEMPLATES, SIMPLE_IMAGENET_TEMPLATES, IMAGENET_CLASSNAMES
|
hlip/open_clip/src/open_clip/bpe_simple_vocab_16e6.txt.gz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:924691ac288e54409236115652ad4aa250f48203de50a9e4722a6ecd48d6804a
|
| 3 |
+
size 1356917
|
hlip/open_clip/src/open_clip/coca_model.py
ADDED
|
@@ -0,0 +1,582 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Dict, List, Optional, Union
|
| 2 |
+
|
| 3 |
+
import torch
|
| 4 |
+
from torch import nn
|
| 5 |
+
from torch.nn import functional as F
|
| 6 |
+
import numpy as np
|
| 7 |
+
from dataclasses import dataclass
|
| 8 |
+
|
| 9 |
+
from .transformer import (
|
| 10 |
+
LayerNormFp32,
|
| 11 |
+
LayerNorm,
|
| 12 |
+
QuickGELU,
|
| 13 |
+
MultimodalTransformer,
|
| 14 |
+
)
|
| 15 |
+
from .model import CLIPTextCfg, CLIPVisionCfg, _build_vision_tower, _build_text_tower
|
| 16 |
+
|
| 17 |
+
try:
|
| 18 |
+
from transformers import (
|
| 19 |
+
BeamSearchScorer,
|
| 20 |
+
LogitsProcessorList,
|
| 21 |
+
TopPLogitsWarper,
|
| 22 |
+
TopKLogitsWarper,
|
| 23 |
+
RepetitionPenaltyLogitsProcessor,
|
| 24 |
+
MinLengthLogitsProcessor,
|
| 25 |
+
MaxLengthCriteria,
|
| 26 |
+
StopStringCriteria,
|
| 27 |
+
EosTokenCriteria,
|
| 28 |
+
StoppingCriteriaList
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
GENERATION_TYPES = {
|
| 32 |
+
"top_k": TopKLogitsWarper,
|
| 33 |
+
"top_p": TopPLogitsWarper,
|
| 34 |
+
"beam_search": "beam_search"
|
| 35 |
+
}
|
| 36 |
+
_has_transformers = True
|
| 37 |
+
except ImportError as e:
|
| 38 |
+
GENERATION_TYPES = {
|
| 39 |
+
"top_k": None,
|
| 40 |
+
"top_p": None,
|
| 41 |
+
"beam_search": "beam_search"
|
| 42 |
+
}
|
| 43 |
+
_has_transformers = False
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
@dataclass
|
| 47 |
+
class MultimodalCfg(CLIPTextCfg):
|
| 48 |
+
mlp_ratio: int = 4
|
| 49 |
+
dim_head: int = 64
|
| 50 |
+
heads: int = 8
|
| 51 |
+
n_queries: int = 256
|
| 52 |
+
attn_pooler_heads: int = 8
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def _build_text_decoder_tower(
|
| 56 |
+
embed_dim,
|
| 57 |
+
multimodal_cfg,
|
| 58 |
+
quick_gelu: bool = False,
|
| 59 |
+
cast_dtype: Optional[torch.dtype] = None,
|
| 60 |
+
):
|
| 61 |
+
multimodal_cfg = MultimodalCfg(**multimodal_cfg) if isinstance(multimodal_cfg, dict) else multimodal_cfg
|
| 62 |
+
act_layer = QuickGELU if quick_gelu else nn.GELU
|
| 63 |
+
norm_layer = (
|
| 64 |
+
LayerNormFp32 if cast_dtype in (torch.float16, torch.bfloat16) else LayerNorm
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
decoder = MultimodalTransformer(
|
| 68 |
+
context_length=multimodal_cfg.context_length,
|
| 69 |
+
width=multimodal_cfg.width,
|
| 70 |
+
heads=multimodal_cfg.heads,
|
| 71 |
+
layers=multimodal_cfg.layers,
|
| 72 |
+
ls_init_value=multimodal_cfg.ls_init_value,
|
| 73 |
+
output_dim=embed_dim,
|
| 74 |
+
act_layer=act_layer,
|
| 75 |
+
norm_layer=norm_layer,
|
| 76 |
+
)
|
| 77 |
+
|
| 78 |
+
return decoder
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
def _token_to_tensor(token_id, device: str = "cpu") -> torch.Tensor:
|
| 82 |
+
if not isinstance(token_id, torch.Tensor):
|
| 83 |
+
if isinstance(token_id, int):
|
| 84 |
+
token_id = [token_id]
|
| 85 |
+
token_id = torch.tensor(token_id, device=device)
|
| 86 |
+
return token_id
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
class CoCa(nn.Module):
|
| 90 |
+
def __init__(
|
| 91 |
+
self,
|
| 92 |
+
embed_dim,
|
| 93 |
+
multimodal_cfg: MultimodalCfg,
|
| 94 |
+
text_cfg: CLIPTextCfg,
|
| 95 |
+
vision_cfg: CLIPVisionCfg,
|
| 96 |
+
quick_gelu: bool = False,
|
| 97 |
+
init_logit_scale: float = np.log(1 / 0.07),
|
| 98 |
+
init_logit_bias: Optional[float] = None,
|
| 99 |
+
nonscalar_logit_scale: bool = False,
|
| 100 |
+
cast_dtype: Optional[torch.dtype] = None,
|
| 101 |
+
pad_id: int = 0,
|
| 102 |
+
):
|
| 103 |
+
super().__init__()
|
| 104 |
+
multimodal_cfg = MultimodalCfg(**multimodal_cfg) if isinstance(multimodal_cfg, dict) else multimodal_cfg
|
| 105 |
+
text_cfg = CLIPTextCfg(**text_cfg) if isinstance(text_cfg, dict) else text_cfg
|
| 106 |
+
vision_cfg = CLIPVisionCfg(**vision_cfg) if isinstance(vision_cfg, dict) else vision_cfg
|
| 107 |
+
|
| 108 |
+
self.text = _build_text_tower(
|
| 109 |
+
embed_dim=embed_dim,
|
| 110 |
+
text_cfg=text_cfg,
|
| 111 |
+
quick_gelu=quick_gelu,
|
| 112 |
+
cast_dtype=cast_dtype,
|
| 113 |
+
)
|
| 114 |
+
|
| 115 |
+
vocab_size = (
|
| 116 |
+
text_cfg.vocab_size # for hf models
|
| 117 |
+
if hasattr(text_cfg, "hf_model_name") and text_cfg.hf_model_name is not None
|
| 118 |
+
else text_cfg.vocab_size
|
| 119 |
+
)
|
| 120 |
+
|
| 121 |
+
self.visual = _build_vision_tower(
|
| 122 |
+
embed_dim=embed_dim,
|
| 123 |
+
vision_cfg=vision_cfg,
|
| 124 |
+
quick_gelu=quick_gelu,
|
| 125 |
+
cast_dtype=cast_dtype,
|
| 126 |
+
)
|
| 127 |
+
|
| 128 |
+
self.text_decoder = _build_text_decoder_tower(
|
| 129 |
+
vocab_size,
|
| 130 |
+
multimodal_cfg=multimodal_cfg,
|
| 131 |
+
quick_gelu=quick_gelu,
|
| 132 |
+
cast_dtype=cast_dtype,
|
| 133 |
+
)
|
| 134 |
+
|
| 135 |
+
lshape = [1] if nonscalar_logit_scale else []
|
| 136 |
+
self.logit_scale = nn.Parameter(torch.ones(lshape) * init_logit_scale)
|
| 137 |
+
if init_logit_bias is not None:
|
| 138 |
+
self.logit_bias = nn.Parameter(torch.ones(lshape) * init_logit_bias)
|
| 139 |
+
else:
|
| 140 |
+
self.logit_bias = None
|
| 141 |
+
self.pad_id = pad_id
|
| 142 |
+
|
| 143 |
+
self.context_length = multimodal_cfg.context_length
|
| 144 |
+
|
| 145 |
+
@torch.jit.ignore
|
| 146 |
+
def set_grad_checkpointing(self, enable: bool = True):
|
| 147 |
+
self.visual.set_grad_checkpointing(enable)
|
| 148 |
+
self.text.set_grad_checkpointing(enable)
|
| 149 |
+
self.text_decoder.set_grad_checkpointing(enable)
|
| 150 |
+
|
| 151 |
+
def _encode_image(self, images, normalize: bool = True):
|
| 152 |
+
image_latent, tokens_embs = self.visual(images)
|
| 153 |
+
image_latent = F.normalize(image_latent, dim=-1) if normalize else image_latent
|
| 154 |
+
return image_latent, tokens_embs
|
| 155 |
+
|
| 156 |
+
def _encode_text(self, text, normalize: bool = True):
|
| 157 |
+
text_latent, token_emb = self.text(text)
|
| 158 |
+
text_latent = F.normalize(text_latent, dim=-1) if normalize else text_latent
|
| 159 |
+
return text_latent, token_emb
|
| 160 |
+
|
| 161 |
+
def encode_image(self, images, normalize: bool = True):
|
| 162 |
+
image_latent, _ = self._encode_image(images, normalize=normalize)
|
| 163 |
+
return image_latent
|
| 164 |
+
|
| 165 |
+
def encode_text(self, text, normalize: bool = True):
|
| 166 |
+
text_latent, _ = self._encode_text(text, normalize=normalize)
|
| 167 |
+
return text_latent
|
| 168 |
+
|
| 169 |
+
def forward_intermediates(
|
| 170 |
+
self,
|
| 171 |
+
image: Optional[torch.Tensor] = None,
|
| 172 |
+
text: Optional[torch.Tensor] = None,
|
| 173 |
+
image_indices: Optional[Union[int, List[int]]] = None,
|
| 174 |
+
text_indices: Optional[Union[int, List[int]]] = None,
|
| 175 |
+
stop_early: bool = False,
|
| 176 |
+
normalize: bool = True,
|
| 177 |
+
normalize_intermediates: bool = False,
|
| 178 |
+
intermediates_only: bool = False,
|
| 179 |
+
image_output_fmt: str = 'NCHW',
|
| 180 |
+
image_output_extra_tokens: bool = False,
|
| 181 |
+
text_output_fmt: str = 'NLC',
|
| 182 |
+
text_output_extra_tokens: bool = False,
|
| 183 |
+
output_logits: bool = False,
|
| 184 |
+
output_logit_scale_bias: bool = False,
|
| 185 |
+
) -> Dict[str, Union[torch.Tensor, List[torch.Tensor]]]:
|
| 186 |
+
""" Forward features that returns intermediates.
|
| 187 |
+
|
| 188 |
+
Args:
|
| 189 |
+
image: Input image tensor
|
| 190 |
+
text: Input text tensor
|
| 191 |
+
image_indices: For image tower, Take last n blocks if int, all if None, select matching indices if sequence
|
| 192 |
+
text_indices: Take last n blocks if int, all if None, select matching indices if sequence
|
| 193 |
+
stop_early: Stop iterating over blocks when last desired intermediate hit
|
| 194 |
+
normalize: L2 Normalize final image and text features (if present)
|
| 195 |
+
normalize_intermediates: Apply final encoder norm layer to all intermediates (if possible)
|
| 196 |
+
intermediates_only: Only return intermediate features, do not return final features
|
| 197 |
+
image_output_fmt: Shape of intermediate image feature outputs
|
| 198 |
+
image_output_extra_tokens: Return both prefix and spatial intermediate tokens
|
| 199 |
+
text_output_fmt: Shape of intermediate text feature outputs
|
| 200 |
+
text_output_extra_tokens: Return both prefix and spatial intermediate tokens
|
| 201 |
+
output_logits: Include logits in output
|
| 202 |
+
output_logit_scale_bias: Include the logit scale bias in the output
|
| 203 |
+
Returns:
|
| 204 |
+
|
| 205 |
+
"""
|
| 206 |
+
output = {}
|
| 207 |
+
if intermediates_only:
|
| 208 |
+
# intermediates only disables final feature normalization, and include logits
|
| 209 |
+
normalize = False
|
| 210 |
+
output_logits = False
|
| 211 |
+
if output_logits:
|
| 212 |
+
assert False, 'FIXME, needs implementing'
|
| 213 |
+
|
| 214 |
+
if image is not None:
|
| 215 |
+
image_output = self.visual.forward_intermediates(
|
| 216 |
+
image,
|
| 217 |
+
indices=image_indices,
|
| 218 |
+
stop_early=stop_early,
|
| 219 |
+
normalize_intermediates=normalize_intermediates,
|
| 220 |
+
intermediates_only=intermediates_only,
|
| 221 |
+
output_fmt=image_output_fmt,
|
| 222 |
+
output_extra_tokens=image_output_extra_tokens,
|
| 223 |
+
)
|
| 224 |
+
if normalize and "image_features" in image_output:
|
| 225 |
+
image_output["image_features"] = F.normalize(image_output["image_features"], dim=-1)
|
| 226 |
+
output.update(image_output)
|
| 227 |
+
|
| 228 |
+
if text is not None:
|
| 229 |
+
text_output = self.text.forward_intermediates(
|
| 230 |
+
text,
|
| 231 |
+
indices=text_indices,
|
| 232 |
+
stop_early=stop_early,
|
| 233 |
+
normalize_intermediates=normalize_intermediates,
|
| 234 |
+
intermediates_only=intermediates_only,
|
| 235 |
+
output_fmt=text_output_fmt,
|
| 236 |
+
output_extra_tokens=text_output_extra_tokens,
|
| 237 |
+
)
|
| 238 |
+
if normalize and "text_features" in text_output:
|
| 239 |
+
text_output["text_features"] = F.normalize(text_output["text_features"], dim=-1)
|
| 240 |
+
output.update(text_output)
|
| 241 |
+
|
| 242 |
+
# FIXME text decoder
|
| 243 |
+
logit_scale_exp = self.logit_scale.exp() if output_logits or output_logit_scale_bias else None
|
| 244 |
+
if output_logit_scale_bias:
|
| 245 |
+
output["logit_scale"] = logit_scale_exp
|
| 246 |
+
if self.logit_bias is not None:
|
| 247 |
+
output['logit_bias'] = self.logit_bias
|
| 248 |
+
|
| 249 |
+
return output
|
| 250 |
+
|
| 251 |
+
def forward(
|
| 252 |
+
self,
|
| 253 |
+
image,
|
| 254 |
+
text: Optional[torch.Tensor] = None,
|
| 255 |
+
image_latent: Optional[torch.Tensor] = None,
|
| 256 |
+
image_embs: Optional[torch.Tensor] = None,
|
| 257 |
+
output_labels: bool = True,
|
| 258 |
+
):
|
| 259 |
+
if image_latent is None or image_embs is None:
|
| 260 |
+
image_latent, image_embs = self._encode_image(image)
|
| 261 |
+
|
| 262 |
+
if text is None:
|
| 263 |
+
return {"image_features": image_latent, "image_embs": image_embs}
|
| 264 |
+
|
| 265 |
+
text_latent, token_embs = self._encode_text(text)
|
| 266 |
+
|
| 267 |
+
# FIXME this isn't an ideal solution, would like to improve -RW
|
| 268 |
+
labels: Optional[torch.Tensor] = text[:, 1:] if output_labels else None
|
| 269 |
+
if output_labels:
|
| 270 |
+
# align text_embs and thus logits with labels for teacher-forcing caption loss
|
| 271 |
+
token_embs = token_embs[:, :-1]
|
| 272 |
+
|
| 273 |
+
logits = self.text_decoder(image_embs, token_embs)
|
| 274 |
+
out_dict = {
|
| 275 |
+
"image_features": image_latent,
|
| 276 |
+
"text_features": text_latent,
|
| 277 |
+
"logits": logits,
|
| 278 |
+
"logit_scale": self.logit_scale.exp()
|
| 279 |
+
}
|
| 280 |
+
if labels is not None:
|
| 281 |
+
out_dict["labels"] = labels
|
| 282 |
+
if self.logit_bias is not None:
|
| 283 |
+
out_dict["logit_bias"] = self.logit_bias
|
| 284 |
+
return out_dict
|
| 285 |
+
|
| 286 |
+
def generate(
|
| 287 |
+
self,
|
| 288 |
+
image,
|
| 289 |
+
text=None,
|
| 290 |
+
seq_len=30,
|
| 291 |
+
max_seq_len=77,
|
| 292 |
+
temperature=1.,
|
| 293 |
+
generation_type="beam_search",
|
| 294 |
+
top_p=0.1, # keep tokens in the 1 - top_p quantile
|
| 295 |
+
top_k=1, # keeps the top_k most probable tokens
|
| 296 |
+
pad_token_id=None,
|
| 297 |
+
eos_token_id=None,
|
| 298 |
+
sot_token_id=None,
|
| 299 |
+
num_beams=6,
|
| 300 |
+
num_beam_groups=3,
|
| 301 |
+
min_seq_len=5,
|
| 302 |
+
stopping_criteria=None,
|
| 303 |
+
repetition_penalty=1.0,
|
| 304 |
+
fixed_output_length=False # if True output.shape == (batch_size, seq_len)
|
| 305 |
+
):
|
| 306 |
+
# taking many ideas and components from HuggingFace GenerationMixin
|
| 307 |
+
# https://huggingface.co/docs/transformers/main/en/main_classes/text_generation
|
| 308 |
+
assert _has_transformers, "Please install transformers for generate functionality. `pip install transformers`."
|
| 309 |
+
assert seq_len > min_seq_len, "seq_len must be larger than min_seq_len"
|
| 310 |
+
device = image.device
|
| 311 |
+
|
| 312 |
+
with torch.no_grad():
|
| 313 |
+
sot_token_id = _token_to_tensor(49406 if sot_token_id is None else sot_token_id, device=device)
|
| 314 |
+
eos_token_id = _token_to_tensor(49407 if eos_token_id is None else eos_token_id, device=device)
|
| 315 |
+
pad_token_id = self.pad_id if pad_token_id is None else pad_token_id
|
| 316 |
+
logit_processor = LogitsProcessorList(
|
| 317 |
+
[
|
| 318 |
+
MinLengthLogitsProcessor(min_seq_len, eos_token_id),
|
| 319 |
+
RepetitionPenaltyLogitsProcessor(repetition_penalty),
|
| 320 |
+
]
|
| 321 |
+
)
|
| 322 |
+
|
| 323 |
+
if stopping_criteria is None:
|
| 324 |
+
stopping_criteria = [MaxLengthCriteria(max_length=seq_len)]
|
| 325 |
+
stopping_criteria = StoppingCriteriaList(stopping_criteria)
|
| 326 |
+
|
| 327 |
+
if generation_type == "beam_search":
|
| 328 |
+
output = self._generate_beamsearch(
|
| 329 |
+
image_inputs=image,
|
| 330 |
+
pad_token_id=pad_token_id,
|
| 331 |
+
eos_token_id=eos_token_id,
|
| 332 |
+
sot_token_id=sot_token_id,
|
| 333 |
+
num_beams=num_beams,
|
| 334 |
+
num_beam_groups=num_beam_groups,
|
| 335 |
+
min_seq_len=min_seq_len,
|
| 336 |
+
stopping_criteria=stopping_criteria,
|
| 337 |
+
logit_processor=logit_processor,
|
| 338 |
+
)
|
| 339 |
+
if fixed_output_length and output.shape[1] < seq_len:
|
| 340 |
+
pad_len = seq_len - output.shape[1]
|
| 341 |
+
return torch.cat((
|
| 342 |
+
output,
|
| 343 |
+
torch.ones(output.shape[0], pad_len, device=device, dtype=output.dtype) * pad_token_id
|
| 344 |
+
),
|
| 345 |
+
dim=1
|
| 346 |
+
)
|
| 347 |
+
return output
|
| 348 |
+
|
| 349 |
+
elif generation_type == "top_p":
|
| 350 |
+
logit_warper = GENERATION_TYPES[generation_type](top_p)
|
| 351 |
+
elif generation_type == "top_k":
|
| 352 |
+
logit_warper = GENERATION_TYPES[generation_type](top_k)
|
| 353 |
+
else:
|
| 354 |
+
raise ValueError(
|
| 355 |
+
f"generation_type has to be one of "
|
| 356 |
+
f"{'| ' + ' | '.join(list(GENERATION_TYPES.keys())) + ' |'}."
|
| 357 |
+
)
|
| 358 |
+
|
| 359 |
+
image_latent, image_embs = self._encode_image(image)
|
| 360 |
+
|
| 361 |
+
if text is None:
|
| 362 |
+
text = torch.ones((image.shape[0], 1), device=device, dtype=torch.long) * sot_token_id
|
| 363 |
+
|
| 364 |
+
was_training = self.training
|
| 365 |
+
num_dims = len(text.shape)
|
| 366 |
+
|
| 367 |
+
if num_dims == 1:
|
| 368 |
+
text = text[None, :]
|
| 369 |
+
|
| 370 |
+
self.eval()
|
| 371 |
+
out = text
|
| 372 |
+
|
| 373 |
+
while True:
|
| 374 |
+
x = out[:, -max_seq_len:]
|
| 375 |
+
cur_len = x.shape[1]
|
| 376 |
+
logits = self(
|
| 377 |
+
image,
|
| 378 |
+
x,
|
| 379 |
+
image_latent=image_latent,
|
| 380 |
+
image_embs=image_embs,
|
| 381 |
+
output_labels=False,
|
| 382 |
+
)["logits"][:, -1]
|
| 383 |
+
mask = (out[:, -1] == eos_token_id) | (out[:, -1] == pad_token_id)
|
| 384 |
+
sample = torch.ones((out.shape[0], 1), device=device, dtype=torch.long) * pad_token_id
|
| 385 |
+
|
| 386 |
+
if mask.all():
|
| 387 |
+
if not fixed_output_length:
|
| 388 |
+
break
|
| 389 |
+
else:
|
| 390 |
+
logits = logits[~mask, :]
|
| 391 |
+
filtered_logits = logit_processor(x[~mask, :], logits)
|
| 392 |
+
filtered_logits = logit_warper(x[~mask, :], filtered_logits)
|
| 393 |
+
probs = F.softmax(filtered_logits / temperature, dim=-1)
|
| 394 |
+
|
| 395 |
+
if (cur_len + 1 == seq_len):
|
| 396 |
+
sample[~mask, :] = torch.ones((sum(~mask), 1), device=device, dtype=torch.long) * eos_token_id
|
| 397 |
+
else:
|
| 398 |
+
sample[~mask, :] = torch.multinomial(probs, 1)
|
| 399 |
+
|
| 400 |
+
out = torch.cat((out, sample), dim=-1)
|
| 401 |
+
|
| 402 |
+
cur_len += 1
|
| 403 |
+
|
| 404 |
+
if all(stopping_criteria(out, None)):
|
| 405 |
+
break
|
| 406 |
+
|
| 407 |
+
if num_dims == 1:
|
| 408 |
+
out = out.squeeze(0)
|
| 409 |
+
|
| 410 |
+
self.train(was_training)
|
| 411 |
+
return out
|
| 412 |
+
|
| 413 |
+
def _generate_beamsearch(
|
| 414 |
+
self,
|
| 415 |
+
image_inputs,
|
| 416 |
+
pad_token_id=None,
|
| 417 |
+
eos_token_id=None,
|
| 418 |
+
sot_token_id=None,
|
| 419 |
+
num_beams=6,
|
| 420 |
+
num_beam_groups=3,
|
| 421 |
+
min_seq_len=5,
|
| 422 |
+
stopping_criteria=None,
|
| 423 |
+
logit_processor=None,
|
| 424 |
+
logit_warper=None,
|
| 425 |
+
):
|
| 426 |
+
device = image_inputs.device
|
| 427 |
+
batch_size = image_inputs.shape[0]
|
| 428 |
+
image_inputs = torch.repeat_interleave(image_inputs, num_beams, dim=0)
|
| 429 |
+
image_latent, image_embs = self._encode_image(image_inputs)
|
| 430 |
+
|
| 431 |
+
input_ids = torch.ones((batch_size * num_beams, 1), device=device, dtype=torch.long)
|
| 432 |
+
input_ids = input_ids * sot_token_id
|
| 433 |
+
beam_scorer = BeamSearchScorer(
|
| 434 |
+
batch_size=batch_size,
|
| 435 |
+
num_beams=num_beams,
|
| 436 |
+
device=device,
|
| 437 |
+
num_beam_groups=num_beam_groups,
|
| 438 |
+
)
|
| 439 |
+
# instantiate logits processors
|
| 440 |
+
logits_processor = (
|
| 441 |
+
LogitsProcessorList([MinLengthLogitsProcessor(min_seq_len, eos_token_id=eos_token_id)])
|
| 442 |
+
if logit_processor is None
|
| 443 |
+
else logit_processor
|
| 444 |
+
)
|
| 445 |
+
|
| 446 |
+
num_beams = beam_scorer.num_beams
|
| 447 |
+
num_beam_groups = beam_scorer.num_beam_groups
|
| 448 |
+
num_sub_beams = num_beams // num_beam_groups
|
| 449 |
+
batch_size = len(beam_scorer._beam_hyps) // num_beam_groups
|
| 450 |
+
batch_beam_size, cur_len = input_ids.shape
|
| 451 |
+
beam_indices = None
|
| 452 |
+
|
| 453 |
+
if num_beams * batch_size != batch_beam_size:
|
| 454 |
+
raise ValueError(
|
| 455 |
+
f"Batch dimension of `input_ids` should be {num_beams * batch_size}, but is {batch_beam_size}."
|
| 456 |
+
)
|
| 457 |
+
|
| 458 |
+
beam_scores = torch.full((batch_size, num_beams), -1e9, dtype=torch.float, device=device)
|
| 459 |
+
# initialise score of first beam of each group with 0 and the rest with 1e-9. This ensures that the beams in
|
| 460 |
+
# the same group don't produce same tokens everytime.
|
| 461 |
+
beam_scores[:, ::num_sub_beams] = 0
|
| 462 |
+
beam_scores = beam_scores.view((batch_size * num_beams,))
|
| 463 |
+
|
| 464 |
+
while True:
|
| 465 |
+
|
| 466 |
+
# predicted tokens in cur_len step
|
| 467 |
+
current_tokens = torch.zeros(batch_size * num_beams, dtype=input_ids.dtype, device=device)
|
| 468 |
+
|
| 469 |
+
# indices which will form the beams in the next time step
|
| 470 |
+
reordering_indices = torch.zeros(batch_size * num_beams, dtype=torch.long, device=device)
|
| 471 |
+
|
| 472 |
+
# do one decoder step on all beams of all sentences in batch
|
| 473 |
+
model_inputs = prepare_inputs_for_generation(input_ids=input_ids, image_inputs=image_inputs)
|
| 474 |
+
outputs = self(
|
| 475 |
+
model_inputs['images'],
|
| 476 |
+
model_inputs['text'],
|
| 477 |
+
image_latent=image_latent,
|
| 478 |
+
image_embs=image_embs,
|
| 479 |
+
output_labels=False,
|
| 480 |
+
)
|
| 481 |
+
|
| 482 |
+
for beam_group_idx in range(num_beam_groups):
|
| 483 |
+
group_start_idx = beam_group_idx * num_sub_beams
|
| 484 |
+
group_end_idx = min(group_start_idx + num_sub_beams, num_beams)
|
| 485 |
+
group_size = group_end_idx - group_start_idx
|
| 486 |
+
|
| 487 |
+
# indices of beams of current group among all sentences in batch
|
| 488 |
+
batch_group_indices = []
|
| 489 |
+
|
| 490 |
+
for batch_idx in range(batch_size):
|
| 491 |
+
batch_group_indices.extend(
|
| 492 |
+
[batch_idx * num_beams + idx for idx in range(group_start_idx, group_end_idx)]
|
| 493 |
+
)
|
| 494 |
+
group_input_ids = input_ids[batch_group_indices]
|
| 495 |
+
|
| 496 |
+
# select outputs of beams of currentg group only
|
| 497 |
+
next_token_logits = outputs['logits'][batch_group_indices, -1, :]
|
| 498 |
+
vocab_size = next_token_logits.shape[-1]
|
| 499 |
+
|
| 500 |
+
next_token_scores_processed = logits_processor(
|
| 501 |
+
group_input_ids, next_token_logits, current_tokens=current_tokens, beam_group_idx=beam_group_idx
|
| 502 |
+
)
|
| 503 |
+
next_token_scores = next_token_scores_processed + beam_scores[batch_group_indices].unsqueeze(-1)
|
| 504 |
+
next_token_scores = next_token_scores.expand_as(next_token_scores_processed)
|
| 505 |
+
|
| 506 |
+
# reshape for beam search
|
| 507 |
+
next_token_scores = next_token_scores.view(batch_size, group_size * vocab_size)
|
| 508 |
+
|
| 509 |
+
next_token_scores, next_tokens = torch.topk(
|
| 510 |
+
next_token_scores, 2 * group_size, dim=1, largest=True, sorted=True
|
| 511 |
+
)
|
| 512 |
+
|
| 513 |
+
next_indices = torch.div(next_tokens, vocab_size, rounding_mode="floor")
|
| 514 |
+
next_tokens = next_tokens % vocab_size
|
| 515 |
+
|
| 516 |
+
# stateless
|
| 517 |
+
process_beam_indices = sum(beam_indices, ()) if beam_indices is not None else None
|
| 518 |
+
beam_outputs = beam_scorer.process(
|
| 519 |
+
group_input_ids,
|
| 520 |
+
next_token_scores,
|
| 521 |
+
next_tokens,
|
| 522 |
+
next_indices,
|
| 523 |
+
pad_token_id=pad_token_id,
|
| 524 |
+
eos_token_id=eos_token_id,
|
| 525 |
+
beam_indices=process_beam_indices,
|
| 526 |
+
group_index=beam_group_idx,
|
| 527 |
+
)
|
| 528 |
+
beam_scores[batch_group_indices] = beam_outputs["next_beam_scores"]
|
| 529 |
+
beam_next_tokens = beam_outputs["next_beam_tokens"]
|
| 530 |
+
beam_idx = beam_outputs["next_beam_indices"]
|
| 531 |
+
|
| 532 |
+
input_ids[batch_group_indices] = group_input_ids[beam_idx]
|
| 533 |
+
group_input_ids = torch.cat([group_input_ids[beam_idx, :], beam_next_tokens.unsqueeze(-1)], dim=-1)
|
| 534 |
+
current_tokens[batch_group_indices] = group_input_ids[:, -1]
|
| 535 |
+
|
| 536 |
+
# (beam_idx // group_size) -> batch_idx
|
| 537 |
+
# (beam_idx % group_size) -> offset of idx inside the group
|
| 538 |
+
reordering_indices[batch_group_indices] = (
|
| 539 |
+
num_beams * torch.div(beam_idx, group_size, rounding_mode="floor") + group_start_idx + (beam_idx % group_size)
|
| 540 |
+
)
|
| 541 |
+
|
| 542 |
+
input_ids = torch.cat([input_ids, current_tokens.unsqueeze(-1)], dim=-1)
|
| 543 |
+
|
| 544 |
+
# increase cur_len
|
| 545 |
+
cur_len = cur_len + 1
|
| 546 |
+
if beam_scorer.is_done or all(stopping_criteria(input_ids, None)):
|
| 547 |
+
break
|
| 548 |
+
|
| 549 |
+
final_beam_indices = sum(beam_indices, ()) if beam_indices is not None else None
|
| 550 |
+
sequence_outputs = beam_scorer.finalize(
|
| 551 |
+
input_ids,
|
| 552 |
+
beam_scores,
|
| 553 |
+
next_tokens,
|
| 554 |
+
next_indices,
|
| 555 |
+
pad_token_id=pad_token_id,
|
| 556 |
+
eos_token_id=eos_token_id,
|
| 557 |
+
max_length=stopping_criteria.max_length,
|
| 558 |
+
beam_indices=final_beam_indices,
|
| 559 |
+
)
|
| 560 |
+
return sequence_outputs['sequences']
|
| 561 |
+
|
| 562 |
+
|
| 563 |
+
def prepare_inputs_for_generation(input_ids, image_inputs, past=None, **kwargs):
|
| 564 |
+
if past:
|
| 565 |
+
input_ids = input_ids[:, -1].unsqueeze(-1)
|
| 566 |
+
|
| 567 |
+
attention_mask = kwargs.get("attention_mask", None)
|
| 568 |
+
position_ids = kwargs.get("position_ids", None)
|
| 569 |
+
|
| 570 |
+
if attention_mask is not None and position_ids is None:
|
| 571 |
+
# create position_ids on the fly for batch generation
|
| 572 |
+
position_ids = attention_mask.long().cumsum(-1) - 1
|
| 573 |
+
position_ids.masked_fill_(attention_mask == 0, 1)
|
| 574 |
+
else:
|
| 575 |
+
position_ids = None
|
| 576 |
+
return {
|
| 577 |
+
"text": input_ids,
|
| 578 |
+
"images": image_inputs,
|
| 579 |
+
"past_key_values": past,
|
| 580 |
+
"position_ids": position_ids,
|
| 581 |
+
"attention_mask": attention_mask,
|
| 582 |
+
}
|
hlip/open_clip/src/open_clip/constants.py
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
OPENAI_DATASET_MEAN = (0.48145466, 0.4578275, 0.40821073)
|
| 2 |
+
OPENAI_DATASET_STD = (0.26862954, 0.26130258, 0.27577711)
|
| 3 |
+
IMAGENET_MEAN = (0.485, 0.456, 0.406)
|
| 4 |
+
IMAGENET_STD = (0.229, 0.224, 0.225)
|
| 5 |
+
INCEPTION_MEAN = (0.5, 0.5, 0.5)
|
| 6 |
+
INCEPTION_STD = (0.5, 0.5, 0.5)
|
| 7 |
+
|
| 8 |
+
# Default name for a weights file hosted on the Huggingface Hub.
|
| 9 |
+
HF_WEIGHTS_NAME = "open_clip_pytorch_model.bin" # default pytorch pkl
|
| 10 |
+
HF_SAFE_WEIGHTS_NAME = "open_clip_model.safetensors" # safetensors version
|
| 11 |
+
HF_CONFIG_NAME = 'open_clip_config.json'
|
hlip/open_clip/src/open_clip/convert.py
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
""" Conversion functions for 3rd part state-dicts and non-torch native checkpoint formats.
|
| 2 |
+
"""
|
| 3 |
+
from typing import Union
|
| 4 |
+
|
| 5 |
+
import torch
|
| 6 |
+
import numpy as np
|
| 7 |
+
|
| 8 |
+
from .model import CLIP, CustomTextCLIP
|
| 9 |
+
from .transformer import TextTransformer, Transformer
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
@torch.no_grad()
|
| 13 |
+
def load_big_vision_weights(model: CustomTextCLIP, checkpoint_path: str):
|
| 14 |
+
""" Load weights from .npz checkpoints for official Google big_vision image-text models
|
| 15 |
+
|
| 16 |
+
Currently, the SigLIP source models are supported and a CustomTextCLIP destination model
|
| 17 |
+
w/ timm image encoder.
|
| 18 |
+
"""
|
| 19 |
+
from timm.layers import resample_patch_embed, resample_abs_pos_embed
|
| 20 |
+
|
| 21 |
+
def _n2p(w, t=True, idx=None):
|
| 22 |
+
if idx is not None:
|
| 23 |
+
w = w[idx]
|
| 24 |
+
if w.ndim == 4 and w.shape[0] == w.shape[1] == w.shape[2] == 1:
|
| 25 |
+
w = w.flatten()
|
| 26 |
+
if t:
|
| 27 |
+
if w.ndim == 4:
|
| 28 |
+
w = w.transpose([3, 2, 0, 1])
|
| 29 |
+
elif w.ndim == 3:
|
| 30 |
+
w = w.transpose([2, 0, 1])
|
| 31 |
+
elif w.ndim == 2:
|
| 32 |
+
w = w.transpose([1, 0])
|
| 33 |
+
return torch.from_numpy(w)
|
| 34 |
+
|
| 35 |
+
w = np.load(checkpoint_path)
|
| 36 |
+
interpolation = 'bilinear'
|
| 37 |
+
antialias = False
|
| 38 |
+
|
| 39 |
+
def _convert_timm_img(module, prefix):
|
| 40 |
+
embed_conv_w = _n2p(w[f'{prefix}embedding/kernel'])
|
| 41 |
+
if embed_conv_w.shape[-2:] != module.patch_embed.proj.weight.shape[-2:]:
|
| 42 |
+
embed_conv_w = resample_patch_embed(
|
| 43 |
+
embed_conv_w,
|
| 44 |
+
module.patch_embed.proj.weight.shape[-2:],
|
| 45 |
+
interpolation=interpolation,
|
| 46 |
+
antialias=antialias,
|
| 47 |
+
verbose=True,
|
| 48 |
+
)
|
| 49 |
+
module.patch_embed.proj.weight.copy_(embed_conv_w)
|
| 50 |
+
module.patch_embed.proj.bias.copy_(_n2p(w[f'{prefix}embedding/bias']))
|
| 51 |
+
|
| 52 |
+
if module.cls_token is not None:
|
| 53 |
+
module.cls_token.copy_(_n2p(w[f'{prefix}cls'], t=False))
|
| 54 |
+
|
| 55 |
+
pos_embed_w = _n2p(w[f'{prefix}pos_embedding'], t=False)
|
| 56 |
+
if pos_embed_w.shape != module.pos_embed.shape:
|
| 57 |
+
assert False, f'{pos_embed_w.shape}, {module.pos_embed.shape}'
|
| 58 |
+
num_prefix_tokens = 0 if getattr(module, 'no_embed_class', False) else getattr(module, 'num_prefix_tokens', 1)
|
| 59 |
+
pos_embed_w = resample_abs_pos_embed( # resize pos embedding when different size from pretrained weights
|
| 60 |
+
pos_embed_w,
|
| 61 |
+
new_size=module.patch_embed.grid_size,
|
| 62 |
+
num_prefix_tokens=num_prefix_tokens,
|
| 63 |
+
interpolation=interpolation,
|
| 64 |
+
antialias=antialias,
|
| 65 |
+
verbose=True,
|
| 66 |
+
)
|
| 67 |
+
module.pos_embed.copy_(pos_embed_w)
|
| 68 |
+
|
| 69 |
+
mha_sub, b_sub, ln1_sub = (0, 0, 1)
|
| 70 |
+
for i, block in enumerate(module.blocks.children()):
|
| 71 |
+
if f'{prefix}Transformer/encoderblock/LayerNorm_0/scale' in w:
|
| 72 |
+
block_prefix = f'{prefix}Transformer/encoderblock/'
|
| 73 |
+
idx = i
|
| 74 |
+
else:
|
| 75 |
+
block_prefix = f'{prefix}Transformer/encoderblock_{i}/'
|
| 76 |
+
idx = None
|
| 77 |
+
mha_prefix = block_prefix + f'MultiHeadDotProductAttention_{mha_sub}/'
|
| 78 |
+
block.norm1.weight.copy_(_n2p(w[f'{block_prefix}LayerNorm_0/scale'], idx=idx))
|
| 79 |
+
block.norm1.bias.copy_(_n2p(w[f'{block_prefix}LayerNorm_0/bias'], idx=idx))
|
| 80 |
+
block.attn.qkv.weight.copy_(torch.cat([
|
| 81 |
+
_n2p(w[f'{mha_prefix}{n}/kernel'], t=False, idx=idx).flatten(1).T for n in ('query', 'key', 'value')]))
|
| 82 |
+
block.attn.qkv.bias.copy_(torch.cat([
|
| 83 |
+
_n2p(w[f'{mha_prefix}{n}/bias'], t=False, idx=idx).reshape(-1) for n in ('query', 'key', 'value')]))
|
| 84 |
+
block.attn.proj.weight.copy_(_n2p(w[f'{mha_prefix}out/kernel'], idx=idx).flatten(1))
|
| 85 |
+
block.attn.proj.bias.copy_(_n2p(w[f'{mha_prefix}out/bias'], idx=idx))
|
| 86 |
+
block.norm2.weight.copy_(_n2p(w[f'{block_prefix}LayerNorm_{ln1_sub}/scale'], idx=idx))
|
| 87 |
+
block.norm2.bias.copy_(_n2p(w[f'{block_prefix}LayerNorm_{ln1_sub}/bias'], idx=idx))
|
| 88 |
+
for r in range(2):
|
| 89 |
+
getattr(block.mlp, f'fc{r + 1}').weight.copy_(
|
| 90 |
+
_n2p(w[f'{block_prefix}MlpBlock_{b_sub}/Dense_{r}/kernel'], idx=idx))
|
| 91 |
+
getattr(block.mlp, f'fc{r + 1}').bias.copy_(
|
| 92 |
+
_n2p(w[f'{block_prefix}MlpBlock_{b_sub}/Dense_{r}/bias'], idx=idx))
|
| 93 |
+
|
| 94 |
+
module.norm.weight.copy_(_n2p(w[f'{prefix}Transformer/encoder_norm/scale']))
|
| 95 |
+
module.norm.bias.copy_(_n2p(w[f'{prefix}Transformer/encoder_norm/bias']))
|
| 96 |
+
|
| 97 |
+
if module.attn_pool is not None:
|
| 98 |
+
block_prefix = f'{prefix}MAPHead_0/'
|
| 99 |
+
mha_prefix = block_prefix + f'MultiHeadDotProductAttention_0/'
|
| 100 |
+
module.attn_pool.latent.copy_(_n2p(w[f'{block_prefix}probe'], t=False))
|
| 101 |
+
module.attn_pool.q.weight.copy_(_n2p(w[f'{mha_prefix}query/kernel'], t=False).flatten(1).T)
|
| 102 |
+
module.attn_pool.q.bias.copy_(_n2p(w[f'{mha_prefix}query/bias'], t=False).reshape(-1))
|
| 103 |
+
module.attn_pool.kv.weight.copy_(torch.cat([
|
| 104 |
+
_n2p(w[f'{mha_prefix}{n}/kernel'], t=False).flatten(1).T for n in ('key', 'value')]))
|
| 105 |
+
module.attn_pool.kv.bias.copy_(torch.cat([
|
| 106 |
+
_n2p(w[f'{mha_prefix}{n}/bias'], t=False).reshape(-1) for n in ('key', 'value')]))
|
| 107 |
+
module.attn_pool.proj.weight.copy_(_n2p(w[f'{mha_prefix}out/kernel']).flatten(1))
|
| 108 |
+
module.attn_pool.proj.bias.copy_(_n2p(w[f'{mha_prefix}out/bias']))
|
| 109 |
+
module.attn_pool.norm.weight.copy_(_n2p(w[f'{block_prefix}LayerNorm_0/scale']))
|
| 110 |
+
module.attn_pool.norm.bias.copy_(_n2p(w[f'{block_prefix}LayerNorm_0/bias']))
|
| 111 |
+
for r in range(2):
|
| 112 |
+
getattr(module.attn_pool.mlp, f'fc{r + 1}').weight.copy_(_n2p(w[f'{block_prefix}MlpBlock_0/Dense_{r}/kernel']))
|
| 113 |
+
getattr(module.attn_pool.mlp, f'fc{r + 1}').bias.copy_(_n2p(w[f'{block_prefix}MlpBlock_0/Dense_{r}/bias']))
|
| 114 |
+
|
| 115 |
+
def _convert_openclip_transformer(module: Transformer, prefix):
|
| 116 |
+
for i, block in enumerate(module.resblocks.children()):
|
| 117 |
+
if f'{prefix}encoderblock/LayerNorm_0/scale' in w:
|
| 118 |
+
block_prefix = f'{prefix}encoderblock/'
|
| 119 |
+
idx = i
|
| 120 |
+
else:
|
| 121 |
+
block_prefix = f'{prefix}encoderblock_{i}/'
|
| 122 |
+
idx = None
|
| 123 |
+
mha_prefix = block_prefix + f'MultiHeadDotProductAttention_0/'
|
| 124 |
+
block.ln_1.weight.copy_(_n2p(w[f'{block_prefix}LayerNorm_0/scale'], idx=idx))
|
| 125 |
+
block.ln_1.bias.copy_(_n2p(w[f'{block_prefix}LayerNorm_0/bias'], idx=idx))
|
| 126 |
+
block.attn.in_proj_weight.copy_(torch.cat([
|
| 127 |
+
_n2p(w[f'{mha_prefix}{n}/kernel'], t=False, idx=idx).flatten(1).T for n in ('query', 'key', 'value')]))
|
| 128 |
+
block.attn.in_proj_bias.copy_(torch.cat([
|
| 129 |
+
_n2p(w[f'{mha_prefix}{n}/bias'], t=False, idx=idx).reshape(-1) for n in ('query', 'key', 'value')]))
|
| 130 |
+
block.attn.out_proj.weight.copy_(_n2p(w[f'{mha_prefix}out/kernel'], idx=idx).flatten(1))
|
| 131 |
+
block.attn.out_proj.bias.copy_(_n2p(w[f'{mha_prefix}out/bias'], idx=idx))
|
| 132 |
+
block.ln_2.weight.copy_(_n2p(w[f'{block_prefix}LayerNorm_1/scale'], idx=idx))
|
| 133 |
+
block.ln_2.bias.copy_(_n2p(w[f'{block_prefix}LayerNorm_1/bias'], idx=idx))
|
| 134 |
+
block.mlp.c_fc.weight.copy_(_n2p(w[f'{block_prefix}MlpBlock_0/Dense_0/kernel'], idx=idx))
|
| 135 |
+
block.mlp.c_fc.bias.copy_(_n2p(w[f'{block_prefix}MlpBlock_0/Dense_0/bias'], idx=idx))
|
| 136 |
+
block.mlp.c_proj.weight.copy_(_n2p(w[f'{block_prefix}MlpBlock_0/Dense_1/kernel'], idx=idx))
|
| 137 |
+
block.mlp.c_proj.bias.copy_(_n2p(w[f'{block_prefix}MlpBlock_0/Dense_1/bias'], idx=idx))
|
| 138 |
+
|
| 139 |
+
def _convert_openclip_txt(module: TextTransformer, prefix):
|
| 140 |
+
module.token_embedding.weight.copy_(_n2p(w[f'{prefix}Embed_0/embedding'], t=False))
|
| 141 |
+
pos_embed_w = _n2p(w[f'{prefix}pos_embedding'], t=False).squeeze(0)
|
| 142 |
+
module.positional_embedding.copy_(pos_embed_w)
|
| 143 |
+
_convert_openclip_transformer(module.transformer, prefix=prefix + 'Encoder_0/')
|
| 144 |
+
module.ln_final.weight.copy_(_n2p(w[f'{prefix}Encoder_0/encoder_norm/scale']))
|
| 145 |
+
module.ln_final.bias.copy_(_n2p(w[f'{prefix}Encoder_0/encoder_norm/bias']))
|
| 146 |
+
if module.text_projection is not None:
|
| 147 |
+
module.text_projection.weight.copy_(_n2p(w[f'{prefix}head/kernel']))
|
| 148 |
+
module.text_projection.bias.copy_(_n2p(w[f'{prefix}head/bias']))
|
| 149 |
+
|
| 150 |
+
root_prefix = 'params/' if 'params/b' in w else ''
|
| 151 |
+
_convert_timm_img(model.visual.trunk, f'{root_prefix}img/')
|
| 152 |
+
_convert_openclip_txt(model.text, f'{root_prefix}txt/')
|
| 153 |
+
model.logit_bias.copy_(_n2p(w[f'{root_prefix}b'])[0])
|
| 154 |
+
model.logit_scale.copy_(_n2p(w[f'{root_prefix}t'])[0])
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
@torch.no_grad()
|
| 158 |
+
def convert_mobile_clip_state_dict(model: CustomTextCLIP, state_dict, fastvit = True):
|
| 159 |
+
|
| 160 |
+
def _convert_timm_img(state_dict):
|
| 161 |
+
if fastvit:
|
| 162 |
+
from timm.models.fastvit import checkpoint_filter_fn
|
| 163 |
+
else:
|
| 164 |
+
from timm.models.vision_transformer_hybrid import checkpoint_filter_fn
|
| 165 |
+
timm_state_dict = checkpoint_filter_fn(state_dict, model.visual.trunk)
|
| 166 |
+
timm_state_dict = {'visual.trunk.' + k: v for k, v in timm_state_dict.items()}
|
| 167 |
+
return timm_state_dict
|
| 168 |
+
|
| 169 |
+
def _convert_openclip_txt(state_dict, prefix='text_encoder.'):
|
| 170 |
+
text_dict = {}
|
| 171 |
+
for k, v in state_dict.items():
|
| 172 |
+
if not k.startswith(prefix):
|
| 173 |
+
continue
|
| 174 |
+
k = k.replace(prefix, '')
|
| 175 |
+
k = k.replace('projection_layer', 'text_projection')
|
| 176 |
+
k = k.replace('embedding_layer', 'token_embedding')
|
| 177 |
+
if k.startswith('positional_embedding.pos_embed.pos_embed'):
|
| 178 |
+
k = k.replace('positional_embedding.pos_embed.pos_embed', 'positional_embedding')
|
| 179 |
+
v = v.squeeze()
|
| 180 |
+
k = k.replace('final_layer_norm', 'ln_final')
|
| 181 |
+
k = k.replace('pre_norm_mha.0', 'ln_1')
|
| 182 |
+
k = k.replace('pre_norm_mha.1', 'attn')
|
| 183 |
+
k = k.replace('pre_norm_ffn.0', 'ln_2')
|
| 184 |
+
k = k.replace('pre_norm_ffn.1', 'mlp.c_fc')
|
| 185 |
+
k = k.replace('pre_norm_ffn.4', 'mlp.c_proj')
|
| 186 |
+
k = k.replace('qkv_proj.weight', 'in_proj_weight')
|
| 187 |
+
k = k.replace('qkv_proj.bias', 'in_proj_bias')
|
| 188 |
+
k = k.replace('transformer.', 'transformer.resblocks.')
|
| 189 |
+
text_dict['text.' + k] = v
|
| 190 |
+
return text_dict
|
| 191 |
+
|
| 192 |
+
image_dict = _convert_timm_img(state_dict)
|
| 193 |
+
text_dict = _convert_openclip_txt(state_dict)
|
| 194 |
+
out_dict = {**image_dict, **text_dict}
|
| 195 |
+
out_dict['logit_scale'] = state_dict['logit_scale']
|
| 196 |
+
return out_dict
|
| 197 |
+
|
| 198 |
+
|
| 199 |
+
def convert_state_dict(model: Union[CustomTextCLIP, CLIP], state_dict):
|
| 200 |
+
if 'image_encoder.model.patch_embed.0.rbr_conv.0.conv.weight' in state_dict:
|
| 201 |
+
# Apple MobileCLIP s1 & s2 state_dicts (s0 and b not currently supported)
|
| 202 |
+
state_dict = convert_mobile_clip_state_dict(model, state_dict)
|
| 203 |
+
if 'image_encoder.model.patch_emb.0.block.conv.weight' in state_dict:
|
| 204 |
+
# convert b model
|
| 205 |
+
state_dict = convert_mobile_clip_state_dict(model, state_dict, fastvit=False)
|
| 206 |
+
return state_dict
|
hlip/open_clip/src/open_clip/factory.py
ADDED
|
@@ -0,0 +1,1108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import logging
|
| 3 |
+
import os
|
| 4 |
+
import re
|
| 5 |
+
import warnings
|
| 6 |
+
from copy import deepcopy
|
| 7 |
+
from dataclasses import asdict
|
| 8 |
+
from pathlib import Path
|
| 9 |
+
from typing import Any, Dict, Optional, Tuple, Union
|
| 10 |
+
|
| 11 |
+
import torch
|
| 12 |
+
|
| 13 |
+
from .convert import convert_state_dict
|
| 14 |
+
from .model import CLIP, CustomTextCLIP, convert_weights_to_lp, convert_to_custom_text_state_dict,\
|
| 15 |
+
resize_pos_embed, get_cast_dtype, resize_text_pos_embed, set_model_preprocess_cfg
|
| 16 |
+
from .coca_model import CoCa
|
| 17 |
+
from .loss import ClipLoss, DistillClipLoss, CoCaLoss, SigLipLoss
|
| 18 |
+
from .pretrained import is_pretrained_cfg, get_pretrained_cfg, download_pretrained,\
|
| 19 |
+
list_pretrained_tags_by_model, download_pretrained_from_hf
|
| 20 |
+
from .transform import image_transform_v2, AugmentationCfg, PreprocessCfg, merge_preprocess_dict, merge_preprocess_kwargs
|
| 21 |
+
from .tokenizer import HFTokenizer, SimpleTokenizer, SigLipTokenizer, DEFAULT_CONTEXT_LENGTH
|
| 22 |
+
|
| 23 |
+
HF_HUB_PREFIX = 'hf-hub:'
|
| 24 |
+
_MODEL_CONFIG_PATHS = [Path(__file__).parent / f"model_configs/"]
|
| 25 |
+
_MODEL_CONFIGS = {} # directory (model_name: config) of model architecture configs
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def _natural_key(string_):
|
| 29 |
+
return [int(s) if s.isdigit() else s for s in re.split(r'(\d+)', string_.lower())]
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def _rescan_model_configs():
|
| 33 |
+
global _MODEL_CONFIGS
|
| 34 |
+
|
| 35 |
+
config_ext = ('.json',)
|
| 36 |
+
config_files = []
|
| 37 |
+
for config_path in _MODEL_CONFIG_PATHS:
|
| 38 |
+
if config_path.is_file() and config_path.suffix in config_ext:
|
| 39 |
+
config_files.append(config_path)
|
| 40 |
+
elif config_path.is_dir():
|
| 41 |
+
for ext in config_ext:
|
| 42 |
+
config_files.extend(config_path.glob(f'*{ext}'))
|
| 43 |
+
|
| 44 |
+
for cf in config_files:
|
| 45 |
+
with open(cf, 'r') as f:
|
| 46 |
+
model_cfg = json.load(f)
|
| 47 |
+
if all(a in model_cfg for a in ('embed_dim', 'vision_cfg', 'text_cfg')):
|
| 48 |
+
_MODEL_CONFIGS[cf.stem] = model_cfg
|
| 49 |
+
|
| 50 |
+
_MODEL_CONFIGS = {k: v for k, v in sorted(_MODEL_CONFIGS.items(), key=lambda x: _natural_key(x[0]))}
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
_rescan_model_configs() # initial populate of model config registry
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
def list_models():
|
| 57 |
+
""" enumerate available model architectures based on config files """
|
| 58 |
+
return list(_MODEL_CONFIGS.keys())
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
def add_model_config(path):
|
| 62 |
+
""" add model config path or file and update registry """
|
| 63 |
+
if not isinstance(path, Path):
|
| 64 |
+
path = Path(path)
|
| 65 |
+
_MODEL_CONFIG_PATHS.append(path)
|
| 66 |
+
_rescan_model_configs()
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
# Define Schema Prefixes as constants
|
| 70 |
+
HF_HUB_PREFIX = 'hf-hub:'
|
| 71 |
+
LOCAL_DIR_PREFIX = 'local-dir:'
|
| 72 |
+
|
| 73 |
+
def parse_model_name(model_name: str) -> Tuple[Optional[str], str]:
|
| 74 |
+
"""
|
| 75 |
+
Parses a model name string to identify a schema and the remaining identifier.
|
| 76 |
+
|
| 77 |
+
Args:
|
| 78 |
+
model_name: The model name string (e.g., 'ViT-B-32',
|
| 79 |
+
'hf-hub:org/repo', 'local-dir:/path/to/dir',
|
| 80 |
+
'local-dir:./relative/path').
|
| 81 |
+
|
| 82 |
+
Returns:
|
| 83 |
+
A tuple (schema, identifier):
|
| 84 |
+
- schema (Optional[str]): 'hf-hub', 'local-dir', or None if no schema detected.
|
| 85 |
+
- identifier (str): The part after the schema prefix, or the original
|
| 86 |
+
string if no schema was present. For 'local-dir',
|
| 87 |
+
this is the raw path string provided.
|
| 88 |
+
Raises:
|
| 89 |
+
ValueError: If a schema prefix is present but the identifier part is empty.
|
| 90 |
+
"""
|
| 91 |
+
# Check for local directory schema first
|
| 92 |
+
if model_name.startswith(LOCAL_DIR_PREFIX):
|
| 93 |
+
# Extract the identifier (path) after the prefix
|
| 94 |
+
identifier = model_name[len(LOCAL_DIR_PREFIX):]
|
| 95 |
+
# Validate that the identifier (path) is not empty
|
| 96 |
+
if not identifier:
|
| 97 |
+
raise ValueError("Empty path specified after 'local-dir:' schema.")
|
| 98 |
+
# Return the schema and the raw path identifier
|
| 99 |
+
# Note: We don't resolve or fully validate the path here,
|
| 100 |
+
# that's left to the calling function (e.g., using os.path.isdir)
|
| 101 |
+
return 'local-dir', identifier
|
| 102 |
+
|
| 103 |
+
# Check for Hugging Face Hub schema
|
| 104 |
+
elif model_name.startswith(HF_HUB_PREFIX):
|
| 105 |
+
# Extract the identifier (HF Hub ID) after the prefix
|
| 106 |
+
identifier = model_name[len(HF_HUB_PREFIX):]
|
| 107 |
+
# Validate that the identifier is not empty
|
| 108 |
+
if not identifier:
|
| 109 |
+
raise ValueError("Empty identifier specified after 'hf-hub:' schema.")
|
| 110 |
+
# Return the schema and the HF Hub ID
|
| 111 |
+
return 'hf-hub', identifier
|
| 112 |
+
|
| 113 |
+
# If neither schema prefix is found
|
| 114 |
+
else:
|
| 115 |
+
# No schema detected, return None for schema and the original string as identifier
|
| 116 |
+
return None, model_name
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
def _get_hf_config(
|
| 120 |
+
model_id: str,
|
| 121 |
+
cache_dir: Optional[str] = None,
|
| 122 |
+
):
|
| 123 |
+
""" Fetch model config from HuggingFace Hub.
|
| 124 |
+
"""
|
| 125 |
+
config_path = download_pretrained_from_hf(
|
| 126 |
+
model_id,
|
| 127 |
+
filename='open_clip_config.json',
|
| 128 |
+
cache_dir=cache_dir,
|
| 129 |
+
)
|
| 130 |
+
with open(config_path, 'r', encoding='utf-8') as f:
|
| 131 |
+
config = json.load(f)
|
| 132 |
+
return config
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
def get_model_config(model_name):
|
| 136 |
+
""" Fetch model config from schema specified location or local library configs.
|
| 137 |
+
"""
|
| 138 |
+
loc, model_id = parse_model_name(model_name)
|
| 139 |
+
if loc == 'local-dir':
|
| 140 |
+
local_path = Path(model_id) / 'open_clip_config.json'
|
| 141 |
+
with open(local_path, 'r', encoding='utf-8') as f:
|
| 142 |
+
config = json.load(f)
|
| 143 |
+
return config.get('model_cfg', config)
|
| 144 |
+
elif loc == 'hf-hub':
|
| 145 |
+
config = _get_hf_config(model_id)
|
| 146 |
+
return config.get('model_cfg', config)
|
| 147 |
+
elif model_name in _MODEL_CONFIGS:
|
| 148 |
+
return deepcopy(_MODEL_CONFIGS[model_name])
|
| 149 |
+
else:
|
| 150 |
+
return None
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
def load_state_dict(
|
| 154 |
+
checkpoint_path: str,
|
| 155 |
+
device='cpu',
|
| 156 |
+
weights_only=True,
|
| 157 |
+
):
|
| 158 |
+
# Check if safetensors or not and load weights accordingly
|
| 159 |
+
if str(checkpoint_path).endswith(".safetensors"):
|
| 160 |
+
from safetensors.torch import load_file
|
| 161 |
+
checkpoint = load_file(checkpoint_path, device=device)
|
| 162 |
+
else:
|
| 163 |
+
try:
|
| 164 |
+
checkpoint = torch.load(checkpoint_path, map_location=device, weights_only=weights_only)
|
| 165 |
+
except TypeError:
|
| 166 |
+
checkpoint = torch.load(checkpoint_path, map_location=device)
|
| 167 |
+
|
| 168 |
+
if isinstance(checkpoint, dict) and 'state_dict' in checkpoint:
|
| 169 |
+
state_dict = checkpoint['state_dict']
|
| 170 |
+
elif isinstance(checkpoint, torch.jit.ScriptModule):
|
| 171 |
+
state_dict = checkpoint.state_dict()
|
| 172 |
+
for key in ["input_resolution", "context_length", "vocab_size"]:
|
| 173 |
+
state_dict.pop(key, None)
|
| 174 |
+
else:
|
| 175 |
+
state_dict = checkpoint
|
| 176 |
+
if next(iter(state_dict.items()))[0].startswith('module'):
|
| 177 |
+
state_dict = {k[7:]: v for k, v in state_dict.items()}
|
| 178 |
+
return state_dict
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
def load_checkpoint(
|
| 182 |
+
model: Union[CLIP, CustomTextCLIP],
|
| 183 |
+
checkpoint_path: str,
|
| 184 |
+
strict: bool = True,
|
| 185 |
+
weights_only: bool = True,
|
| 186 |
+
device='cpu',
|
| 187 |
+
):
|
| 188 |
+
if Path(checkpoint_path).suffix in ('.npz', '.npy'):
|
| 189 |
+
# Separate path loading numpy big_vision (SigLIP) weights
|
| 190 |
+
from open_clip.convert import load_big_vision_weights
|
| 191 |
+
load_big_vision_weights(model, checkpoint_path)
|
| 192 |
+
return {}
|
| 193 |
+
|
| 194 |
+
state_dict = load_state_dict(checkpoint_path, device=device, weights_only=weights_only)
|
| 195 |
+
|
| 196 |
+
# Detect & convert 3rd party state_dicts -> open_clip
|
| 197 |
+
state_dict = convert_state_dict(model, state_dict)
|
| 198 |
+
|
| 199 |
+
# Detect old format and make compatible with new format
|
| 200 |
+
if 'positional_embedding' in state_dict and not hasattr(model, 'positional_embedding'):
|
| 201 |
+
state_dict = convert_to_custom_text_state_dict(state_dict)
|
| 202 |
+
|
| 203 |
+
# correct if logit_scale differs in being scaler vs 1d param
|
| 204 |
+
if 'logit_scale' in state_dict and model.logit_scale.ndim != state_dict['logit_scale'].ndim:
|
| 205 |
+
state_dict['logit_scale'] = state_dict['logit_scale'].reshape(model.logit_scale.shape)
|
| 206 |
+
|
| 207 |
+
# correct if logit_bias differs in being scaler vs 1d param
|
| 208 |
+
if 'logit_bias' in state_dict and model.logit_bias.ndim != state_dict['logit_bias'].ndim:
|
| 209 |
+
state_dict['logit_bias'] = state_dict['logit_bias'].reshape(model.logit_bias.shape)
|
| 210 |
+
|
| 211 |
+
# If loading a non-SigLIP model for SigLIP training. See https://github.com/mlfoundations/open_clip/issues/712
|
| 212 |
+
if 'logit_bias' not in state_dict and model.logit_bias is not None:
|
| 213 |
+
state_dict["logit_bias"] = torch.zeros_like(state_dict["logit_scale"])
|
| 214 |
+
|
| 215 |
+
# Certain text transformers no longer expect position_ids after transformers==4.31
|
| 216 |
+
position_id_key = 'text.transformer.embeddings.position_ids'
|
| 217 |
+
if position_id_key in state_dict and not hasattr(model, position_id_key):
|
| 218 |
+
del state_dict[position_id_key]
|
| 219 |
+
|
| 220 |
+
resize_pos_embed(state_dict, model)
|
| 221 |
+
resize_text_pos_embed(state_dict, model)
|
| 222 |
+
|
| 223 |
+
# Finally, load the massaged state_dict into model
|
| 224 |
+
incompatible_keys = model.load_state_dict(state_dict, strict=strict)
|
| 225 |
+
return incompatible_keys
|
| 226 |
+
|
| 227 |
+
|
| 228 |
+
def _find_checkpoint_in_dir(dir_path: Path) -> Optional[str]:
|
| 229 |
+
checkpoints = list(dir_path.glob('*.safetensors')) + list(dir_path.glob('*.bin')) + list(dir_path.glob('*.pth'))
|
| 230 |
+
if not checkpoints:
|
| 231 |
+
return None
|
| 232 |
+
checkpoints.sort()
|
| 233 |
+
checkpoints.sort(key=lambda x: x.suffix == '.safetensors', reverse=True)
|
| 234 |
+
preferred_order = [
|
| 235 |
+
"open_clip_model.safetensors", "open_clip_pytorch_model.safetensors",
|
| 236 |
+
"open_clip_pytorch_model.bin", "open_clip_pytorch_model.pth",
|
| 237 |
+
"model.safetensors", "pytorch_model.bin", "pytorch_model.pth", "model.pth"
|
| 238 |
+
]
|
| 239 |
+
preferred_checkpoints = [c for c in checkpoints if c.name in preferred_order]
|
| 240 |
+
if preferred_checkpoints:
|
| 241 |
+
preferred_checkpoints.sort(key=lambda x: preferred_order.index(x.name))
|
| 242 |
+
chosen = preferred_checkpoints[0]
|
| 243 |
+
logging.info(f"Found preferred checkpoint file: {chosen.name} in {dir_path}")
|
| 244 |
+
return str(chosen)
|
| 245 |
+
chosen = checkpoints[0]
|
| 246 |
+
logging.warning(
|
| 247 |
+
f"Multiple checkpoints found in {dir_path}: {[c.name for c in checkpoints]}. Using '{chosen.name}'.")
|
| 248 |
+
return str(chosen)
|
| 249 |
+
|
| 250 |
+
|
| 251 |
+
def create_model(
|
| 252 |
+
model_name: str, # Can contain schemas 'hf-hub:' or 'local-dir:'
|
| 253 |
+
pretrained: Optional[str] = None, # Used ONLY if model_name has NO schema
|
| 254 |
+
load_weights: bool = True,
|
| 255 |
+
precision: str = 'fp32',
|
| 256 |
+
device: Union[str, torch.device] = 'cpu',
|
| 257 |
+
jit: bool = False,
|
| 258 |
+
force_quick_gelu: bool = False,
|
| 259 |
+
force_custom_text: bool = False,
|
| 260 |
+
force_patch_dropout: Optional[float] = None,
|
| 261 |
+
force_image_size: Optional[Union[int, Tuple[int, int]]] = None,
|
| 262 |
+
force_preprocess_cfg: Optional[Dict[str, Any]] = None,
|
| 263 |
+
force_context_length: Optional[int] = None,
|
| 264 |
+
pretrained_image: bool = False, # Load default base image weights (at creation, if no CLIP weights)
|
| 265 |
+
pretrained_text: bool = True, # Load default base text weights (at creation, if no CLIP weights) - NEW
|
| 266 |
+
pretrained_image_path: Optional[str] = None, # Load specific image weights from file (after creation)
|
| 267 |
+
pretrained_text_path: Optional[str] = None, # Load specific text weights from file (after creation)
|
| 268 |
+
cache_dir: Optional[str] = None,
|
| 269 |
+
output_dict: Optional[bool] = None,
|
| 270 |
+
require_pretrained: bool = False,
|
| 271 |
+
weights_only: bool = True,
|
| 272 |
+
**model_kwargs,
|
| 273 |
+
) -> torch.nn.Module:
|
| 274 |
+
"""
|
| 275 |
+
创建并配置一个对比式视觉-语言模型。
|
| 276 |
+
|
| 277 |
+
`model_name` 用于指定结构 / 配置的来源:
|
| 278 |
+
- 'ViT-B-32':内置模型名称。`pretrained` 指定 CLIP 权重来源(tag 或文件路径)。
|
| 279 |
+
- 'hf-hub:org/repo':从 HF Hub 加载配置 / 权重,此时会忽略 `pretrained`。
|
| 280 |
+
- 'local-dir:/path/to/folder':从本地目录加载配置 / 权重,此时会忽略 `pretrained`。
|
| 281 |
+
|
| 282 |
+
基础 tower 权重的加载由 `pretrained_image` 和 `pretrained_text` 这两个标志控制,
|
| 283 |
+
仅在没有加载完整 CLIP checkpoint(通过 `pretrained` 或带 schema 的来源)时才会生效。
|
| 284 |
+
|
| 285 |
+
可以在创建 *之后* 通过 `pretrained_image_path` 和 `pretrained_text_path`
|
| 286 |
+
为各自的 tower 加载特定权重。
|
| 287 |
+
|
| 288 |
+
Args:
|
| 289 |
+
model_name: 模型标识符,可能包含 schema('hf-hub:'、'local-dir:')。
|
| 290 |
+
pretrained: 当 model_name 不带 schema 时,CLIP 权重的来源(tag 或文件路径)。
|
| 291 |
+
load_weights: 若为 True,则加载解析出的预训练权重;否则仅随机初始化或应用 tower 级别的覆盖。
|
| 292 |
+
precision: 模型精度('fp32'、'fp16'、'bf16' 等)。
|
| 293 |
+
device: 设备('cpu'、'cuda' 等)。
|
| 294 |
+
jit: 若为 True,则对模型进行 JIT 编译。
|
| 295 |
+
force_quick_gelu: 在模型配置中强制使用 QuickGELU 激活函数。
|
| 296 |
+
force_custom_text: 强制使用自定义文本编码器结构。
|
| 297 |
+
force_patch_dropout: 覆盖模型配置中的 patch dropout 值。
|
| 298 |
+
force_image_size: 覆盖模型配置中的图像尺寸。
|
| 299 |
+
force_preprocess_cfg: 用于覆盖最终预处理配置中部分参数的 dict。
|
| 300 |
+
force_context_length: 覆盖模型配置中的上下文长度。
|
| 301 |
+
pretrained_image: 若未加载 CLIP 权重,在创建时为 image tower 加载默认基础权重。
|
| 302 |
+
pretrained_text: 若未加载 CLIP 权重,在创建时为 text tower 加载默认基础权重(默认:True)。
|
| 303 |
+
pretrained_image_path: 在创建后,将指定路径的权重加载到 image tower 中。
|
| 304 |
+
pretrained_text_path: 在创建后,将指定路径的权重加载到 text tower 中。
|
| 305 |
+
cache_dir: 下载使用的缓存目录。
|
| 306 |
+
output_dict: 若为 True 且模型支持,则返回 dict 形式的输出。
|
| 307 |
+
require_pretrained: 在需要 `pretrained` CLIP 权重却未加载时抛出错误。
|
| 308 |
+
weights_only: 为 torch.load 使用 weights_only=True(更安全)。
|
| 309 |
+
**model_kwargs: 传入模型构造函数的额外关键字参数(覆盖优先级最高)。
|
| 310 |
+
|
| 311 |
+
Returns:
|
| 312 |
+
创建好的模型实例。
|
| 313 |
+
"""
|
| 314 |
+
schema, identifier = parse_model_name(model_name)
|
| 315 |
+
if 'pretrained_hf' in model_kwargs:
|
| 316 |
+
# for backwards compat, override pretrained_text
|
| 317 |
+
pretrained_text = model_kwargs.pop('pretrained_hf')
|
| 318 |
+
if isinstance(device, str):
|
| 319 |
+
device = torch.device(device)
|
| 320 |
+
|
| 321 |
+
model_cfg = None
|
| 322 |
+
preprocess_cfg = asdict(PreprocessCfg()) # Populate with defaults
|
| 323 |
+
checkpoint_path = None # Final path for full CLIP weights
|
| 324 |
+
pretrained_cfg_for_tag = None # Store tag config if pretrained is a tag and schema is None
|
| 325 |
+
|
| 326 |
+
logging.info(f"Parsing model identifier. Schema: {schema}, Identifier: {identifier}")
|
| 327 |
+
if schema and pretrained:
|
| 328 |
+
logging.warning(f"Ignoring `pretrained='{pretrained}'` because `model_name` has '{schema}' schema.")
|
| 329 |
+
pretrained = None # Nullify pretrained as it's ignored
|
| 330 |
+
|
| 331 |
+
# Handle schemas first - these ignore the `pretrained` argument
|
| 332 |
+
if schema == 'local-dir':
|
| 333 |
+
# Handle local directory schema
|
| 334 |
+
local_path = Path(identifier)
|
| 335 |
+
if not local_path.is_dir():
|
| 336 |
+
raise FileNotFoundError(f"Directory specified via 'local-dir:' schema not found: {local_path}")
|
| 337 |
+
|
| 338 |
+
local_config_path = local_path / 'open_clip_config.json'
|
| 339 |
+
logging.info(f"Attempting to load config from local dir: {local_config_path}")
|
| 340 |
+
if local_config_path.is_file():
|
| 341 |
+
try:
|
| 342 |
+
# Try loading and parsing the JSON config
|
| 343 |
+
with open(local_config_path, 'r', encoding='utf-8') as f:
|
| 344 |
+
local_json_config = json.load(f)
|
| 345 |
+
# Check if the required 'model_cfg' key is present
|
| 346 |
+
if 'model_cfg' in local_json_config:
|
| 347 |
+
# Load model config and merge preprocess config
|
| 348 |
+
model_cfg = local_json_config['model_cfg']
|
| 349 |
+
preprocess_cfg = merge_preprocess_dict(preprocess_cfg, local_json_config.get('preprocess_cfg', {}))
|
| 350 |
+
logging.info(f"Loaded model config and preprocess from: {local_config_path}")
|
| 351 |
+
# Look for weights checkpoint in the same directory
|
| 352 |
+
checkpoint_path = _find_checkpoint_in_dir(local_path)
|
| 353 |
+
if checkpoint_path:
|
| 354 |
+
logging.info(f"Found CLIP weights in local folder: {checkpoint_path}")
|
| 355 |
+
else:
|
| 356 |
+
logging.warning(f"Local config loaded, but no CLIP weights found in {local_path}")
|
| 357 |
+
else:
|
| 358 |
+
# Config file exists but lacks the necessary key
|
| 359 |
+
raise ValueError(f"Local config {local_config_path} missing 'model_cfg'.")
|
| 360 |
+
except Exception as e:
|
| 361 |
+
# Handle JSON parsing errors or other exceptions during config load
|
| 362 |
+
raise ValueError(f"Could not load valid config from specified 'local-dir:{identifier}': {e}") from e
|
| 363 |
+
else:
|
| 364 |
+
# Directory exists but the config file is missing
|
| 365 |
+
raise FileNotFoundError(f"'local-dir:' specified, but config file missing: {local_config_path}")
|
| 366 |
+
|
| 367 |
+
elif schema == 'hf-hub':
|
| 368 |
+
# Handle Hugging Face Hub schema
|
| 369 |
+
model_id = identifier
|
| 370 |
+
logging.info(f"Attempting to load config from HF Hub: {model_id}")
|
| 371 |
+
try:
|
| 372 |
+
# Fetch configuration from Hugging Face Hub
|
| 373 |
+
hf_config = _get_hf_config(model_id, cache_dir=cache_dir)
|
| 374 |
+
if 'model_cfg' not in hf_config:
|
| 375 |
+
raise RuntimeError(f"'model_cfg' not found in config from {model_id}")
|
| 376 |
+
# Load model config and merge preprocess config
|
| 377 |
+
model_cfg = hf_config['model_cfg']
|
| 378 |
+
preprocess_cfg = merge_preprocess_dict(preprocess_cfg, hf_config.get('preprocess_cfg', {}))
|
| 379 |
+
logging.info(f"Loaded model config from HF Hub: {model_id}")
|
| 380 |
+
# Attempt find default weights file from the Hub repo
|
| 381 |
+
try:
|
| 382 |
+
checkpoint_path = download_pretrained_from_hf(model_id, cache_dir=cache_dir)
|
| 383 |
+
logging.info(f"Found default weights file on HF Hub: {checkpoint_path}")
|
| 384 |
+
except Exception as e_weights:
|
| 385 |
+
# Log warning if weights download fails, but proceed (might only need config)
|
| 386 |
+
logging.warning(f"Could not find/download default weights on HF Hub for {model_id}: {e_weights}")
|
| 387 |
+
except Exception as e_config:
|
| 388 |
+
# Handle errors during config fetching from HF Hub
|
| 389 |
+
raise RuntimeError(f"Failed initial config/weights load from HF Hub {model_id}: {e_config}") from e_config
|
| 390 |
+
|
| 391 |
+
# No Schema Prefix - Use built-in name + pretrained arg (tag or file)
|
| 392 |
+
elif schema is None:
|
| 393 |
+
# Handle model names without schema prefix
|
| 394 |
+
# Use identifier (original model_name) and clean it for lookup
|
| 395 |
+
model_name_cleaned = identifier.replace('/', '-')
|
| 396 |
+
|
| 397 |
+
# Get base config from built-in name using the cleaned identifier
|
| 398 |
+
model_cfg = get_model_config(model_name_cleaned)
|
| 399 |
+
if model_cfg is None:
|
| 400 |
+
# Raise error if no matching built-in config found
|
| 401 |
+
raise RuntimeError(
|
| 402 |
+
f"Model config for '{model_name_cleaned}' not found in built-ins. Available: {list_models()}")
|
| 403 |
+
logging.info(f"Loaded built-in {model_name_cleaned} model config.")
|
| 404 |
+
|
| 405 |
+
# Determine checkpoint path and update preprocess_cfg based on `pretrained` arg (tag or file)
|
| 406 |
+
if pretrained:
|
| 407 |
+
# Check if `pretrained` is a known tag
|
| 408 |
+
pretrained_cfg_for_tag = get_pretrained_cfg(model_name_cleaned, pretrained)
|
| 409 |
+
if pretrained_cfg_for_tag:
|
| 410 |
+
try:
|
| 411 |
+
# Download weights associated with the tag
|
| 412 |
+
checkpoint_path = download_pretrained(pretrained_cfg_for_tag, cache_dir=cache_dir)
|
| 413 |
+
preprocess_cfg = merge_preprocess_dict(preprocess_cfg, pretrained_cfg_for_tag)
|
| 414 |
+
# QuickGELU compatibility check will happen in after force overrides
|
| 415 |
+
except Exception as e:
|
| 416 |
+
logging.error(f"Failed to download weights for tag '{pretrained}': {e}")
|
| 417 |
+
raise RuntimeError(f"Failed to download weights for tag '{pretrained}': {e}")
|
| 418 |
+
elif os.path.isfile(pretrained):
|
| 419 |
+
# Handle pretrained file path
|
| 420 |
+
logging.info(f"`pretrained` specifies file path: {pretrained}")
|
| 421 |
+
checkpoint_path = pretrained
|
| 422 |
+
else:
|
| 423 |
+
logging.error(
|
| 424 |
+
f"Pretrained tag or path ({pretrained}) for '{model_name_cleaned}' not found. "
|
| 425 |
+
f"Available tags: {list_pretrained_tags_by_model(model_name_cleaned)}"
|
| 426 |
+
)
|
| 427 |
+
raise RuntimeError(f"Pretrained value '{pretrained}' is not a known tag or valid file path")
|
| 428 |
+
|
| 429 |
+
# Apply model config overrides
|
| 430 |
+
if model_cfg is None:
|
| 431 |
+
raise RuntimeError("Model configuration could not be determined after Stage 1.")
|
| 432 |
+
|
| 433 |
+
# print("model_cfg:", model_cfg)
|
| 434 |
+
# >>> model_cfg: {'embed_dim': 512, 'vision_cfg': {'timm_model_name': 'vit_base_singlescan_h2_token2744', 'timm_model_pretrained': True, 'timm_drop_path': 0.2, 'timm_pool': 'token', 'timm_proj': 'linear'}, 'text_cfg': {'hf_model_name': 'microsoft/BiomedNLP-BiomedBERT-base-uncased-abstract-fulltext', 'hf_tokenizer_name': 'microsoft/BiomedVLP-CXR-BERT-specialized', 'hf_pooler_type': 'cls_last_hidden_state_pooler', 'hf_proj_type': 'linear', 'context_length': 512}}
|
| 435 |
+
# import sys
|
| 436 |
+
# sys.exit()
|
| 437 |
+
|
| 438 |
+
text_cfg = model_cfg['text_cfg']
|
| 439 |
+
vision_cfg = model_cfg['vision_cfg']
|
| 440 |
+
if force_quick_gelu:
|
| 441 |
+
model_cfg["quick_gelu"] = True
|
| 442 |
+
if force_patch_dropout is not None:
|
| 443 |
+
vision_cfg["patch_dropout"] = force_patch_dropout
|
| 444 |
+
if force_image_size is not None:
|
| 445 |
+
vision_cfg["image_size"] = force_image_size
|
| 446 |
+
if force_context_length is not None:
|
| 447 |
+
text_cfg["context_length"] = force_context_length
|
| 448 |
+
|
| 449 |
+
# Check compatibility (e.g., QuickGELU warning for tags)
|
| 450 |
+
if schema is None and pretrained_cfg_for_tag:
|
| 451 |
+
# Only perform check if config came from built-in and weights from a tag
|
| 452 |
+
model_quick_gelu = model_cfg.get('quick_gelu', False) # Check the potentially overridden value
|
| 453 |
+
tag_quick_gelu = pretrained_cfg_for_tag.get('quick_gelu', False)
|
| 454 |
+
if tag_quick_gelu != model_quick_gelu:
|
| 455 |
+
# Warn if the final model config's GELU setting mismatches the tag's training setting
|
| 456 |
+
warnings.warn(
|
| 457 |
+
f"QuickGELU mismatch between final model config (quick_gelu={model_quick_gelu}) "
|
| 458 |
+
f"and pretrained tag '{pretrained}' (quick_gelu={tag_quick_gelu}).",
|
| 459 |
+
UserWarning
|
| 460 |
+
)
|
| 461 |
+
|
| 462 |
+
# Decide whether to use the checkpoint path based on load_weights
|
| 463 |
+
if checkpoint_path is not None:
|
| 464 |
+
if not load_weights:
|
| 465 |
+
logging.info(
|
| 466 |
+
f"Potential checkpoint path '{checkpoint_path}' found, but skipping assignment due to load_weights=False.")
|
| 467 |
+
checkpoint_path = None
|
| 468 |
+
else:
|
| 469 |
+
logging.info("No potential checkpoint path found from config source or pretrained arg.")
|
| 470 |
+
|
| 471 |
+
# Set default base weight loading flags for image and text towers
|
| 472 |
+
# Only load base pretrained weights if other weights will not be loaded into respective towers
|
| 473 |
+
enable_default_image_weights = pretrained_image and pretrained_image_path is None and checkpoint_path is None
|
| 474 |
+
enable_default_text_weights = pretrained_text and pretrained_text_path is None and checkpoint_path is None
|
| 475 |
+
is_timm_model = 'timm_model_name' in model_cfg.get("vision_cfg", {})
|
| 476 |
+
is_hf_text_model = 'hf_model_name' in model_cfg.get('text_cfg', {})
|
| 477 |
+
if is_timm_model:
|
| 478 |
+
vision_cfg['timm_model_pretrained'] = enable_default_image_weights
|
| 479 |
+
else:
|
| 480 |
+
enable_default_image_weights = False # for accurate logging
|
| 481 |
+
if is_hf_text_model:
|
| 482 |
+
text_cfg['hf_model_pretrained'] = enable_default_text_weights
|
| 483 |
+
else:
|
| 484 |
+
enable_default_text_weights = False # for accurate logging
|
| 485 |
+
|
| 486 |
+
# Determine model class (CLIP, CustomTextCLIP, CoCa)
|
| 487 |
+
custom_text = model_cfg.pop('custom_text', False) or force_custom_text or is_hf_text_model
|
| 488 |
+
if custom_text:
|
| 489 |
+
# Use CustomTextCLIP (or CoCa if multimodal_cfg is present)
|
| 490 |
+
if "multimodal_cfg" in model_cfg:
|
| 491 |
+
model_class = CoCa
|
| 492 |
+
else:
|
| 493 |
+
model_class = CustomTextCLIP
|
| 494 |
+
else:
|
| 495 |
+
# Default to standard CLIP
|
| 496 |
+
model_class = CLIP
|
| 497 |
+
|
| 498 |
+
# Apply final **kwargs overrides (highest priority) to a copy of model_cfg
|
| 499 |
+
final_model_cfg = deepcopy(model_cfg)
|
| 500 |
+
final_model_cfg.update(model_kwargs)
|
| 501 |
+
|
| 502 |
+
# Get casting dtype based on precision argument
|
| 503 |
+
cast_dtype = get_cast_dtype(precision)
|
| 504 |
+
|
| 505 |
+
# Instantiate the model
|
| 506 |
+
logging.info(f"Instantiating model architecture: {model_class.__name__}")
|
| 507 |
+
model = model_class(**final_model_cfg, cast_dtype=cast_dtype)
|
| 508 |
+
_set_model_device_and_precision(model, device, precision, is_timm_model)
|
| 509 |
+
|
| 510 |
+
# Load Full Pretrained CLIP Weights (if path exists)
|
| 511 |
+
pretrained_loaded = False
|
| 512 |
+
if checkpoint_path:
|
| 513 |
+
logging.info(f'Loading full pretrained weights from: {checkpoint_path}')
|
| 514 |
+
# Use the load_checkpoint helper which handles state dict loading, conversions, etc.
|
| 515 |
+
# Use strict=True by default for full model loading to catch mismatches.
|
| 516 |
+
load_checkpoint(
|
| 517 |
+
model,
|
| 518 |
+
checkpoint_path,
|
| 519 |
+
strict=True,
|
| 520 |
+
weights_only=weights_only,
|
| 521 |
+
device='cpu' # Load to CPU first
|
| 522 |
+
)
|
| 523 |
+
pretrained_loaded = True
|
| 524 |
+
|
| 525 |
+
# Load tower-specific weights (image and text), after the full CLIP checkpoint, potentially overwriting parts.
|
| 526 |
+
pretrained_image_loaded = False # Track if specific image weights loaded
|
| 527 |
+
if pretrained_image_path:
|
| 528 |
+
if os.path.isfile(pretrained_image_path):
|
| 529 |
+
logging.info(f"Attempting to load image tower weights from: {pretrained_image_path}")
|
| 530 |
+
try:
|
| 531 |
+
# Load the state dict from the file
|
| 532 |
+
image_state_dict = load_state_dict(
|
| 533 |
+
pretrained_image_path,
|
| 534 |
+
device='cpu',
|
| 535 |
+
weights_only=weights_only
|
| 536 |
+
)
|
| 537 |
+
# Check if model has the 'visual' attribute
|
| 538 |
+
if hasattr(model, 'visual'):
|
| 539 |
+
# Load into the visual tower, use strict=False for flexibility
|
| 540 |
+
incompatible_keys = model.visual.load_state_dict(image_state_dict, strict=False)
|
| 541 |
+
logging.info(
|
| 542 |
+
f"Loaded image tower weights from {pretrained_image_path}. Incompatible keys: {incompatible_keys}")
|
| 543 |
+
pretrained_image_loaded = True # Mark specific image weights as loaded
|
| 544 |
+
else:
|
| 545 |
+
# Model structure doesn't match expectation
|
| 546 |
+
logging.warning(
|
| 547 |
+
f"Model does not have a 'visual' attribute, cannot load image tower weights from {pretrained_image_path}")
|
| 548 |
+
except Exception as e:
|
| 549 |
+
# Handle errors during image tower weight loading
|
| 550 |
+
logging.error(f"Error loading image tower weights from {pretrained_image_path}: {e}")
|
| 551 |
+
else:
|
| 552 |
+
# Path provided is not a valid file
|
| 553 |
+
logging.warning(f"Invalid file path specified for pretrained_image_path: {pretrained_image_path}")
|
| 554 |
+
|
| 555 |
+
pretrained_text_loaded = False # Track if specific text weights loaded
|
| 556 |
+
if pretrained_text_path:
|
| 557 |
+
if os.path.isfile(pretrained_text_path):
|
| 558 |
+
logging.info(f"Attempting to load text tower weights from: {pretrained_text_path}")
|
| 559 |
+
try:
|
| 560 |
+
# Load the state dict from the file
|
| 561 |
+
text_state_dict = load_state_dict(
|
| 562 |
+
pretrained_text_path,
|
| 563 |
+
device='cpu',
|
| 564 |
+
weights_only=weights_only
|
| 565 |
+
)
|
| 566 |
+
# Safely get the text attribute (usually 'text', but could be different)
|
| 567 |
+
text_module = getattr(model, 'text', model)
|
| 568 |
+
if text_module is not None:
|
| 569 |
+
# Load into the text tower, use strict=False for flexibility
|
| 570 |
+
incompatible_keys = text_module.load_state_dict(text_state_dict, strict=False)
|
| 571 |
+
logging.info(f"Loaded text tower weights from {pretrained_text_path}. Incompatible keys: {incompatible_keys}")
|
| 572 |
+
pretrained_text_loaded = True # Mark specific text weights as loaded
|
| 573 |
+
else:
|
| 574 |
+
# Model structure doesn't match expectation
|
| 575 |
+
logging.warning(f"Model does not have a standard 'text' attribute, cannot load text tower weights from {pretrained_text_path}")
|
| 576 |
+
except Exception as e:
|
| 577 |
+
# Handle errors during text tower weight loading
|
| 578 |
+
logging.error(f"Error loading text tower weights from {pretrained_text_path}: {e}")
|
| 579 |
+
else:
|
| 580 |
+
# Path provided is not a valid file
|
| 581 |
+
logging.warning(f"Invalid file path specified for pretrained_text_path: {pretrained_text_path}")
|
| 582 |
+
|
| 583 |
+
partially_loaded = enable_default_text_weights or enable_default_image_weights \
|
| 584 |
+
or pretrained_image_loaded or pretrained_text_loaded
|
| 585 |
+
if require_pretrained and not pretrained_loaded:
|
| 586 |
+
# If CLIP weights were required but failed to load, raise an error.
|
| 587 |
+
# Loading tower-specific weights does not satisfy `require_pretrained`.
|
| 588 |
+
raise RuntimeError(
|
| 589 |
+
f"Required pretrained weights (`model_name='{model_name}', pretrained='{pretrained}'`) could not be loaded. "
|
| 590 |
+
)
|
| 591 |
+
elif not pretrained_loaded and partially_loaded:
|
| 592 |
+
# Some tower weights loaded
|
| 593 |
+
logging.warning(f"Model {model_name} initialized partially.")
|
| 594 |
+
elif not pretrained_loaded and not partially_loaded:
|
| 595 |
+
# Absolutely no weights were loaded from any source
|
| 596 |
+
logging.warning(f"No pretrained weights loaded for model '{model_name}'. Model initialized randomly.")
|
| 597 |
+
|
| 598 |
+
if output_dict and hasattr(model, "output_dict"):
|
| 599 |
+
# Enable dictionary output if model supports it
|
| 600 |
+
model.output_dict = True
|
| 601 |
+
|
| 602 |
+
# If force_image_size was specified and we have a timm model, call set_input_size after loading weights
|
| 603 |
+
if force_image_size is not None and is_timm_model and hasattr(model.visual, 'set_input_size'):
|
| 604 |
+
logging.info(f"Calling set_input_size({force_image_size}) on timm vision model.")
|
| 605 |
+
model.visual.set_input_size(force_image_size)
|
| 606 |
+
|
| 607 |
+
if jit:
|
| 608 |
+
logging.info("Attempting JIT scripting...")
|
| 609 |
+
try:
|
| 610 |
+
model = torch.jit.script(model)
|
| 611 |
+
logging.info("JIT scripting successful.")
|
| 612 |
+
except Exception as e:
|
| 613 |
+
logging.warning(f"JIT scripting failed: {e}. Returning non-JIT model.")
|
| 614 |
+
|
| 615 |
+
# Prepare and set final preprocessing configuration on the model
|
| 616 |
+
final_preprocess_cfg = deepcopy(preprocess_cfg) # Start with config determined earlier
|
| 617 |
+
# Ensure image_size in preprocess config matches the actual model's visual component size, if possible
|
| 618 |
+
visual_module = getattr(model, 'visual', None)
|
| 619 |
+
if visual_module is not None and hasattr(visual_module, 'image_size'):
|
| 620 |
+
# Update preprocess size from the instantiated visual module
|
| 621 |
+
final_preprocess_cfg['size'] = visual_module.image_size
|
| 622 |
+
# Apply force_preprocess_cfg overrides (highest priority for preprocessing)
|
| 623 |
+
final_preprocess_cfg = merge_preprocess_dict(final_preprocess_cfg, force_preprocess_cfg or {})
|
| 624 |
+
|
| 625 |
+
# Attach the final config to the model
|
| 626 |
+
set_model_preprocess_cfg(model, final_preprocess_cfg)
|
| 627 |
+
logging.info(f"Final image preprocessing configuration set: {final_preprocess_cfg}")
|
| 628 |
+
|
| 629 |
+
# Log completion and return the configured model
|
| 630 |
+
logging.info(f"Model {model_name} creation process complete.")
|
| 631 |
+
return model
|
| 632 |
+
|
| 633 |
+
|
| 634 |
+
def get_tokenizer(
|
| 635 |
+
model_name: str = '',
|
| 636 |
+
context_length: Optional[int] = None,
|
| 637 |
+
cache_dir: Optional[str] = None,
|
| 638 |
+
**kwargs, # Additional tokenizer kwargs passed to constructor
|
| 639 |
+
):
|
| 640 |
+
"""
|
| 641 |
+
Gets the appropriate tokenizer based on the model identifier schema or name.
|
| 642 |
+
|
| 643 |
+
`model_name` can specify source via schema:
|
| 644 |
+
- 'ViT-B-32': Looks up built-in config to determine tokenizer type.
|
| 645 |
+
- 'hf-hub:org/repo': Loads config from HF Hub to determine tokenizer type.
|
| 646 |
+
- 'local-dir:/path/to/folder': Loads config from local dir to determine tokenizer type.
|
| 647 |
+
"""
|
| 648 |
+
schema, identifier = parse_model_name(model_name)
|
| 649 |
+
|
| 650 |
+
config = {} # Stores the loaded model_cfg relevant section (usually text_cfg)
|
| 651 |
+
local_dir_path = None # Store path if schema is local-dir to resolve relative paths
|
| 652 |
+
hf_fallback_id = None
|
| 653 |
+
|
| 654 |
+
# Determine Configuration Source based on Schema
|
| 655 |
+
logging.info(f"Parsing tokenizer identifier. Schema: {schema}, Identifier: {identifier}")
|
| 656 |
+
|
| 657 |
+
if schema == 'local-dir':
|
| 658 |
+
# Handle local directory schema
|
| 659 |
+
local_dir_path = Path(identifier) # Store the path for later use
|
| 660 |
+
if not local_dir_path.is_dir():
|
| 661 |
+
raise FileNotFoundError(f"Directory specified via 'local-dir:' schema not found at {local_dir_path}")
|
| 662 |
+
local_config_path = local_dir_path / 'open_clip_config.json'
|
| 663 |
+
logging.info(f"Attempting to load config from local-dir: {local_config_path}")
|
| 664 |
+
if local_config_path.is_file():
|
| 665 |
+
try:
|
| 666 |
+
# Load and parse the JSON config
|
| 667 |
+
with open(local_config_path, 'r', encoding='utf-8') as f:
|
| 668 |
+
local_json_config = json.load(f)
|
| 669 |
+
if 'model_cfg' in local_json_config:
|
| 670 |
+
config = local_json_config['model_cfg']
|
| 671 |
+
else:
|
| 672 |
+
raise ValueError(f"Local config {local_config_path} missing 'model_cfg'.")
|
| 673 |
+
except Exception as e:
|
| 674 |
+
raise ValueError(f"Could not load valid config for 'local-dir:{identifier}' ({e}).") from e
|
| 675 |
+
else:
|
| 676 |
+
raise FileNotFoundError(f"'local-dir:' specified, but config file missing: {local_config_path}")
|
| 677 |
+
|
| 678 |
+
elif schema == 'hf-hub':
|
| 679 |
+
# Handle Hugging Face Hub schema
|
| 680 |
+
model_id = identifier
|
| 681 |
+
logging.info(f"Attempting to load config from hf-hub:{model_id}")
|
| 682 |
+
config_err = ''
|
| 683 |
+
try:
|
| 684 |
+
# Fetch config from HF Hub
|
| 685 |
+
hf_config = _get_hf_config(model_id, cache_dir=cache_dir)
|
| 686 |
+
config = hf_config.get('model_cfg', None)
|
| 687 |
+
if not config:
|
| 688 |
+
config_err = 'model_cfg key not found'
|
| 689 |
+
except Exception as e:
|
| 690 |
+
config_err = str(e)
|
| 691 |
+
if not config:
|
| 692 |
+
hf_fallback_id = model_id
|
| 693 |
+
config = {}
|
| 694 |
+
logging.warning(
|
| 695 |
+
f"Could not load config from hf-hub:{model_id} ({config_err})."
|
| 696 |
+
f"Falling back to using model_id for tokenizer.")
|
| 697 |
+
|
| 698 |
+
elif schema is None and identifier:
|
| 699 |
+
# Try built-in config lookup using the identifier (original model_name)
|
| 700 |
+
logging.info(f"Attempting to load config from built-in: {identifier}")
|
| 701 |
+
config = get_model_config(identifier)
|
| 702 |
+
|
| 703 |
+
# Check if config determination failed completely (should only be possible if initial schema parsing failed badly)
|
| 704 |
+
if config is None:
|
| 705 |
+
logging.warning(f"Model configuration not found, returning default SimpleTokenizer.")
|
| 706 |
+
return SimpleTokenizer(context_length=context_length or DEFAULT_CONTEXT_LENGTH, **kwargs)
|
| 707 |
+
|
| 708 |
+
# Safely access text_cfg even if config is {} (from non-builtin name case)
|
| 709 |
+
text_config = config.get('text_cfg', {})
|
| 710 |
+
|
| 711 |
+
# Resolve context length: argument > config > default
|
| 712 |
+
if context_length is None:
|
| 713 |
+
# Use context_length from text_cfg if available, otherwise default
|
| 714 |
+
context_length = text_config.get('context_length', DEFAULT_CONTEXT_LENGTH)
|
| 715 |
+
|
| 716 |
+
# Merge tokenizer kwargs: function kwargs override config kwargs
|
| 717 |
+
tokenizer_kwargs = text_config.get('tokenizer_kwargs', {}) # Start with config kwargs
|
| 718 |
+
tokenizer_kwargs.update(kwargs) # Apply caller kwargs, overriding config ones
|
| 719 |
+
|
| 720 |
+
# Get the specified HF tokenizer name from config, if any
|
| 721 |
+
hf_tokenizer_name = text_config.get('hf_tokenizer_name', '')
|
| 722 |
+
if not hf_tokenizer_name and hf_fallback_id:
|
| 723 |
+
hf_tokenizer_name = hf_fallback_id
|
| 724 |
+
|
| 725 |
+
if hf_tokenizer_name:
|
| 726 |
+
# If 'hf_tokenizer_name' key exists in text_cfg (even if empty string): Use HFTokenizer.
|
| 727 |
+
if schema == 'local-dir':
|
| 728 |
+
# If config came from local-dir, ALWAYS use the local dir path for HFTokenizer.
|
| 729 |
+
# This assumes the tokenizer files are inside that directory.
|
| 730 |
+
tokenizer_source = local_dir_path
|
| 731 |
+
else:
|
| 732 |
+
tokenizer_source = hf_tokenizer_name
|
| 733 |
+
tokenizer_mode = text_config.get('tokenizer_mode', None)
|
| 734 |
+
|
| 735 |
+
logging.info(f"Using HFTokenizer with source: '{tokenizer_source}', mode: '{tokenizer_mode}'")
|
| 736 |
+
tokenizer = HFTokenizer(
|
| 737 |
+
tokenizer_source,
|
| 738 |
+
context_length=context_length,
|
| 739 |
+
cache_dir=cache_dir,
|
| 740 |
+
tokenizer_mode=tokenizer_mode,
|
| 741 |
+
**tokenizer_kwargs,
|
| 742 |
+
)
|
| 743 |
+
|
| 744 |
+
elif schema is None and 'siglip' in identifier.lower():
|
| 745 |
+
# Check for SigLIP naming convention ONLY if no schema was present AND no hf_tokenizer_name found
|
| 746 |
+
# Avoids misinterpreting 'local-dir:/path/with/siglip/in/name'
|
| 747 |
+
tn_variant = 'gemma' if 'siglip2' in identifier.lower() else 'mc4' if 'i18n' in identifier.lower() else 'c4-en'
|
| 748 |
+
logging.info(f"Using SigLipTokenizer variant: {tn_variant}")
|
| 749 |
+
tokenizer = SigLipTokenizer(
|
| 750 |
+
tn_variant,
|
| 751 |
+
context_length=context_length,
|
| 752 |
+
)
|
| 753 |
+
else:
|
| 754 |
+
# Default to SimpleTokenizer if no HF specified and not SigLIP name match
|
| 755 |
+
logging.info("Using default SimpleTokenizer.")
|
| 756 |
+
tokenizer = SimpleTokenizer(
|
| 757 |
+
context_length=context_length,
|
| 758 |
+
**tokenizer_kwargs,
|
| 759 |
+
)
|
| 760 |
+
|
| 761 |
+
return tokenizer
|
| 762 |
+
|
| 763 |
+
|
| 764 |
+
def _set_model_device_and_precision(
|
| 765 |
+
model: torch.nn.Module,
|
| 766 |
+
device: torch.device,
|
| 767 |
+
precision: str,
|
| 768 |
+
is_timm_model: bool = False
|
| 769 |
+
):
|
| 770 |
+
if precision in ("fp16", "bf16"):
|
| 771 |
+
dtype = torch.float16 if 'fp16' in precision else torch.bfloat16
|
| 772 |
+
# manual mixed precision that matches original OpenAI behaviour
|
| 773 |
+
if is_timm_model:
|
| 774 |
+
from .transformer import LayerNormFp32
|
| 775 |
+
# FIXME this is a bit janky, create timm based model in low-precision and
|
| 776 |
+
# then cast only LayerNormFp32 instances back to float32 so they don't break.
|
| 777 |
+
# Why? The convert_weights_to_lp fn only works with native models.
|
| 778 |
+
model.to(device=device, dtype=dtype)
|
| 779 |
+
|
| 780 |
+
def _convert_ln(m):
|
| 781 |
+
if isinstance(m, LayerNormFp32):
|
| 782 |
+
m.weight.data = m.weight.data.to(torch.float32)
|
| 783 |
+
m.bias.data = m.bias.data.to(torch.float32)
|
| 784 |
+
|
| 785 |
+
model.apply(_convert_ln)
|
| 786 |
+
else:
|
| 787 |
+
model.to(device=device)
|
| 788 |
+
convert_weights_to_lp(model, dtype=dtype)
|
| 789 |
+
elif precision in ("pure_fp16", "pure_bf16"):
|
| 790 |
+
dtype = torch.float16 if 'fp16' in precision else torch.bfloat16
|
| 791 |
+
model.to(device=device, dtype=dtype)
|
| 792 |
+
else:
|
| 793 |
+
model.to(device=device)
|
| 794 |
+
|
| 795 |
+
|
| 796 |
+
def create_loss(args):
|
| 797 |
+
if args.distill:
|
| 798 |
+
return DistillClipLoss(
|
| 799 |
+
local_loss=args.local_loss,
|
| 800 |
+
gather_with_grad=args.gather_with_grad,
|
| 801 |
+
cache_labels=True,
|
| 802 |
+
rank=args.rank,
|
| 803 |
+
world_size=args.world_size,
|
| 804 |
+
use_horovod=args.horovod,
|
| 805 |
+
)
|
| 806 |
+
elif "coca" in args.model.lower():
|
| 807 |
+
return CoCaLoss(
|
| 808 |
+
caption_loss_weight=args.coca_caption_loss_weight,
|
| 809 |
+
clip_loss_weight=args.coca_contrastive_loss_weight,
|
| 810 |
+
local_loss=args.local_loss,
|
| 811 |
+
gather_with_grad=args.gather_with_grad,
|
| 812 |
+
cache_labels=True,
|
| 813 |
+
rank=args.rank,
|
| 814 |
+
world_size=args.world_size,
|
| 815 |
+
use_horovod=args.horovod,
|
| 816 |
+
)
|
| 817 |
+
elif args.siglip:
|
| 818 |
+
assert not args.horovod, "Horovod not currently supported for SigLip"
|
| 819 |
+
return SigLipLoss(
|
| 820 |
+
rank=args.rank,
|
| 821 |
+
world_size=args.world_size,
|
| 822 |
+
dist_impl=args.loss_dist_impl, # siglip has multiple distributed implementations to choose from
|
| 823 |
+
)
|
| 824 |
+
|
| 825 |
+
return ClipLoss(
|
| 826 |
+
local_loss=args.local_loss,
|
| 827 |
+
gather_with_grad=args.gather_with_grad,
|
| 828 |
+
cache_labels=True,
|
| 829 |
+
rank=args.rank,
|
| 830 |
+
world_size=args.world_size,
|
| 831 |
+
use_horovod=args.horovod,
|
| 832 |
+
)
|
| 833 |
+
|
| 834 |
+
|
| 835 |
+
def create_model_and_transforms(
|
| 836 |
+
model_name: str,
|
| 837 |
+
pretrained: Optional[str] = None,
|
| 838 |
+
load_weights: bool = True,
|
| 839 |
+
precision: str = 'fp32',
|
| 840 |
+
device: Union[str, torch.device] = 'cpu',
|
| 841 |
+
jit: bool = False,
|
| 842 |
+
force_quick_gelu: bool = False,
|
| 843 |
+
force_custom_text: bool = False,
|
| 844 |
+
force_patch_dropout: Optional[float] = None,
|
| 845 |
+
force_image_size: Optional[Union[int, Tuple[int, int]]] = None,
|
| 846 |
+
force_context_length: Optional[int] = None,
|
| 847 |
+
image_mean: Optional[Tuple[float, ...]] = None,
|
| 848 |
+
image_std: Optional[Tuple[float, ...]] = None,
|
| 849 |
+
image_interpolation: Optional[str] = None,
|
| 850 |
+
image_resize_mode: Optional[str] = None, # only effective for inference
|
| 851 |
+
aug_cfg: Optional[Union[Dict[str, Any], AugmentationCfg]] = None,
|
| 852 |
+
pretrained_image: bool = False,
|
| 853 |
+
pretrained_text: bool = True,
|
| 854 |
+
pretrained_image_path: Optional[str] = None,
|
| 855 |
+
pretrained_text_path: Optional[str] = None,
|
| 856 |
+
cache_dir: Optional[str] = None,
|
| 857 |
+
output_dict: Optional[bool] = None,
|
| 858 |
+
weights_only: bool = True,
|
| 859 |
+
**model_kwargs,
|
| 860 |
+
):
|
| 861 |
+
"""
|
| 862 |
+
创建一个对比式视觉-语言模型,并同时创建用于训练和验证的预处理 transforms。
|
| 863 |
+
|
| 864 |
+
这个函数将模型创建与合适的图像预处理流水线组合在一起,
|
| 865 |
+
方便在既需要模型又需要 transforms 的训练工作流中使用。
|
| 866 |
+
|
| 867 |
+
`model_name` 用来指定结构 / 配置的来源:
|
| 868 |
+
- 'ViT-B-32':内置模型名称。`pretrained` 指定 CLIP 权重来源(tag 或文件路径)。
|
| 869 |
+
- 'hf-hub:org/repo':从 Hugging Face Hub 加载配置 / 权重。此时会忽略 `pretrained`。
|
| 870 |
+
- 'local-dir:/path/to/folder':从本地文件夹加载配置 / 权重。此时会忽略 `pretrained`。
|
| 871 |
+
|
| 872 |
+
预处理 transforms 会根据模型的需求自动配置,
|
| 873 |
+
并为训练(带数据增强)和验证(不带数据增强)分别构建独立流水线。
|
| 874 |
+
|
| 875 |
+
Args:
|
| 876 |
+
model_name: 模型标识符,可能带有 schema('hf-hub:', 'local-dir:')。
|
| 877 |
+
pretrained: 当 `model_name` 没有 schema 时,CLIP 权重的来源(tag 或文件路径)。
|
| 878 |
+
load_weights: 若为 True,则加载解析得到的预训练权重;否则仅随机初始化或应用 tower 覆盖。
|
| 879 |
+
precision: 模型精度('fp32'、'fp16'、'bf16' 等)。
|
| 880 |
+
device: 设备('cpu'、'cuda' 等)。
|
| 881 |
+
jit: 若为 True,则对模型进行 JIT 编译。
|
| 882 |
+
force_quick_gelu: 在模型配置中强制使用 QuickGELU 激活函数。
|
| 883 |
+
force_custom_text: 强制使用自定义的文本编码器结构。
|
| 884 |
+
force_patch_dropout: 覆盖模型配置中的 patch dropout 值。
|
| 885 |
+
force_image_size: 覆盖模型配置中的图像尺寸。
|
| 886 |
+
force_context_length: 覆盖模型配置中的上下文长度。
|
| 887 |
+
image_mean: 覆盖默认图像归一化的均值(按通道)。
|
| 888 |
+
image_std: 覆盖默认图像归一化的标准差(按通道)。
|
| 889 |
+
image_interpolation: 覆盖图像缩放时默认使用的插值方式。
|
| 890 |
+
image_resize_mode: 覆盖推理预处理中的缩放模式('squash'、'longest'、'shortest')。
|
| 891 |
+
aug_cfg: 训练 transforms 的数据增强配置。可以是 dict 或 AugmentationCfg 对象。
|
| 892 |
+
控制随机裁剪、颜色抖动等。如果为 None,则使用模型默认设置。
|
| 893 |
+
pretrained_image: 当没有加载 CLIP 权重时,在创建时为 image tower 加载默认的(timm)基础权重。
|
| 894 |
+
pretrained_text: 当没有加载 CLIP 权重时,在创建时为 text tower 加载默认的(hf)基础权重。
|
| 895 |
+
pretrained_image_path: 在创建后,将指定路径的权重加载到 image tower 中。
|
| 896 |
+
pretrained_text_path: 在创建后,将指定路径的权重加载到 text tower 中。
|
| 897 |
+
cache_dir: 下载文件的缓存目录。
|
| 898 |
+
output_dict: 若为 True 且模型支持,则使用 dict 形式的输出。
|
| 899 |
+
weights_only: 为 torch.load 使用 weights_only=True(更安全)。
|
| 900 |
+
**model_kwargs: 传给模型构造函数的额外关键字参数(优先级最高的覆盖项)。
|
| 901 |
+
|
| 902 |
+
Returns:
|
| 903 |
+
Tuple[torch.nn.Module, Callable, Callable]: 包含以下内容的三元组:
|
| 904 |
+
- model: 创建好的模型实例
|
| 905 |
+
- preprocess_train: 训练用的图像预处理 transform(包含数据增强)
|
| 906 |
+
- preprocess_val: 验证 / 推理用的图像预处理 transform(不包含数据增强)
|
| 907 |
+
|
| 908 |
+
Example:
|
| 909 |
+
>>> # 使用内置模型的基础示例
|
| 910 |
+
>>> model, train_transform, val_transform = create_model_and_transforms('ViT-B-32', pretrained='openai')
|
| 911 |
+
>>>
|
| 912 |
+
>>> # 使用自定义数据增强
|
| 913 |
+
>>> aug_cfg = {'scale': (0.9, 1.0), 'ratio': (1.0, 1.0)}
|
| 914 |
+
>>> model, train_transform, val_transform = create_model_and_transforms(
|
| 915 |
+
... 'ViT-L-14',
|
| 916 |
+
... pretrained='datacomp_xl_s13b_b90k',
|
| 917 |
+
... aug_cfg=aug_cfg
|
| 918 |
+
... )
|
| 919 |
+
>>>
|
| 920 |
+
>>> # 从 Hugging Face Hub 加载
|
| 921 |
+
>>> model, train_transform, val_transform = create_model_and_transforms('hf-hub:org/model-repo')
|
| 922 |
+
|
| 923 |
+
Note:
|
| 924 |
+
训练用的 transform 会根据 `aug_cfg` 启用数据增强,而验证用的 transform
|
| 925 |
+
只执行必要的预处理(缩放、中心裁剪、归一化),不会进行任何随机增强。
|
| 926 |
+
"""
|
| 927 |
+
force_preprocess_cfg = merge_preprocess_kwargs(
|
| 928 |
+
{},
|
| 929 |
+
mean=image_mean,
|
| 930 |
+
std=image_std,
|
| 931 |
+
interpolation=image_interpolation,
|
| 932 |
+
resize_mode=image_resize_mode,
|
| 933 |
+
)
|
| 934 |
+
|
| 935 |
+
model = create_model(
|
| 936 |
+
model_name,
|
| 937 |
+
pretrained,
|
| 938 |
+
load_weights=load_weights,
|
| 939 |
+
precision=precision,
|
| 940 |
+
device=device,
|
| 941 |
+
jit=jit,
|
| 942 |
+
force_quick_gelu=force_quick_gelu,
|
| 943 |
+
force_custom_text=force_custom_text,
|
| 944 |
+
force_patch_dropout=force_patch_dropout,
|
| 945 |
+
force_image_size=force_image_size,
|
| 946 |
+
force_preprocess_cfg=force_preprocess_cfg,
|
| 947 |
+
force_context_length=force_context_length,
|
| 948 |
+
pretrained_image=pretrained_image,
|
| 949 |
+
pretrained_text=pretrained_text,
|
| 950 |
+
pretrained_image_path=pretrained_image_path,
|
| 951 |
+
pretrained_text_path=pretrained_text_path,
|
| 952 |
+
cache_dir=cache_dir,
|
| 953 |
+
output_dict=output_dict,
|
| 954 |
+
weights_only=weights_only,
|
| 955 |
+
**model_kwargs,
|
| 956 |
+
)
|
| 957 |
+
|
| 958 |
+
# ** 不是幂运算,而是 “字典拆包(关键词参数展开)” 的意思
|
| 959 |
+
|
| 960 |
+
# # 假设 model.visual.preprocess_cfg 是这样的字典:
|
| 961 |
+
# model.visual.preprocess_cfg = {
|
| 962 |
+
# "image_size": 224,
|
| 963 |
+
# "interpolation": "bicubic",
|
| 964 |
+
# "mean": [0.5, 0.5, 0.5],
|
| 965 |
+
# }
|
| 966 |
+
|
| 967 |
+
# # 那这一行就等价于:
|
| 968 |
+
# pp_cfg = PreprocessCfg(
|
| 969 |
+
# image_size=224,
|
| 970 |
+
# interpolation="bicubic",
|
| 971 |
+
# mean=[0.5, 0.5, 0.5],
|
| 972 |
+
# )
|
| 973 |
+
|
| 974 |
+
pp_cfg = PreprocessCfg(**model.visual.preprocess_cfg)
|
| 975 |
+
|
| 976 |
+
preprocess_train = image_transform_v2(
|
| 977 |
+
pp_cfg,
|
| 978 |
+
is_train=True,
|
| 979 |
+
aug_cfg=aug_cfg,
|
| 980 |
+
)
|
| 981 |
+
preprocess_val = image_transform_v2(
|
| 982 |
+
pp_cfg,
|
| 983 |
+
is_train=False,
|
| 984 |
+
)
|
| 985 |
+
|
| 986 |
+
return model, preprocess_train, preprocess_val
|
| 987 |
+
|
| 988 |
+
|
| 989 |
+
def create_model_from_pretrained(
|
| 990 |
+
model_name: str,
|
| 991 |
+
pretrained: Optional[str] = None,
|
| 992 |
+
precision: str = 'fp32',
|
| 993 |
+
device: Union[str, torch.device] = 'cpu',
|
| 994 |
+
jit: bool = False,
|
| 995 |
+
force_quick_gelu: bool = False,
|
| 996 |
+
force_custom_text: bool = False,
|
| 997 |
+
force_image_size: Optional[Union[int, Tuple[int, int]]] = None,
|
| 998 |
+
force_context_length: Optional[int] = None,
|
| 999 |
+
image_mean: Optional[Tuple[float, ...]] = None,
|
| 1000 |
+
image_std: Optional[Tuple[float, ...]] = None,
|
| 1001 |
+
image_interpolation: Optional[str] = None,
|
| 1002 |
+
image_resize_mode: Optional[str] = None, # only effective for inference
|
| 1003 |
+
return_transform: bool = True,
|
| 1004 |
+
cache_dir: Optional[str] = None,
|
| 1005 |
+
weights_only: bool = True,
|
| 1006 |
+
**model_kwargs,
|
| 1007 |
+
):
|
| 1008 |
+
"""
|
| 1009 |
+
Creates a contrastive vision-language model from pretrained weights with optional preprocessing transform.
|
| 1010 |
+
|
| 1011 |
+
This function is a convenience wrapper around `create_model` that enforces loading of pretrained weights
|
| 1012 |
+
(require_pretrained=True) and optionally returns the appropriate preprocessing transform for inference.
|
| 1013 |
+
It's designed for use cases where a pretrained model is required, such as feature extraction,
|
| 1014 |
+
zero-shot classification, or fine-tuning.
|
| 1015 |
+
|
| 1016 |
+
`model_name` specifies architecture/config source:
|
| 1017 |
+
- 'ViT-B-32': Built-in model name. `pretrained` specifies CLIP weights source (tag or file path).
|
| 1018 |
+
- 'hf-hub:org/repo': Loads config/weights from HF Hub. `pretrained` is IGNORED.
|
| 1019 |
+
- 'local-dir:/path/to/folder': Loads config/weights from local dir. `pretrained` is IGNORED.
|
| 1020 |
+
|
| 1021 |
+
Unlike `create_model`, this function will raise an error if pretrained weights cannot be loaded.
|
| 1022 |
+
|
| 1023 |
+
Args:
|
| 1024 |
+
model_name: Model identifier, potentially with schema ('hf-hub:', 'local-dir:').
|
| 1025 |
+
pretrained: Source for CLIP weights (tag or file path) ONLY if model_name has no schema.
|
| 1026 |
+
If None and schema requires it, will raise an error.
|
| 1027 |
+
precision: Model precision ('fp32', 'fp16', 'bf16', ...).
|
| 1028 |
+
device: Device ('cpu', 'cuda', ...).
|
| 1029 |
+
jit: If True, JIT compile the model.
|
| 1030 |
+
force_quick_gelu: Force use of QuickGELU activation in model config.
|
| 1031 |
+
force_custom_text: Force use of custom text encoder architecture.
|
| 1032 |
+
force_image_size: Override image size in model config. Useful for using models at different resolutions.
|
| 1033 |
+
force_context_length: Override context length in model config.
|
| 1034 |
+
image_mean: Override default image normalization mean values (per channel).
|
| 1035 |
+
image_std: Override default image normalization std values (per channel).
|
| 1036 |
+
image_interpolation: Override default interpolation method for image resizing ('bicubic', 'bilinear', 'nearest').
|
| 1037 |
+
image_resize_mode: Override resize mode for inference preprocessing ('squash', 'longest', 'shortest').
|
| 1038 |
+
Only affects the returned preprocessing transform, not training.
|
| 1039 |
+
return_transform: If True, returns (model, preprocess). If False, returns only model.
|
| 1040 |
+
cache_dir: Cache directory for downloads.
|
| 1041 |
+
weights_only: Use weights_only=True for torch.load (safer).
|
| 1042 |
+
**model_kwargs: Additional keyword arguments for model constructor (highest override priority).
|
| 1043 |
+
|
| 1044 |
+
Returns:
|
| 1045 |
+
Union[torch.nn.Module, Tuple[torch.nn.Module, Callable]]:
|
| 1046 |
+
- If return_transform=False: Just the model instance
|
| 1047 |
+
- If return_transform=True: Tuple of (model, preprocess) where preprocess is the
|
| 1048 |
+
inference preprocessing transform
|
| 1049 |
+
|
| 1050 |
+
Raises:
|
| 1051 |
+
RuntimeError: If pretrained weights are required but cannot be loaded.
|
| 1052 |
+
|
| 1053 |
+
Example:
|
| 1054 |
+
>>> # Load model with preprocessing
|
| 1055 |
+
>>> model, preprocess = create_model_from_pretrained('ViT-B-32', pretrained='openai')
|
| 1056 |
+
>>>
|
| 1057 |
+
>>> # Load model without preprocessing (e.g., when using custom preprocessing)
|
| 1058 |
+
>>> model = create_model_from_pretrained('ViT-B-32', pretrained='openai', return_transform=False)
|
| 1059 |
+
>>>
|
| 1060 |
+
>>> # Load from Hugging Face Hub
|
| 1061 |
+
>>> model, preprocess = create_model_from_pretrained('hf-hub:laion/CLIP-ViT-L-14-DataComp.XL-s13B-b90K')
|
| 1062 |
+
>>>
|
| 1063 |
+
>>> # Load with custom image size
|
| 1064 |
+
>>> model, preprocess = create_model_from_pretrained(
|
| 1065 |
+
... 'ViT-L-14',
|
| 1066 |
+
... pretrained='openai',
|
| 1067 |
+
... force_image_size=336
|
| 1068 |
+
... )
|
| 1069 |
+
|
| 1070 |
+
Note:
|
| 1071 |
+
This function always requires pretrained weights to be available and loaded successfully.
|
| 1072 |
+
For cases where you want to create a model without pretrained weights or with only
|
| 1073 |
+
partial weight loading, use `create_model` or `create_model_and_transforms` instead.
|
| 1074 |
+
"""
|
| 1075 |
+
force_preprocess_cfg = merge_preprocess_kwargs(
|
| 1076 |
+
{},
|
| 1077 |
+
mean=image_mean,
|
| 1078 |
+
std=image_std,
|
| 1079 |
+
interpolation=image_interpolation,
|
| 1080 |
+
resize_mode=image_resize_mode,
|
| 1081 |
+
)
|
| 1082 |
+
|
| 1083 |
+
model = create_model(
|
| 1084 |
+
model_name,
|
| 1085 |
+
pretrained,
|
| 1086 |
+
precision=precision,
|
| 1087 |
+
device=device,
|
| 1088 |
+
jit=jit,
|
| 1089 |
+
force_quick_gelu=force_quick_gelu,
|
| 1090 |
+
force_custom_text=force_custom_text,
|
| 1091 |
+
force_image_size=force_image_size,
|
| 1092 |
+
force_preprocess_cfg=force_preprocess_cfg,
|
| 1093 |
+
force_context_length=force_context_length,
|
| 1094 |
+
cache_dir=cache_dir,
|
| 1095 |
+
require_pretrained=True,
|
| 1096 |
+
weights_only=weights_only,
|
| 1097 |
+
**model_kwargs,
|
| 1098 |
+
)
|
| 1099 |
+
|
| 1100 |
+
if not return_transform:
|
| 1101 |
+
return model
|
| 1102 |
+
|
| 1103 |
+
preprocess = image_transform_v2(
|
| 1104 |
+
PreprocessCfg(**model.visual.preprocess_cfg),
|
| 1105 |
+
is_train=False,
|
| 1106 |
+
)
|
| 1107 |
+
|
| 1108 |
+
return model, preprocess
|
hlip/open_clip/src/open_clip/hf_configs.py
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# HF architecture dict:
|
| 2 |
+
arch_dict = {
|
| 3 |
+
# https://huggingface.co/docs/transformers/model_doc/roberta#roberta
|
| 4 |
+
"roberta": {
|
| 5 |
+
"config_names": {
|
| 6 |
+
"context_length": "max_position_embeddings",
|
| 7 |
+
"vocab_size": "vocab_size",
|
| 8 |
+
"width": "hidden_size",
|
| 9 |
+
"heads": "num_attention_heads",
|
| 10 |
+
"layers": "num_hidden_layers",
|
| 11 |
+
"layer_attr": "layer",
|
| 12 |
+
"token_embeddings_attr": "embeddings"
|
| 13 |
+
},
|
| 14 |
+
"pooler": "mean_pooler",
|
| 15 |
+
},
|
| 16 |
+
# https://huggingface.co/docs/transformers/model_doc/xlm-roberta#transformers.XLMRobertaConfig
|
| 17 |
+
"xlm-roberta": {
|
| 18 |
+
"config_names": {
|
| 19 |
+
"context_length": "max_position_embeddings",
|
| 20 |
+
"vocab_size": "vocab_size",
|
| 21 |
+
"width": "hidden_size",
|
| 22 |
+
"heads": "num_attention_heads",
|
| 23 |
+
"layers": "num_hidden_layers",
|
| 24 |
+
"layer_attr": "layer",
|
| 25 |
+
"token_embeddings_attr": "embeddings"
|
| 26 |
+
},
|
| 27 |
+
"pooler": "mean_pooler",
|
| 28 |
+
},
|
| 29 |
+
# https://huggingface.co/docs/transformers/model_doc/mt5#mt5
|
| 30 |
+
"mt5": {
|
| 31 |
+
"config_names": {
|
| 32 |
+
# unlimited seqlen
|
| 33 |
+
# https://github.com/google-research/text-to-text-transfer-transformer/issues/273
|
| 34 |
+
# https://github.com/huggingface/transformers/blob/v4.24.0/src/transformers/models/t5/modeling_t5.py#L374
|
| 35 |
+
"context_length": "",
|
| 36 |
+
"vocab_size": "vocab_size",
|
| 37 |
+
"width": "d_model",
|
| 38 |
+
"heads": "num_heads",
|
| 39 |
+
"layers": "num_layers",
|
| 40 |
+
"layer_attr": "block",
|
| 41 |
+
"token_embeddings_attr": "embed_tokens"
|
| 42 |
+
},
|
| 43 |
+
"pooler": "mean_pooler",
|
| 44 |
+
},
|
| 45 |
+
# https://huggingface.co/docs/transformers/model_doc/bert
|
| 46 |
+
"bert": {
|
| 47 |
+
"config_names": {
|
| 48 |
+
"context_length": "max_position_embeddings",
|
| 49 |
+
"vocab_size": "vocab_size",
|
| 50 |
+
"width": "hidden_size",
|
| 51 |
+
"heads": "num_attention_heads",
|
| 52 |
+
"layers": "num_hidden_layers",
|
| 53 |
+
},
|
| 54 |
+
"pooler": "cls_pooler",
|
| 55 |
+
},
|
| 56 |
+
# https://huggingface.co/docs/transformers/model_doc/m2m_100
|
| 57 |
+
"m2m_100": {
|
| 58 |
+
"config_names": {
|
| 59 |
+
"context_length": "max_position_embeddings",
|
| 60 |
+
"vocab_size": "vocab_size",
|
| 61 |
+
"width": "d_model",
|
| 62 |
+
"heads": "encoder_attention_heads",
|
| 63 |
+
"layers": "encoder_layers",
|
| 64 |
+
},
|
| 65 |
+
"pooler": "cls_pooler",
|
| 66 |
+
},
|
| 67 |
+
}
|
hlip/open_clip/src/open_clip/hf_model.py
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
""" huggingface model adapter
|
| 2 |
+
|
| 3 |
+
Wraps HuggingFace transformers (https://github.com/huggingface/transformers) models for use as a text tower in CLIP model.
|
| 4 |
+
"""
|
| 5 |
+
import re
|
| 6 |
+
|
| 7 |
+
import torch
|
| 8 |
+
import torch.nn as nn
|
| 9 |
+
from torch import TensorType
|
| 10 |
+
|
| 11 |
+
try:
|
| 12 |
+
import transformers
|
| 13 |
+
from transformers import AutoModel, AutoTokenizer, AutoConfig, PretrainedConfig
|
| 14 |
+
from transformers.modeling_outputs import BaseModelOutput, BaseModelOutputWithPooling, \
|
| 15 |
+
BaseModelOutputWithPoolingAndCrossAttentions
|
| 16 |
+
except ImportError as e:
|
| 17 |
+
transformers = None
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
class BaseModelOutput:
|
| 21 |
+
pass
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
class PretrainedConfig:
|
| 25 |
+
pass
|
| 26 |
+
|
| 27 |
+
from .hf_configs import arch_dict
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
# utils
|
| 31 |
+
def _camel2snake(s):
|
| 32 |
+
return re.sub(r'(?<!^)(?=[A-Z])', '_', s).lower()
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
# TODO: ?last - for gpt-like models
|
| 36 |
+
_POOLERS = {}
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def register_pooler(cls):
|
| 40 |
+
"""Decorator registering pooler class"""
|
| 41 |
+
_POOLERS[_camel2snake(cls.__name__)] = cls
|
| 42 |
+
return cls
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
@register_pooler
|
| 46 |
+
class MeanPooler(nn.Module):
|
| 47 |
+
"""Mean pooling"""
|
| 48 |
+
|
| 49 |
+
def forward(self, x: BaseModelOutput, attention_mask: TensorType):
|
| 50 |
+
masked_output = x.last_hidden_state * attention_mask.unsqueeze(-1)
|
| 51 |
+
return masked_output.sum(dim=1) / attention_mask.sum(-1, keepdim=True)
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
@register_pooler
|
| 55 |
+
class MaxPooler(nn.Module):
|
| 56 |
+
"""Max pooling"""
|
| 57 |
+
|
| 58 |
+
def forward(self, x: BaseModelOutput, attention_mask: TensorType):
|
| 59 |
+
masked_output = x.last_hidden_state.masked_fill(attention_mask.unsqueeze(-1), -torch.inf)
|
| 60 |
+
return masked_output.max(1).values
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
@register_pooler
|
| 64 |
+
class ClsPooler(nn.Module):
|
| 65 |
+
"""CLS token pooling"""
|
| 66 |
+
|
| 67 |
+
def __init__(self, use_pooler_output=True):
|
| 68 |
+
super().__init__()
|
| 69 |
+
self.cls_token_position = 0
|
| 70 |
+
self.use_pooler_output = use_pooler_output
|
| 71 |
+
|
| 72 |
+
def forward(self, x: BaseModelOutput, attention_mask: TensorType):
|
| 73 |
+
if (self.use_pooler_output and
|
| 74 |
+
isinstance(x, (BaseModelOutputWithPooling, BaseModelOutputWithPoolingAndCrossAttentions)) and
|
| 75 |
+
(x.pooler_output is not None)
|
| 76 |
+
):
|
| 77 |
+
return x.pooler_output
|
| 78 |
+
|
| 79 |
+
return x.last_hidden_state[:, self.cls_token_position, :]
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
@register_pooler
|
| 83 |
+
class ClsLastHiddenStatePooler(nn.Module):
|
| 84 |
+
"""CLS token pooling
|
| 85 |
+
NOTE: this is equivalent to ClsPooler above with use_pooler_output=False
|
| 86 |
+
"""
|
| 87 |
+
|
| 88 |
+
def __init__(self):
|
| 89 |
+
super().__init__()
|
| 90 |
+
self.cls_token_position = 0
|
| 91 |
+
|
| 92 |
+
def forward(self, x: BaseModelOutput, attention_mask: TensorType):
|
| 93 |
+
return x.last_hidden_state[:, self.cls_token_position, :]
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
class HFTextEncoder(nn.Module):
|
| 97 |
+
"""HuggingFace model adapter"""
|
| 98 |
+
output_tokens: torch.jit.Final[bool]
|
| 99 |
+
|
| 100 |
+
def __init__(
|
| 101 |
+
self,
|
| 102 |
+
model_name_or_path: str,
|
| 103 |
+
output_dim: int,
|
| 104 |
+
config: PretrainedConfig = None,
|
| 105 |
+
pooler_type: str = None,
|
| 106 |
+
proj_type: str = None,
|
| 107 |
+
pretrained: bool = True,
|
| 108 |
+
output_tokens: bool = False,
|
| 109 |
+
):
|
| 110 |
+
super().__init__()
|
| 111 |
+
self.output_tokens = output_tokens
|
| 112 |
+
self.output_dim = output_dim
|
| 113 |
+
|
| 114 |
+
# TODO: find better way to get this information
|
| 115 |
+
uses_transformer_pooler = (pooler_type == "cls_pooler")
|
| 116 |
+
|
| 117 |
+
if transformers is None:
|
| 118 |
+
raise RuntimeError("Please `pip install transformers` to use pre-trained HuggingFace models")
|
| 119 |
+
if config is None:
|
| 120 |
+
self.config = AutoConfig.from_pretrained(model_name_or_path)
|
| 121 |
+
create_func, model_args = (AutoModel.from_pretrained, model_name_or_path) if pretrained else (
|
| 122 |
+
AutoModel.from_config, self.config)
|
| 123 |
+
# TODO: do all model configs have this attribute? PretrainedConfig does so yes??
|
| 124 |
+
if hasattr(self.config, "is_encoder_decoder") and self.config.is_encoder_decoder:
|
| 125 |
+
self.transformer = create_func(model_args)
|
| 126 |
+
self.transformer = self.transformer.encoder
|
| 127 |
+
else:
|
| 128 |
+
self.transformer = create_func(model_args, add_pooling_layer=uses_transformer_pooler)
|
| 129 |
+
else:
|
| 130 |
+
self.config = config
|
| 131 |
+
self.transformer = AutoModel.from_config(config)
|
| 132 |
+
if pooler_type is None: # get default arch pooler
|
| 133 |
+
pooler_type = (arch_dict[self.config.model_type]["pooler"])
|
| 134 |
+
|
| 135 |
+
# FIXME downstream users of OpenCLIP models use these attr, need to verify valid across all models
|
| 136 |
+
self.vocab_size = getattr(self.config, 'vocab_size', 0)
|
| 137 |
+
self.context_length = getattr(self.config, 'max_position_embeddings', 0)
|
| 138 |
+
|
| 139 |
+
self.pooler = _POOLERS[pooler_type]()
|
| 140 |
+
|
| 141 |
+
d_model = getattr(self.config, arch_dict[self.config.model_type]["config_names"]["width"])
|
| 142 |
+
if (d_model == output_dim) and (proj_type is None): # do we always need a proj?
|
| 143 |
+
self.proj = nn.Identity()
|
| 144 |
+
elif proj_type == 'linear':
|
| 145 |
+
self.proj = nn.Linear(d_model, output_dim, bias=False)
|
| 146 |
+
elif proj_type == 'mlp':
|
| 147 |
+
hidden_size = (d_model + output_dim) // 2
|
| 148 |
+
self.proj = nn.Sequential(
|
| 149 |
+
nn.Linear(d_model, hidden_size, bias=False),
|
| 150 |
+
nn.GELU(),
|
| 151 |
+
nn.Linear(hidden_size, output_dim, bias=False),
|
| 152 |
+
)
|
| 153 |
+
|
| 154 |
+
def forward(self, x: TensorType):
|
| 155 |
+
attn_mask = (x != self.config.pad_token_id).long()
|
| 156 |
+
out = self.transformer(input_ids=x, attention_mask=attn_mask)
|
| 157 |
+
pooled_out = self.pooler(out, attn_mask)
|
| 158 |
+
projected = self.proj(pooled_out)
|
| 159 |
+
|
| 160 |
+
seq_len = out.last_hidden_state.shape[1]
|
| 161 |
+
tokens = (
|
| 162 |
+
out.last_hidden_state[:, torch.arange(seq_len) != self.pooler.cls_token_position, :]
|
| 163 |
+
if type(self.pooler) == ClsPooler
|
| 164 |
+
else out.last_hidden_state
|
| 165 |
+
)
|
| 166 |
+
|
| 167 |
+
if self.output_tokens:
|
| 168 |
+
return projected, tokens
|
| 169 |
+
return projected
|
| 170 |
+
|
| 171 |
+
def lock(self, unlocked_layers: int = 0, freeze_layer_norm: bool = True):
|
| 172 |
+
if not unlocked_layers: # full freezing
|
| 173 |
+
for n, p in self.transformer.named_parameters():
|
| 174 |
+
p.requires_grad = (not freeze_layer_norm) if "LayerNorm" in n.split(".") else False
|
| 175 |
+
return
|
| 176 |
+
|
| 177 |
+
encoder = self.transformer.encoder if hasattr(self.transformer, 'encoder') else self.transformer
|
| 178 |
+
layer_list = getattr(encoder, arch_dict[self.config.model_type]["config_names"]["layer_attr"])
|
| 179 |
+
print(f"Unlocking {unlocked_layers}/{len(layer_list) + 1} layers of hf model")
|
| 180 |
+
embeddings = getattr(
|
| 181 |
+
self.transformer, arch_dict[self.config.model_type]["config_names"]["token_embeddings_attr"])
|
| 182 |
+
modules = [embeddings, *layer_list][:-unlocked_layers]
|
| 183 |
+
# freeze layers
|
| 184 |
+
for module in modules:
|
| 185 |
+
for n, p in module.named_parameters():
|
| 186 |
+
p.requires_grad = (not freeze_layer_norm) if "LayerNorm" in n.split(".") else False
|
| 187 |
+
|
| 188 |
+
@torch.jit.ignore
|
| 189 |
+
def set_grad_checkpointing(self, enable=True):
|
| 190 |
+
self.transformer.gradient_checkpointing_enable()
|
| 191 |
+
|
| 192 |
+
def init_parameters(self):
|
| 193 |
+
pass
|
hlip/open_clip/src/open_clip/loss.py
ADDED
|
@@ -0,0 +1,464 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Optional
|
| 2 |
+
|
| 3 |
+
import torch
|
| 4 |
+
import torch.nn as nn
|
| 5 |
+
from torch.nn import functional as F
|
| 6 |
+
|
| 7 |
+
try:
|
| 8 |
+
import torch.distributed.nn
|
| 9 |
+
from torch import distributed as dist
|
| 10 |
+
|
| 11 |
+
has_distributed = True
|
| 12 |
+
except ImportError:
|
| 13 |
+
has_distributed = False
|
| 14 |
+
|
| 15 |
+
try:
|
| 16 |
+
import horovod.torch as hvd
|
| 17 |
+
except ImportError:
|
| 18 |
+
hvd = None
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def gather_features(
|
| 22 |
+
image_features,
|
| 23 |
+
text_features,
|
| 24 |
+
local_loss=False,
|
| 25 |
+
gather_with_grad=False,
|
| 26 |
+
rank=0,
|
| 27 |
+
world_size=1,
|
| 28 |
+
use_horovod=False
|
| 29 |
+
):
|
| 30 |
+
assert has_distributed, 'torch.distributed did not import correctly, please use a PyTorch version with support.'
|
| 31 |
+
if use_horovod:
|
| 32 |
+
assert hvd is not None, 'Please install horovod'
|
| 33 |
+
if gather_with_grad:
|
| 34 |
+
all_image_features = hvd.allgather(image_features)
|
| 35 |
+
all_text_features = hvd.allgather(text_features)
|
| 36 |
+
else:
|
| 37 |
+
with torch.no_grad():
|
| 38 |
+
all_image_features = hvd.allgather(image_features)
|
| 39 |
+
all_text_features = hvd.allgather(text_features)
|
| 40 |
+
if not local_loss:
|
| 41 |
+
# ensure grads for local rank when all_* features don't have a gradient
|
| 42 |
+
gathered_image_features = list(all_image_features.chunk(world_size, dim=0))
|
| 43 |
+
gathered_text_features = list(all_text_features.chunk(world_size, dim=0))
|
| 44 |
+
gathered_image_features[rank] = image_features
|
| 45 |
+
gathered_text_features[rank] = text_features
|
| 46 |
+
all_image_features = torch.cat(gathered_image_features, dim=0)
|
| 47 |
+
all_text_features = torch.cat(gathered_text_features, dim=0)
|
| 48 |
+
else:
|
| 49 |
+
# We gather tensors from all gpus
|
| 50 |
+
if gather_with_grad:
|
| 51 |
+
all_image_features = torch.cat(torch.distributed.nn.all_gather(image_features), dim=0)
|
| 52 |
+
all_text_features = torch.cat(torch.distributed.nn.all_gather(text_features), dim=0)
|
| 53 |
+
else:
|
| 54 |
+
gathered_image_features = [torch.zeros_like(image_features) for _ in range(world_size)]
|
| 55 |
+
gathered_text_features = [torch.zeros_like(text_features) for _ in range(world_size)]
|
| 56 |
+
dist.all_gather(gathered_image_features, image_features)
|
| 57 |
+
dist.all_gather(gathered_text_features, text_features)
|
| 58 |
+
if not local_loss:
|
| 59 |
+
# ensure grads for local rank when all_* features don't have a gradient
|
| 60 |
+
gathered_image_features[rank] = image_features
|
| 61 |
+
gathered_text_features[rank] = text_features
|
| 62 |
+
all_image_features = torch.cat(gathered_image_features, dim=0)
|
| 63 |
+
all_text_features = torch.cat(gathered_text_features, dim=0)
|
| 64 |
+
|
| 65 |
+
return all_image_features, all_text_features
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
class ClipLoss(nn.Module):
|
| 69 |
+
|
| 70 |
+
def __init__(
|
| 71 |
+
self,
|
| 72 |
+
local_loss=False,
|
| 73 |
+
gather_with_grad=False,
|
| 74 |
+
cache_labels=False,
|
| 75 |
+
rank=0,
|
| 76 |
+
world_size=1,
|
| 77 |
+
use_horovod=False,
|
| 78 |
+
):
|
| 79 |
+
super().__init__()
|
| 80 |
+
self.local_loss = local_loss
|
| 81 |
+
self.gather_with_grad = gather_with_grad
|
| 82 |
+
self.cache_labels = cache_labels
|
| 83 |
+
self.rank = rank
|
| 84 |
+
self.world_size = world_size
|
| 85 |
+
self.use_horovod = use_horovod
|
| 86 |
+
|
| 87 |
+
# cache state
|
| 88 |
+
self.prev_num_logits = 0
|
| 89 |
+
self.labels = {}
|
| 90 |
+
|
| 91 |
+
def get_ground_truth(self, device, num_logits) -> torch.Tensor:
|
| 92 |
+
# calculated ground-truth and cache if enabled
|
| 93 |
+
if self.prev_num_logits != num_logits or device not in self.labels:
|
| 94 |
+
labels = torch.arange(num_logits, device=device, dtype=torch.long)
|
| 95 |
+
if self.world_size > 1 and self.local_loss:
|
| 96 |
+
labels = labels + num_logits * self.rank
|
| 97 |
+
if self.cache_labels:
|
| 98 |
+
self.labels[device] = labels
|
| 99 |
+
self.prev_num_logits = num_logits
|
| 100 |
+
else:
|
| 101 |
+
labels = self.labels[device]
|
| 102 |
+
return labels
|
| 103 |
+
|
| 104 |
+
def get_logits(self, image_features, text_features, logit_scale, logit_bias=None):
|
| 105 |
+
if self.world_size > 1:
|
| 106 |
+
all_image_features, all_text_features = gather_features(
|
| 107 |
+
image_features,
|
| 108 |
+
text_features,
|
| 109 |
+
local_loss=self.local_loss,
|
| 110 |
+
gather_with_grad=self.gather_with_grad,
|
| 111 |
+
rank=self.rank,
|
| 112 |
+
world_size=self.world_size,
|
| 113 |
+
use_horovod=self.use_horovod,
|
| 114 |
+
)
|
| 115 |
+
|
| 116 |
+
if self.local_loss:
|
| 117 |
+
logits_per_image = logit_scale * image_features @ all_text_features.T
|
| 118 |
+
logits_per_text = logit_scale * text_features @ all_image_features.T
|
| 119 |
+
else:
|
| 120 |
+
logits_per_image = logit_scale * all_image_features @ all_text_features.T
|
| 121 |
+
logits_per_text = logits_per_image.T
|
| 122 |
+
else:
|
| 123 |
+
logits_per_image = logit_scale * image_features @ text_features.T
|
| 124 |
+
logits_per_text = logit_scale * text_features @ image_features.T
|
| 125 |
+
|
| 126 |
+
if logit_bias is not None:
|
| 127 |
+
logits_per_image += logit_bias
|
| 128 |
+
logits_per_text += logit_bias
|
| 129 |
+
|
| 130 |
+
return logits_per_image, logits_per_text
|
| 131 |
+
|
| 132 |
+
def forward(
|
| 133 |
+
self,
|
| 134 |
+
image_features,
|
| 135 |
+
text_features,
|
| 136 |
+
logit_scale,
|
| 137 |
+
logit_bias=None,
|
| 138 |
+
output_dict=False,
|
| 139 |
+
):
|
| 140 |
+
device = image_features.device
|
| 141 |
+
logits_per_image, logits_per_text = self.get_logits(
|
| 142 |
+
image_features,
|
| 143 |
+
text_features,
|
| 144 |
+
logit_scale,
|
| 145 |
+
logit_bias=logit_bias,
|
| 146 |
+
)
|
| 147 |
+
|
| 148 |
+
labels = self.get_ground_truth(device, logits_per_image.shape[0])
|
| 149 |
+
|
| 150 |
+
total_loss = (
|
| 151 |
+
F.cross_entropy(logits_per_image, labels) +
|
| 152 |
+
F.cross_entropy(logits_per_text, labels)
|
| 153 |
+
) / 2
|
| 154 |
+
|
| 155 |
+
return {"contrastive_loss": total_loss} if output_dict else total_loss
|
| 156 |
+
|
| 157 |
+
|
| 158 |
+
class CoCaLoss(ClipLoss):
|
| 159 |
+
def __init__(
|
| 160 |
+
self,
|
| 161 |
+
caption_loss_weight,
|
| 162 |
+
clip_loss_weight,
|
| 163 |
+
pad_id=0, # pad_token for open_clip custom tokenizer
|
| 164 |
+
local_loss=False,
|
| 165 |
+
gather_with_grad=False,
|
| 166 |
+
cache_labels=False,
|
| 167 |
+
rank=0,
|
| 168 |
+
world_size=1,
|
| 169 |
+
use_horovod=False,
|
| 170 |
+
):
|
| 171 |
+
super().__init__(
|
| 172 |
+
local_loss=local_loss,
|
| 173 |
+
gather_with_grad=gather_with_grad,
|
| 174 |
+
cache_labels=cache_labels,
|
| 175 |
+
rank=rank,
|
| 176 |
+
world_size=world_size,
|
| 177 |
+
use_horovod=use_horovod
|
| 178 |
+
)
|
| 179 |
+
|
| 180 |
+
self.clip_loss_weight = clip_loss_weight
|
| 181 |
+
self.caption_loss_weight = caption_loss_weight
|
| 182 |
+
self.caption_loss = nn.CrossEntropyLoss(ignore_index=pad_id)
|
| 183 |
+
|
| 184 |
+
def forward(self, image_features, text_features, logits, labels, logit_scale, output_dict=False):
|
| 185 |
+
if self.clip_loss_weight:
|
| 186 |
+
clip_loss = super().forward(image_features, text_features, logit_scale)
|
| 187 |
+
clip_loss = self.clip_loss_weight * clip_loss
|
| 188 |
+
else:
|
| 189 |
+
clip_loss = torch.tensor(0, device=logits.device)
|
| 190 |
+
|
| 191 |
+
caption_loss = self.caption_loss(
|
| 192 |
+
logits.permute(0, 2, 1),
|
| 193 |
+
labels,
|
| 194 |
+
)
|
| 195 |
+
caption_loss = caption_loss * self.caption_loss_weight
|
| 196 |
+
|
| 197 |
+
if output_dict:
|
| 198 |
+
return {"contrastive_loss": clip_loss, "caption_loss": caption_loss}
|
| 199 |
+
|
| 200 |
+
return clip_loss, caption_loss
|
| 201 |
+
|
| 202 |
+
|
| 203 |
+
class DistillClipLoss(ClipLoss):
|
| 204 |
+
|
| 205 |
+
def dist_loss(self, teacher_logits, student_logits):
|
| 206 |
+
return -(teacher_logits.softmax(dim=1) * student_logits.log_softmax(dim=1)).sum(dim=1).mean(dim=0)
|
| 207 |
+
|
| 208 |
+
def forward(
|
| 209 |
+
self,
|
| 210 |
+
image_features,
|
| 211 |
+
text_features,
|
| 212 |
+
logit_scale,
|
| 213 |
+
dist_image_features,
|
| 214 |
+
dist_text_features,
|
| 215 |
+
dist_logit_scale,
|
| 216 |
+
output_dict=False,
|
| 217 |
+
):
|
| 218 |
+
logits_per_image, logits_per_text = \
|
| 219 |
+
self.get_logits(image_features, text_features, logit_scale)
|
| 220 |
+
|
| 221 |
+
dist_logits_per_image, dist_logits_per_text = \
|
| 222 |
+
self.get_logits(dist_image_features, dist_text_features, dist_logit_scale)
|
| 223 |
+
|
| 224 |
+
labels = self.get_ground_truth(image_features.device, logits_per_image.shape[0])
|
| 225 |
+
|
| 226 |
+
contrastive_loss = (
|
| 227 |
+
F.cross_entropy(logits_per_image, labels) +
|
| 228 |
+
F.cross_entropy(logits_per_text, labels)
|
| 229 |
+
) / 2
|
| 230 |
+
|
| 231 |
+
distill_loss = (
|
| 232 |
+
self.dist_loss(dist_logits_per_image, logits_per_image) +
|
| 233 |
+
self.dist_loss(dist_logits_per_text, logits_per_text)
|
| 234 |
+
) / 2
|
| 235 |
+
|
| 236 |
+
if output_dict:
|
| 237 |
+
return {"contrastive_loss": contrastive_loss, "distill_loss": distill_loss}
|
| 238 |
+
|
| 239 |
+
return contrastive_loss, distill_loss
|
| 240 |
+
|
| 241 |
+
|
| 242 |
+
def neighbour_exchange(from_rank, to_rank, tensor, group=None):
|
| 243 |
+
tensor_recv = torch.zeros_like(tensor)
|
| 244 |
+
send_op = torch.distributed.P2POp(
|
| 245 |
+
torch.distributed.isend,
|
| 246 |
+
tensor,
|
| 247 |
+
to_rank,
|
| 248 |
+
group=group,
|
| 249 |
+
)
|
| 250 |
+
recv_op = torch.distributed.P2POp(
|
| 251 |
+
torch.distributed.irecv,
|
| 252 |
+
tensor_recv,
|
| 253 |
+
from_rank,
|
| 254 |
+
group=group,
|
| 255 |
+
)
|
| 256 |
+
reqs = torch.distributed.batch_isend_irecv([send_op, recv_op])
|
| 257 |
+
for req in reqs:
|
| 258 |
+
req.wait()
|
| 259 |
+
return tensor_recv
|
| 260 |
+
|
| 261 |
+
|
| 262 |
+
def neighbour_exchange_bidir(left_rank, right_rank, tensor_to_left, tensor_to_right, group=None):
|
| 263 |
+
tensor_from_left = torch.zeros_like(tensor_to_right)
|
| 264 |
+
tensor_from_right = torch.zeros_like(tensor_to_left)
|
| 265 |
+
send_op_left = torch.distributed.P2POp(
|
| 266 |
+
torch.distributed.isend,
|
| 267 |
+
tensor_to_left,
|
| 268 |
+
left_rank,
|
| 269 |
+
group=group,
|
| 270 |
+
)
|
| 271 |
+
send_op_right = torch.distributed.P2POp(
|
| 272 |
+
torch.distributed.isend,
|
| 273 |
+
tensor_to_right,
|
| 274 |
+
right_rank,
|
| 275 |
+
group=group,
|
| 276 |
+
)
|
| 277 |
+
recv_op_left = torch.distributed.P2POp(
|
| 278 |
+
torch.distributed.irecv,
|
| 279 |
+
tensor_from_left,
|
| 280 |
+
left_rank,
|
| 281 |
+
group=group,
|
| 282 |
+
)
|
| 283 |
+
recv_op_right = torch.distributed.P2POp(
|
| 284 |
+
torch.distributed.irecv,
|
| 285 |
+
tensor_from_right,
|
| 286 |
+
right_rank,
|
| 287 |
+
group=group,
|
| 288 |
+
)
|
| 289 |
+
reqs = torch.distributed.batch_isend_irecv([send_op_right, send_op_left, recv_op_right, recv_op_left])
|
| 290 |
+
for req in reqs:
|
| 291 |
+
req.wait()
|
| 292 |
+
return tensor_from_right, tensor_from_left
|
| 293 |
+
|
| 294 |
+
|
| 295 |
+
class NeighbourExchange(torch.autograd.Function):
|
| 296 |
+
@staticmethod
|
| 297 |
+
def forward(ctx, from_rank, to_rank, group, tensor):
|
| 298 |
+
ctx.group = group
|
| 299 |
+
ctx.from_rank = from_rank
|
| 300 |
+
ctx.to_rank = to_rank
|
| 301 |
+
return neighbour_exchange(from_rank, to_rank, tensor, group=group)
|
| 302 |
+
|
| 303 |
+
@staticmethod
|
| 304 |
+
def backward(ctx, grad_output):
|
| 305 |
+
return (None, None, None) + (NeighbourExchange.apply(ctx.to_rank, ctx.from_rank, ctx.group, grad_output),)
|
| 306 |
+
|
| 307 |
+
|
| 308 |
+
def neighbour_exchange_with_grad(from_rank, to_rank, tensor, group=None):
|
| 309 |
+
return NeighbourExchange.apply(from_rank, to_rank, group, tensor)
|
| 310 |
+
|
| 311 |
+
|
| 312 |
+
class NeighbourExchangeBidir(torch.autograd.Function):
|
| 313 |
+
@staticmethod
|
| 314 |
+
def forward(ctx, left_rank, right_rank, group, tensor_to_left, tensor_to_right):
|
| 315 |
+
ctx.group = group
|
| 316 |
+
ctx.left_rank = left_rank
|
| 317 |
+
ctx.right_rank = right_rank
|
| 318 |
+
return neighbour_exchange_bidir(left_rank, right_rank, tensor_to_left, tensor_to_right, group=group)
|
| 319 |
+
|
| 320 |
+
@staticmethod
|
| 321 |
+
def backward(ctx, *grad_outputs):
|
| 322 |
+
return (None, None, None) + \
|
| 323 |
+
NeighbourExchangeBidir.apply(ctx.right_rank, ctx.left_rank, ctx.group, *grad_outputs)
|
| 324 |
+
|
| 325 |
+
|
| 326 |
+
def neighbour_exchange_bidir_with_grad(left_rank, right_rank, tensor_to_left, tensor_to_right, group=None):
|
| 327 |
+
return NeighbourExchangeBidir.apply(left_rank, right_rank, group, tensor_to_left, tensor_to_right)
|
| 328 |
+
|
| 329 |
+
|
| 330 |
+
class SigLipLoss(nn.Module):
|
| 331 |
+
""" Sigmoid Loss for Language Image Pre-Training (SigLIP) - https://arxiv.org/abs/2303.15343
|
| 332 |
+
|
| 333 |
+
@article{zhai2023sigmoid,
|
| 334 |
+
title={Sigmoid loss for language image pre-training},
|
| 335 |
+
author={Zhai, Xiaohua and Mustafa, Basil and Kolesnikov, Alexander and Beyer, Lucas},
|
| 336 |
+
journal={arXiv preprint arXiv:2303.15343},
|
| 337 |
+
year={2023}
|
| 338 |
+
}
|
| 339 |
+
"""
|
| 340 |
+
def __init__(
|
| 341 |
+
self,
|
| 342 |
+
cache_labels: bool = False,
|
| 343 |
+
rank: int = 0,
|
| 344 |
+
world_size: int = 1,
|
| 345 |
+
dist_impl: Optional[str] = None,
|
| 346 |
+
):
|
| 347 |
+
super().__init__()
|
| 348 |
+
self.cache_labels = cache_labels
|
| 349 |
+
self.rank = rank
|
| 350 |
+
self.world_size = world_size
|
| 351 |
+
self.dist_impl = dist_impl or 'bidir' # default to bidir exchange for now, this will likely change
|
| 352 |
+
assert self.dist_impl in ('bidir', 'shift', 'reduce', 'gather')
|
| 353 |
+
|
| 354 |
+
# cache state FIXME cache not currently used, worthwhile?
|
| 355 |
+
self.prev_num_logits = 0
|
| 356 |
+
self.labels = {}
|
| 357 |
+
|
| 358 |
+
def get_ground_truth(self, device, dtype, num_logits, negative_only=False) -> torch.Tensor:
|
| 359 |
+
labels = -torch.ones((num_logits, num_logits), device=device, dtype=dtype)
|
| 360 |
+
if not negative_only:
|
| 361 |
+
labels = 2 * torch.eye(num_logits, device=device, dtype=dtype) + labels
|
| 362 |
+
return labels
|
| 363 |
+
|
| 364 |
+
def get_logits(self, image_features, text_features, logit_scale, logit_bias=None):
|
| 365 |
+
logits = logit_scale * image_features @ text_features.T
|
| 366 |
+
if logit_bias is not None:
|
| 367 |
+
logits += logit_bias
|
| 368 |
+
return logits
|
| 369 |
+
|
| 370 |
+
def _loss(self, image_features, text_features, logit_scale, logit_bias=None, negative_only=False):
|
| 371 |
+
logits = self.get_logits(image_features, text_features, logit_scale, logit_bias)
|
| 372 |
+
labels = self.get_ground_truth(
|
| 373 |
+
image_features.device,
|
| 374 |
+
image_features.dtype,
|
| 375 |
+
image_features.shape[0],
|
| 376 |
+
negative_only=negative_only,
|
| 377 |
+
)
|
| 378 |
+
loss = -F.logsigmoid(labels * logits).sum() / image_features.shape[0]
|
| 379 |
+
return loss
|
| 380 |
+
|
| 381 |
+
def forward(self, image_features, text_features, logit_scale, logit_bias, output_dict=False):
|
| 382 |
+
loss = self._loss(image_features, text_features, logit_scale, logit_bias)
|
| 383 |
+
|
| 384 |
+
if self.world_size > 1:
|
| 385 |
+
if self.dist_impl == 'bidir':
|
| 386 |
+
right_rank = (self.rank + 1) % self.world_size
|
| 387 |
+
left_rank = (self.rank - 1 + self.world_size) % self.world_size
|
| 388 |
+
text_features_to_right = text_features_to_left = text_features
|
| 389 |
+
num_bidir, remainder = divmod(self.world_size - 1, 2)
|
| 390 |
+
for i in range(num_bidir):
|
| 391 |
+
text_features_recv = neighbour_exchange_bidir_with_grad(
|
| 392 |
+
left_rank,
|
| 393 |
+
right_rank,
|
| 394 |
+
text_features_to_left,
|
| 395 |
+
text_features_to_right,
|
| 396 |
+
)
|
| 397 |
+
for f in text_features_recv:
|
| 398 |
+
loss += self._loss(
|
| 399 |
+
image_features,
|
| 400 |
+
f,
|
| 401 |
+
logit_scale,
|
| 402 |
+
logit_bias,
|
| 403 |
+
negative_only=True,
|
| 404 |
+
)
|
| 405 |
+
text_features_to_left, text_features_to_right = text_features_recv
|
| 406 |
+
|
| 407 |
+
if remainder:
|
| 408 |
+
text_features_recv = neighbour_exchange_with_grad(
|
| 409 |
+
left_rank,
|
| 410 |
+
right_rank,
|
| 411 |
+
text_features_to_right
|
| 412 |
+
)
|
| 413 |
+
loss += self._loss(
|
| 414 |
+
image_features,
|
| 415 |
+
text_features_recv,
|
| 416 |
+
logit_scale,
|
| 417 |
+
logit_bias,
|
| 418 |
+
negative_only=True,
|
| 419 |
+
)
|
| 420 |
+
elif self.dist_impl == "shift":
|
| 421 |
+
right_rank = (self.rank + 1) % self.world_size
|
| 422 |
+
left_rank = (self.rank - 1 + self.world_size) % self.world_size
|
| 423 |
+
text_features_to_right = text_features
|
| 424 |
+
for i in range(self.world_size - 1):
|
| 425 |
+
text_features_from_left = neighbour_exchange_with_grad(
|
| 426 |
+
left_rank,
|
| 427 |
+
right_rank,
|
| 428 |
+
text_features_to_right,
|
| 429 |
+
)
|
| 430 |
+
loss += self._loss(
|
| 431 |
+
image_features,
|
| 432 |
+
text_features_from_left,
|
| 433 |
+
logit_scale,
|
| 434 |
+
logit_bias,
|
| 435 |
+
negative_only=True,
|
| 436 |
+
)
|
| 437 |
+
text_features_to_right = text_features_from_left
|
| 438 |
+
elif self.dist_impl == "reduce":
|
| 439 |
+
for i in range(self.world_size):
|
| 440 |
+
text_from_other = torch.distributed.nn.all_reduce(
|
| 441 |
+
text_features * (self.rank == i),
|
| 442 |
+
torch.distributed.ReduceOp.SUM,
|
| 443 |
+
)
|
| 444 |
+
loss += float(i != self.rank) * self._loss(
|
| 445 |
+
image_features,
|
| 446 |
+
text_from_other,
|
| 447 |
+
logit_scale,
|
| 448 |
+
logit_bias,
|
| 449 |
+
negative_only=True,
|
| 450 |
+
)
|
| 451 |
+
elif self.dist_impl == "gather":
|
| 452 |
+
all_text = torch.distributed.nn.all_gather(text_features)
|
| 453 |
+
for i in range(self.world_size):
|
| 454 |
+
loss += float(i != self.rank) * self._loss(
|
| 455 |
+
image_features,
|
| 456 |
+
all_text[i],
|
| 457 |
+
logit_scale,
|
| 458 |
+
logit_bias,
|
| 459 |
+
negative_only=True,
|
| 460 |
+
)
|
| 461 |
+
else:
|
| 462 |
+
assert False
|
| 463 |
+
|
| 464 |
+
return {"contrastive_loss": loss} if output_dict else loss
|
hlip/open_clip/src/open_clip/model.py
ADDED
|
@@ -0,0 +1,892 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
""" CLIP Model
|
| 2 |
+
|
| 3 |
+
Adapted from https://github.com/openai/CLIP. Originally MIT License, Copyright (c) 2021 OpenAI.
|
| 4 |
+
"""
|
| 5 |
+
import copy
|
| 6 |
+
import logging
|
| 7 |
+
import math
|
| 8 |
+
from dataclasses import dataclass
|
| 9 |
+
from typing import Any, Dict, List, Optional, Tuple, Union
|
| 10 |
+
|
| 11 |
+
import numpy as np
|
| 12 |
+
import torch
|
| 13 |
+
import torch.nn.functional as F
|
| 14 |
+
from torch import nn
|
| 15 |
+
from torch.utils.checkpoint import checkpoint
|
| 16 |
+
from functools import partial
|
| 17 |
+
|
| 18 |
+
from .hf_model import HFTextEncoder
|
| 19 |
+
from .modified_resnet import ModifiedResNet
|
| 20 |
+
from .timm_model import TimmModel
|
| 21 |
+
from .transformer import (
|
| 22 |
+
LayerNormFp32,
|
| 23 |
+
LayerNorm,
|
| 24 |
+
QuickGELU,
|
| 25 |
+
Attention,
|
| 26 |
+
VisionTransformer,
|
| 27 |
+
TextTransformer,
|
| 28 |
+
text_global_pool,
|
| 29 |
+
lock_text_tower,
|
| 30 |
+
)
|
| 31 |
+
from .utils import to_2tuple
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
@dataclass
|
| 35 |
+
class CLIPVisionCfg:
|
| 36 |
+
layers: Union[Tuple[int, int, int, int], int] = 12
|
| 37 |
+
width: int = 768
|
| 38 |
+
head_width: int = 64
|
| 39 |
+
mlp_ratio: float = 4.0
|
| 40 |
+
patch_size: int = 16
|
| 41 |
+
image_size: Union[Tuple[int, int], int] = 224
|
| 42 |
+
|
| 43 |
+
ls_init_value: Optional[float] = None # layer scale initial value
|
| 44 |
+
patch_dropout: float = 0. # what fraction of patches to dropout during training (0 would mean disabled and no patches dropped) - 0.5 to 0.75 recommended in the paper for optimal results
|
| 45 |
+
attentional_pool: bool = False # whether to use attentional pooler in the last embedding layer (overrides pool_type)
|
| 46 |
+
attn_pooler_queries: int = 256 # n_queries for attentional pooler
|
| 47 |
+
attn_pooler_heads: int = 8 # n heads for attentional_pooling
|
| 48 |
+
no_ln_pre: bool = False # disable pre transformer LayerNorm
|
| 49 |
+
pos_embed_type: str = 'learnable'
|
| 50 |
+
final_ln_after_pool: bool = False # apply final LayerNorm after pooling
|
| 51 |
+
pool_type: str = 'tok'
|
| 52 |
+
output_tokens: bool = False
|
| 53 |
+
act_kwargs: Optional[dict] = None
|
| 54 |
+
norm_kwargs: Optional[dict] = None
|
| 55 |
+
|
| 56 |
+
# Custom attention block settings
|
| 57 |
+
block_type: Optional[str] = None # attention block type ('default', 'custom'), auto-selects 'custom' if any below features enabled
|
| 58 |
+
qk_norm: bool = False # apply layer norm to q and k in attention
|
| 59 |
+
scaled_cosine_attn: bool = False # use scaled cosine attention
|
| 60 |
+
scale_heads: bool = False # learnable head-specific scale applied to attention logits
|
| 61 |
+
scale_attn_inner: bool = False # apply layer norm on attention context, before output projection
|
| 62 |
+
scale_attn: bool = False # apply layer norm after full attention block
|
| 63 |
+
scale_fc: bool = False # apply layer norm in MLP block
|
| 64 |
+
|
| 65 |
+
timm_model_name: Optional[str] = None # a valid model name overrides layers, width, patch_size
|
| 66 |
+
timm_model_pretrained: bool = False # use (imagenet) pretrained weights for named model
|
| 67 |
+
timm_pool: str = 'avg' # feature pooling for timm model ('abs_attn', 'rot_attn', 'avg', '')
|
| 68 |
+
timm_proj: str = 'linear' # linear projection for timm model output ('linear', 'mlp', '')
|
| 69 |
+
timm_proj_bias: bool = False # enable bias final projection
|
| 70 |
+
timm_drop: float = 0. # head dropout
|
| 71 |
+
timm_drop_path: Optional[float] = None # backbone stochastic depth
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
@dataclass
|
| 75 |
+
class CLIPTextCfg:
|
| 76 |
+
context_length: int = 77
|
| 77 |
+
vocab_size: int = 49408
|
| 78 |
+
hf_tokenizer_name: Optional[str] = None
|
| 79 |
+
tokenizer_mode: Optional[str] = None
|
| 80 |
+
tokenizer_kwargs: Optional[dict] = None
|
| 81 |
+
|
| 82 |
+
width: int = 512
|
| 83 |
+
heads: int = 8
|
| 84 |
+
layers: int = 12
|
| 85 |
+
mlp_ratio: float = 4.0
|
| 86 |
+
ls_init_value: Optional[float] = None # layer scale initial value
|
| 87 |
+
embed_cls: bool = False
|
| 88 |
+
pad_id: int = 0
|
| 89 |
+
eos_id: int = 2 # only used for when pool_type == 'eos', must match tokenizer eos
|
| 90 |
+
no_causal_mask: bool = False # disable causal masking
|
| 91 |
+
final_ln_after_pool: bool = False # apply final LayerNorm after pooling
|
| 92 |
+
pool_type: str = 'argmax'
|
| 93 |
+
proj_bias: bool = False
|
| 94 |
+
proj_type: str = 'linear' # control final text projection, 'none' forces no projection
|
| 95 |
+
output_tokens: bool = False
|
| 96 |
+
act_kwargs: dict = None
|
| 97 |
+
norm_kwargs: dict = None
|
| 98 |
+
|
| 99 |
+
# Custom attention block settings
|
| 100 |
+
block_type: Optional[str] = None # attention block type ('default', 'custom'), auto-selects 'custom' if any custom features enabled
|
| 101 |
+
qk_norm: bool = False # apply layer norm to q and k in attention
|
| 102 |
+
scaled_cosine_attn: bool = False # use scaled cosine attention
|
| 103 |
+
scale_heads: bool = False # learnable head-specific scale applied to attention logits
|
| 104 |
+
scale_attn_inner: bool = False # apply layer norm on attention context, before output projection
|
| 105 |
+
scale_attn: bool = False # apply layer norm after full attention block
|
| 106 |
+
scale_fc: bool = False # apply layer norm in MLP block
|
| 107 |
+
|
| 108 |
+
# HuggingFace specific text tower config
|
| 109 |
+
hf_model_name: Optional[str] = None
|
| 110 |
+
hf_model_pretrained: bool = True
|
| 111 |
+
hf_proj_type: str = 'mlp'
|
| 112 |
+
hf_pooler_type: str = 'mean_pooler' # attentional pooling for HF models
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
def get_cast_dtype(precision: str):
|
| 116 |
+
cast_dtype = None
|
| 117 |
+
if precision == 'bf16':
|
| 118 |
+
cast_dtype = torch.bfloat16
|
| 119 |
+
elif precision == 'fp16':
|
| 120 |
+
cast_dtype = torch.float16
|
| 121 |
+
return cast_dtype
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
def get_input_dtype(precision: str):
|
| 125 |
+
input_dtype = None
|
| 126 |
+
if precision in ('bf16', 'pure_bf16'):
|
| 127 |
+
input_dtype = torch.bfloat16
|
| 128 |
+
elif precision in ('fp16', 'pure_fp16'):
|
| 129 |
+
input_dtype = torch.float16
|
| 130 |
+
return input_dtype
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
def _build_vision_tower(
|
| 134 |
+
embed_dim: int,
|
| 135 |
+
vision_cfg: CLIPVisionCfg,
|
| 136 |
+
quick_gelu: bool = False,
|
| 137 |
+
cast_dtype: Optional[torch.dtype] = None
|
| 138 |
+
):
|
| 139 |
+
if isinstance(vision_cfg, dict):
|
| 140 |
+
vision_cfg = CLIPVisionCfg(**vision_cfg)
|
| 141 |
+
|
| 142 |
+
# OpenAI models are pretrained w/ QuickGELU but native nn.GELU is both faster and more
|
| 143 |
+
# memory efficient in recent PyTorch releases (>= 1.10).
|
| 144 |
+
# NOTE: timm models always use native GELU regardless of quick_gelu flag.
|
| 145 |
+
act_layer = QuickGELU if quick_gelu else nn.GELU
|
| 146 |
+
|
| 147 |
+
if vision_cfg.timm_model_name:
|
| 148 |
+
visual = TimmModel(
|
| 149 |
+
vision_cfg.timm_model_name,
|
| 150 |
+
pretrained=vision_cfg.timm_model_pretrained,
|
| 151 |
+
pool=vision_cfg.timm_pool,
|
| 152 |
+
proj=vision_cfg.timm_proj,
|
| 153 |
+
proj_bias=vision_cfg.timm_proj_bias,
|
| 154 |
+
drop=vision_cfg.timm_drop,
|
| 155 |
+
drop_path=vision_cfg.timm_drop_path,
|
| 156 |
+
patch_drop=vision_cfg.patch_dropout if vision_cfg.patch_dropout > 0 else None,
|
| 157 |
+
embed_dim=embed_dim,
|
| 158 |
+
image_size=vision_cfg.image_size,
|
| 159 |
+
)
|
| 160 |
+
elif isinstance(vision_cfg.layers, (tuple, list)):
|
| 161 |
+
vision_heads = vision_cfg.width * 32 // vision_cfg.head_width
|
| 162 |
+
visual = ModifiedResNet(
|
| 163 |
+
layers=vision_cfg.layers,
|
| 164 |
+
output_dim=embed_dim,
|
| 165 |
+
heads=vision_heads,
|
| 166 |
+
image_size=vision_cfg.image_size,
|
| 167 |
+
width=vision_cfg.width,
|
| 168 |
+
)
|
| 169 |
+
else:
|
| 170 |
+
vision_heads = vision_cfg.width // vision_cfg.head_width
|
| 171 |
+
norm_layer = LayerNormFp32 if cast_dtype in (torch.float16, torch.bfloat16) else LayerNorm
|
| 172 |
+
if vision_cfg.norm_kwargs:
|
| 173 |
+
norm_layer = partial(norm_layer, **vision_cfg.norm_kwargs)
|
| 174 |
+
if vision_cfg.act_kwargs is not None:
|
| 175 |
+
act_layer = partial(act_layer, **vision_cfg.act_kwargs)
|
| 176 |
+
|
| 177 |
+
visual = VisionTransformer(
|
| 178 |
+
image_size=vision_cfg.image_size,
|
| 179 |
+
patch_size=vision_cfg.patch_size,
|
| 180 |
+
width=vision_cfg.width,
|
| 181 |
+
layers=vision_cfg.layers,
|
| 182 |
+
heads=vision_heads,
|
| 183 |
+
mlp_ratio=vision_cfg.mlp_ratio,
|
| 184 |
+
ls_init_value=vision_cfg.ls_init_value,
|
| 185 |
+
patch_dropout=vision_cfg.patch_dropout,
|
| 186 |
+
attentional_pool=vision_cfg.attentional_pool,
|
| 187 |
+
attn_pooler_queries=vision_cfg.attn_pooler_queries,
|
| 188 |
+
attn_pooler_heads=vision_cfg.attn_pooler_heads,
|
| 189 |
+
pos_embed_type=vision_cfg.pos_embed_type,
|
| 190 |
+
no_ln_pre=vision_cfg.no_ln_pre,
|
| 191 |
+
final_ln_after_pool=vision_cfg.final_ln_after_pool,
|
| 192 |
+
pool_type=vision_cfg.pool_type,
|
| 193 |
+
output_tokens=vision_cfg.output_tokens,
|
| 194 |
+
output_dim=embed_dim,
|
| 195 |
+
act_layer=act_layer,
|
| 196 |
+
norm_layer=norm_layer,
|
| 197 |
+
block_type=vision_cfg.block_type,
|
| 198 |
+
qk_norm=vision_cfg.qk_norm,
|
| 199 |
+
scaled_cosine_attn=vision_cfg.scaled_cosine_attn,
|
| 200 |
+
scale_heads=vision_cfg.scale_heads,
|
| 201 |
+
scale_attn_inner=vision_cfg.scale_attn_inner,
|
| 202 |
+
scale_attn=vision_cfg.scale_attn,
|
| 203 |
+
scale_fc=vision_cfg.scale_fc,
|
| 204 |
+
)
|
| 205 |
+
|
| 206 |
+
return visual
|
| 207 |
+
|
| 208 |
+
|
| 209 |
+
def _build_text_tower(
|
| 210 |
+
embed_dim: int,
|
| 211 |
+
text_cfg: CLIPTextCfg,
|
| 212 |
+
quick_gelu: bool = False,
|
| 213 |
+
cast_dtype: Optional[torch.dtype] = None,
|
| 214 |
+
):
|
| 215 |
+
if isinstance(text_cfg, dict):
|
| 216 |
+
text_cfg = CLIPTextCfg(**text_cfg)
|
| 217 |
+
|
| 218 |
+
if text_cfg.hf_model_name:
|
| 219 |
+
text = HFTextEncoder(
|
| 220 |
+
text_cfg.hf_model_name,
|
| 221 |
+
output_dim=embed_dim,
|
| 222 |
+
proj_type=text_cfg.hf_proj_type,
|
| 223 |
+
pooler_type=text_cfg.hf_pooler_type,
|
| 224 |
+
pretrained=text_cfg.hf_model_pretrained,
|
| 225 |
+
output_tokens=text_cfg.output_tokens,
|
| 226 |
+
)
|
| 227 |
+
else:
|
| 228 |
+
act_layer = QuickGELU if quick_gelu else nn.GELU
|
| 229 |
+
norm_layer = LayerNormFp32 if cast_dtype in (torch.float16, torch.bfloat16) else LayerNorm
|
| 230 |
+
if text_cfg.norm_kwargs:
|
| 231 |
+
norm_layer = partial(norm_layer, **text_cfg.norm_kwargs)
|
| 232 |
+
if text_cfg.act_kwargs is not None:
|
| 233 |
+
act_layer = partial(act_layer, **text_cfg.act_kwargs)
|
| 234 |
+
|
| 235 |
+
text = TextTransformer(
|
| 236 |
+
context_length=text_cfg.context_length,
|
| 237 |
+
vocab_size=text_cfg.vocab_size,
|
| 238 |
+
width=text_cfg.width,
|
| 239 |
+
heads=text_cfg.heads,
|
| 240 |
+
layers=text_cfg.layers,
|
| 241 |
+
mlp_ratio=text_cfg.mlp_ratio,
|
| 242 |
+
ls_init_value=text_cfg.ls_init_value,
|
| 243 |
+
output_dim=embed_dim,
|
| 244 |
+
embed_cls=text_cfg.embed_cls,
|
| 245 |
+
no_causal_mask=text_cfg.no_causal_mask,
|
| 246 |
+
pad_id=text_cfg.pad_id,
|
| 247 |
+
eos_id=text_cfg.eos_id,
|
| 248 |
+
pool_type=text_cfg.pool_type,
|
| 249 |
+
proj_type=text_cfg.proj_type,
|
| 250 |
+
proj_bias=text_cfg.proj_bias,
|
| 251 |
+
output_tokens=text_cfg.output_tokens,
|
| 252 |
+
act_layer=act_layer,
|
| 253 |
+
norm_layer=norm_layer,
|
| 254 |
+
block_type=text_cfg.block_type,
|
| 255 |
+
qk_norm=text_cfg.qk_norm,
|
| 256 |
+
scaled_cosine_attn=text_cfg.scaled_cosine_attn,
|
| 257 |
+
scale_heads=text_cfg.scale_heads,
|
| 258 |
+
scale_attn_inner=text_cfg.scale_attn_inner,
|
| 259 |
+
scale_attn=text_cfg.scale_attn,
|
| 260 |
+
scale_fc=text_cfg.scale_fc,
|
| 261 |
+
)
|
| 262 |
+
return text
|
| 263 |
+
|
| 264 |
+
|
| 265 |
+
class CLIP(nn.Module):
|
| 266 |
+
output_dict: torch.jit.Final[bool]
|
| 267 |
+
|
| 268 |
+
def __init__(
|
| 269 |
+
self,
|
| 270 |
+
embed_dim: int,
|
| 271 |
+
vision_cfg: CLIPVisionCfg,
|
| 272 |
+
text_cfg: CLIPTextCfg,
|
| 273 |
+
quick_gelu: bool = False,
|
| 274 |
+
init_logit_scale: float = np.log(1 / 0.07),
|
| 275 |
+
init_logit_bias: Optional[float] = None,
|
| 276 |
+
nonscalar_logit_scale: bool = False,
|
| 277 |
+
cast_dtype: Optional[torch.dtype] = None,
|
| 278 |
+
output_dict: bool = False,
|
| 279 |
+
):
|
| 280 |
+
super().__init__()
|
| 281 |
+
self.output_dict = output_dict
|
| 282 |
+
|
| 283 |
+
self.visual = _build_vision_tower(embed_dim, vision_cfg, quick_gelu, cast_dtype)
|
| 284 |
+
|
| 285 |
+
text = _build_text_tower(embed_dim, text_cfg, quick_gelu, cast_dtype)
|
| 286 |
+
self.transformer = text.transformer
|
| 287 |
+
self.context_length = text.context_length
|
| 288 |
+
self.vocab_size = text.vocab_size
|
| 289 |
+
self.token_embedding = text.token_embedding
|
| 290 |
+
self.positional_embedding = text.positional_embedding
|
| 291 |
+
self.ln_final = text.ln_final
|
| 292 |
+
self.text_projection = text.text_projection
|
| 293 |
+
self.text_pool_type = text.pool_type
|
| 294 |
+
self.text_eos_id = text.eos_id
|
| 295 |
+
self.register_buffer('attn_mask', text.attn_mask, persistent=False)
|
| 296 |
+
|
| 297 |
+
lshape = [1] if nonscalar_logit_scale else []
|
| 298 |
+
self.logit_scale = nn.Parameter(torch.ones(lshape) * init_logit_scale)
|
| 299 |
+
if init_logit_bias is not None:
|
| 300 |
+
self.logit_bias = nn.Parameter(torch.ones(lshape) * init_logit_bias)
|
| 301 |
+
else:
|
| 302 |
+
self.logit_bias = None
|
| 303 |
+
|
| 304 |
+
def lock_image_tower(self, unlocked_groups=0, freeze_bn_stats=False):
|
| 305 |
+
# lock image tower as per LiT - https://arxiv.org/abs/2111.07991
|
| 306 |
+
self.visual.lock(unlocked_groups=unlocked_groups, freeze_bn_stats=freeze_bn_stats)
|
| 307 |
+
|
| 308 |
+
def lock_text_tower(self, unlocked_layers: int = 0, freeze_layer_norm: bool = True):
|
| 309 |
+
assert freeze_layer_norm, 'Unfreezing LayerNorm is not supported. LayerNorm treated like other weights.'
|
| 310 |
+
lock_text_tower(self, unlocked_layers)
|
| 311 |
+
|
| 312 |
+
@torch.jit.ignore
|
| 313 |
+
def set_grad_checkpointing(self, enable=True):
|
| 314 |
+
self.visual.set_grad_checkpointing(enable)
|
| 315 |
+
self.transformer.grad_checkpointing = enable
|
| 316 |
+
|
| 317 |
+
@torch.jit.ignore
|
| 318 |
+
def no_weight_decay(self):
|
| 319 |
+
# for timm optimizers, 1d params like logit_scale, logit_bias, ln/bn scale, biases are excluded by default
|
| 320 |
+
no_wd = {'positional_embedding'}
|
| 321 |
+
if hasattr(self.visual, 'no_weight_decay'):
|
| 322 |
+
for n in self.visual.no_weight_decay():
|
| 323 |
+
no_wd.add('visual.' + n)
|
| 324 |
+
return no_wd
|
| 325 |
+
|
| 326 |
+
def encode_image(self, image, normalize: bool = False):
|
| 327 |
+
features = self.visual(image)
|
| 328 |
+
return F.normalize(features, dim=-1) if normalize else features
|
| 329 |
+
|
| 330 |
+
def encode_text(self, text, normalize: bool = False):
|
| 331 |
+
cast_dtype = self.transformer.get_cast_dtype()
|
| 332 |
+
|
| 333 |
+
x = self.token_embedding(text).to(cast_dtype) # [batch_size, n_ctx, d_model]
|
| 334 |
+
|
| 335 |
+
x = x + self.positional_embedding.to(cast_dtype)
|
| 336 |
+
x = self.transformer(x, attn_mask=self.attn_mask)
|
| 337 |
+
x = self.ln_final(x) # [batch_size, n_ctx, transformer.width]
|
| 338 |
+
x = text_global_pool(x, text, self.text_pool_type, eos_token_id=getattr(self, "text_eos_id", None))
|
| 339 |
+
if self.text_projection is not None:
|
| 340 |
+
if isinstance(self.text_projection, nn.Linear):
|
| 341 |
+
x = self.text_projection(x)
|
| 342 |
+
else:
|
| 343 |
+
x = x @ self.text_projection
|
| 344 |
+
|
| 345 |
+
return F.normalize(x, dim=-1) if normalize else x
|
| 346 |
+
|
| 347 |
+
def get_logits(self, image, text):
|
| 348 |
+
image_features = self.encode_image(image, normalize=True)
|
| 349 |
+
text_features = self.encode_text(text, normalize=True)
|
| 350 |
+
image_logits = self.logit_scale.exp() * image_features @ text_features.T
|
| 351 |
+
if self.logit_bias is not None:
|
| 352 |
+
image_logits += self.logit_bias
|
| 353 |
+
text_logits = image_logits.T
|
| 354 |
+
return image_logits, text_logits
|
| 355 |
+
|
| 356 |
+
def forward_intermediates(
|
| 357 |
+
self,
|
| 358 |
+
image: Optional[torch.Tensor] = None,
|
| 359 |
+
text: Optional[torch.Tensor] = None,
|
| 360 |
+
image_indices: Optional[Union[int, List[int]]] = None,
|
| 361 |
+
text_indices: Optional[Union[int, List[int]]] = None,
|
| 362 |
+
stop_early: bool = False,
|
| 363 |
+
normalize: bool = True,
|
| 364 |
+
normalize_intermediates: bool = False,
|
| 365 |
+
intermediates_only: bool = False,
|
| 366 |
+
image_output_fmt: str = 'NCHW',
|
| 367 |
+
image_output_extra_tokens: bool = False,
|
| 368 |
+
text_output_fmt: str = 'NLC',
|
| 369 |
+
text_output_extra_tokens: bool = False,
|
| 370 |
+
output_logits: bool = False,
|
| 371 |
+
output_logit_scale_bias: bool = False,
|
| 372 |
+
) -> Dict[str, Union[torch.Tensor, List[torch.Tensor]]]:
|
| 373 |
+
""" Forward features that returns intermediates.
|
| 374 |
+
|
| 375 |
+
Args:
|
| 376 |
+
image: Input image tensor
|
| 377 |
+
text: Input text tensor
|
| 378 |
+
image_indices: For image tower, Take last n blocks if int, all if None, select matching indices if sequence
|
| 379 |
+
text_indices: Take last n blocks if int, all if None, select matching indices if sequence
|
| 380 |
+
stop_early: Stop iterating over blocks when last desired intermediate hit
|
| 381 |
+
normalize_intermediates: Apply final norm layer to all intermediates
|
| 382 |
+
normalize: L2 Normalize final features
|
| 383 |
+
intermediates_only: Only return intermediate features, do not return final features
|
| 384 |
+
image_output_fmt: Shape of intermediate image feature outputs
|
| 385 |
+
image_output_extra_tokens: Return both prefix and spatial intermediate tokens
|
| 386 |
+
text_output_fmt: Shape of intermediate text feature outputs (ignored for this model)
|
| 387 |
+
text_output_extra_tokens: Return both prefix and spatial intermediate tokens (ignored for this model)
|
| 388 |
+
output_logits: Include logits in output
|
| 389 |
+
output_logit_scale_bias: Include the logit scale bias in the output
|
| 390 |
+
Returns:
|
| 391 |
+
|
| 392 |
+
"""
|
| 393 |
+
output = {}
|
| 394 |
+
if intermediates_only:
|
| 395 |
+
# intermediates only disables final feature normalization, and include logits
|
| 396 |
+
normalize = False
|
| 397 |
+
output_logits = False
|
| 398 |
+
if output_logits:
|
| 399 |
+
assert image is not None and text is not None, 'Both image and text inputs are required to compute logits'
|
| 400 |
+
|
| 401 |
+
if image is not None:
|
| 402 |
+
image_output = self.visual.forward_intermediates(
|
| 403 |
+
image,
|
| 404 |
+
indices=image_indices,
|
| 405 |
+
stop_early=stop_early,
|
| 406 |
+
normalize_intermediates=normalize_intermediates,
|
| 407 |
+
intermediates_only=intermediates_only,
|
| 408 |
+
output_fmt=image_output_fmt,
|
| 409 |
+
output_extra_tokens=image_output_extra_tokens,
|
| 410 |
+
)
|
| 411 |
+
if normalize and "image_features" in image_output:
|
| 412 |
+
image_output["image_features"] = F.normalize(image_output["image_features"], dim=-1)
|
| 413 |
+
output.update(image_output)
|
| 414 |
+
|
| 415 |
+
if text is not None:
|
| 416 |
+
cast_dtype = self.transformer.get_cast_dtype()
|
| 417 |
+
x = self.token_embedding(text).to(cast_dtype) # [batch_size, n_ctx, d_model]
|
| 418 |
+
x = x + self.positional_embedding.to(cast_dtype)
|
| 419 |
+
x, intermediates = self.transformer.forward_intermediates(
|
| 420 |
+
x,
|
| 421 |
+
attn_mask=self.attn_mask,
|
| 422 |
+
indices=text_indices
|
| 423 |
+
)
|
| 424 |
+
if normalize_intermediates:
|
| 425 |
+
intermediates = [self.ln_final(xi) for xi in intermediates]
|
| 426 |
+
|
| 427 |
+
# NOTE this model doesn't support cls embed in text transformer, no need for extra intermediate tokens
|
| 428 |
+
output["text_intermediates"] = intermediates
|
| 429 |
+
|
| 430 |
+
if not intermediates_only:
|
| 431 |
+
x = self.ln_final(x) # [batch_size, n_ctx, transformer.width]
|
| 432 |
+
x = text_global_pool(x, text, self.text_pool_type, eos_token_id=getattr(self, "text_eos_id", None))
|
| 433 |
+
if self.text_projection is not None:
|
| 434 |
+
if isinstance(self.text_projection, nn.Linear):
|
| 435 |
+
x = self.text_projection(x)
|
| 436 |
+
else:
|
| 437 |
+
x = x @ self.text_projection
|
| 438 |
+
if normalize:
|
| 439 |
+
x = F.normalize(x, dim=-1)
|
| 440 |
+
output["text_features"] = x
|
| 441 |
+
|
| 442 |
+
logit_scale_exp = self.logit_scale.exp() if output_logits or output_logit_scale_bias else None
|
| 443 |
+
|
| 444 |
+
if output_logits:
|
| 445 |
+
image_logits = logit_scale_exp * output["image_features"] @ output["text_features"].T
|
| 446 |
+
if self.logit_bias is not None:
|
| 447 |
+
image_logits += self.logit_bias
|
| 448 |
+
text_logits = image_logits.T
|
| 449 |
+
output["image_logits"] = image_logits
|
| 450 |
+
output["text_logits"] = text_logits
|
| 451 |
+
|
| 452 |
+
if output_logit_scale_bias:
|
| 453 |
+
output["logit_scale"] = logit_scale_exp
|
| 454 |
+
if self.logit_bias is not None:
|
| 455 |
+
output['logit_bias'] = self.logit_bias
|
| 456 |
+
|
| 457 |
+
return output
|
| 458 |
+
|
| 459 |
+
def forward(
|
| 460 |
+
self,
|
| 461 |
+
image: Optional[torch.Tensor] = None,
|
| 462 |
+
text: Optional[torch.Tensor] = None,
|
| 463 |
+
):
|
| 464 |
+
image_features = self.encode_image(image, normalize=True) if image is not None else None
|
| 465 |
+
text_features = self.encode_text(text, normalize=True) if text is not None else None
|
| 466 |
+
|
| 467 |
+
if self.output_dict:
|
| 468 |
+
out_dict = {
|
| 469 |
+
"image_features": image_features,
|
| 470 |
+
"text_features": text_features,
|
| 471 |
+
"logit_scale": self.logit_scale.exp()
|
| 472 |
+
}
|
| 473 |
+
if self.logit_bias is not None:
|
| 474 |
+
out_dict['logit_bias'] = self.logit_bias
|
| 475 |
+
return out_dict
|
| 476 |
+
|
| 477 |
+
if self.logit_bias is not None:
|
| 478 |
+
return image_features, text_features, self.logit_scale.exp(), self.logit_bias
|
| 479 |
+
return image_features, text_features, self.logit_scale.exp()
|
| 480 |
+
|
| 481 |
+
|
| 482 |
+
class CustomTextCLIP(nn.Module):
|
| 483 |
+
output_dict: torch.jit.Final[bool]
|
| 484 |
+
|
| 485 |
+
def __init__(
|
| 486 |
+
self,
|
| 487 |
+
embed_dim: int,
|
| 488 |
+
vision_cfg: CLIPVisionCfg,
|
| 489 |
+
text_cfg: CLIPTextCfg,
|
| 490 |
+
quick_gelu: bool = False,
|
| 491 |
+
init_logit_scale: float = np.log(1 / 0.07),
|
| 492 |
+
init_logit_bias: Optional[float] = None,
|
| 493 |
+
nonscalar_logit_scale: bool = False,
|
| 494 |
+
cast_dtype: Optional[torch.dtype] = None,
|
| 495 |
+
output_dict: bool = False,
|
| 496 |
+
):
|
| 497 |
+
super().__init__()
|
| 498 |
+
self.output_dict = output_dict
|
| 499 |
+
self.visual = _build_vision_tower(embed_dim, vision_cfg, quick_gelu, cast_dtype)
|
| 500 |
+
self.text = _build_text_tower(embed_dim, text_cfg, quick_gelu, cast_dtype)
|
| 501 |
+
self.context_length = self.text.context_length
|
| 502 |
+
self.vocab_size = self.text.vocab_size
|
| 503 |
+
|
| 504 |
+
lshape = [1] if nonscalar_logit_scale else []
|
| 505 |
+
self.logit_scale = nn.Parameter(torch.ones(lshape) * init_logit_scale)
|
| 506 |
+
if init_logit_bias is not None:
|
| 507 |
+
self.logit_bias = nn.Parameter(torch.ones(lshape) * init_logit_bias)
|
| 508 |
+
else:
|
| 509 |
+
self.logit_bias = None
|
| 510 |
+
|
| 511 |
+
def lock_image_tower(self, unlocked_groups=0, freeze_bn_stats=False):
|
| 512 |
+
# lock image tower as per LiT - https://arxiv.org/abs/2111.07991
|
| 513 |
+
self.visual.lock(unlocked_groups=unlocked_groups, freeze_bn_stats=freeze_bn_stats)
|
| 514 |
+
|
| 515 |
+
def lock_text_tower(self, unlocked_layers: int = 0, freeze_layer_norm: bool = True):
|
| 516 |
+
self.text.lock(unlocked_layers, freeze_layer_norm)
|
| 517 |
+
|
| 518 |
+
@torch.jit.ignore
|
| 519 |
+
def set_grad_checkpointing(self, enable=True):
|
| 520 |
+
self.visual.set_grad_checkpointing(enable)
|
| 521 |
+
self.text.set_grad_checkpointing(enable)
|
| 522 |
+
|
| 523 |
+
@torch.jit.ignore
|
| 524 |
+
def no_weight_decay(self):
|
| 525 |
+
# for timm optimizers, 1d params like logit_scale, logit_bias, ln/bn scale, biases are excluded by default
|
| 526 |
+
no_wd = set()
|
| 527 |
+
if hasattr(self.visual, 'no_weight_decay'):
|
| 528 |
+
for n in self.visual.no_weight_decay():
|
| 529 |
+
no_wd.add('visual.' + n)
|
| 530 |
+
if hasattr(self.text, 'no_weight_decay'):
|
| 531 |
+
for n in self.text.no_weight_decay():
|
| 532 |
+
no_wd.add('text.' + n)
|
| 533 |
+
return no_wd
|
| 534 |
+
|
| 535 |
+
def encode_image(self, image, normalize: bool = False):
|
| 536 |
+
features = self.visual(image)
|
| 537 |
+
return F.normalize(features, dim=-1) if normalize else features
|
| 538 |
+
|
| 539 |
+
def encode_text(self, text, normalize: bool = False):
|
| 540 |
+
features = self.text(text)
|
| 541 |
+
return F.normalize(features, dim=-1) if normalize else features
|
| 542 |
+
|
| 543 |
+
def get_logits(self, image, text):
|
| 544 |
+
image_features = self.encode_image(image, normalize=True)
|
| 545 |
+
text_features = self.encode_text(text, normalize=True)
|
| 546 |
+
image_logits = self.logit_scale.exp() * image_features @ text_features.T
|
| 547 |
+
if self.logit_bias is not None:
|
| 548 |
+
image_logits += self.logit_bias
|
| 549 |
+
text_logits = image_logits.T
|
| 550 |
+
return image_logits, text_logits
|
| 551 |
+
|
| 552 |
+
def forward_intermediates(
|
| 553 |
+
self,
|
| 554 |
+
image: Optional[torch.Tensor] = None,
|
| 555 |
+
text: Optional[torch.Tensor] = None,
|
| 556 |
+
image_indices: Optional[Union[int, List[int]]] = None,
|
| 557 |
+
text_indices: Optional[Union[int, List[int]]] = None,
|
| 558 |
+
stop_early: bool = False,
|
| 559 |
+
normalize: bool = True,
|
| 560 |
+
normalize_intermediates: bool = False,
|
| 561 |
+
intermediates_only: bool = False,
|
| 562 |
+
image_output_fmt: str = 'NCHW',
|
| 563 |
+
image_output_extra_tokens: bool = False,
|
| 564 |
+
text_output_fmt: str = 'NLC',
|
| 565 |
+
text_output_extra_tokens: bool = False,
|
| 566 |
+
output_logits: bool = False,
|
| 567 |
+
output_logit_scale_bias: bool = False,
|
| 568 |
+
) -> Dict[str, Union[torch.Tensor, List[torch.Tensor]]]:
|
| 569 |
+
""" Forward features that returns intermediates.
|
| 570 |
+
|
| 571 |
+
Args:
|
| 572 |
+
image: Input image tensor
|
| 573 |
+
text: Input text tensor
|
| 574 |
+
image_indices: For image tower, Take last n blocks if int, all if None, select matching indices if sequence
|
| 575 |
+
text_indices: Take last n blocks if int, all if None, select matching indices if sequence
|
| 576 |
+
stop_early: Stop iterating over blocks when last desired intermediate hit
|
| 577 |
+
normalize: L2 Normalize final image and text features (if present)
|
| 578 |
+
normalize_intermediates: Apply final encoder norm layer to all intermediates (if possible)
|
| 579 |
+
intermediates_only: Only return intermediate features, do not return final features
|
| 580 |
+
image_output_fmt: Shape of intermediate image feature outputs
|
| 581 |
+
image_output_extra_tokens: Return both prefix and spatial intermediate tokens
|
| 582 |
+
text_output_fmt: Shape of intermediate text feature outputs
|
| 583 |
+
text_output_extra_tokens: Return both prefix and spatial intermediate tokens
|
| 584 |
+
output_logits: Include logits in output
|
| 585 |
+
output_logit_scale_bias: Include the logit scale bias in the output
|
| 586 |
+
Returns:
|
| 587 |
+
|
| 588 |
+
"""
|
| 589 |
+
output = {}
|
| 590 |
+
if intermediates_only:
|
| 591 |
+
# intermediates only disables final feature normalization, and include logits
|
| 592 |
+
normalize = False
|
| 593 |
+
output_logits = False
|
| 594 |
+
if output_logits:
|
| 595 |
+
assert image is not None and text is not None, 'Both image and text inputs are required to compute logits'
|
| 596 |
+
|
| 597 |
+
if image is not None:
|
| 598 |
+
image_output = self.visual.forward_intermediates(
|
| 599 |
+
image,
|
| 600 |
+
indices=image_indices,
|
| 601 |
+
stop_early=stop_early,
|
| 602 |
+
normalize_intermediates=normalize_intermediates,
|
| 603 |
+
intermediates_only=intermediates_only,
|
| 604 |
+
output_fmt=image_output_fmt,
|
| 605 |
+
output_extra_tokens=image_output_extra_tokens,
|
| 606 |
+
)
|
| 607 |
+
if normalize and "image_features" in image_output:
|
| 608 |
+
image_output["image_features"] = F.normalize(image_output["image_features"], dim=-1)
|
| 609 |
+
output.update(image_output)
|
| 610 |
+
|
| 611 |
+
if text is not None:
|
| 612 |
+
text_output = self.text.forward_intermediates(
|
| 613 |
+
text,
|
| 614 |
+
indices=text_indices,
|
| 615 |
+
stop_early=stop_early,
|
| 616 |
+
normalize_intermediates=normalize_intermediates,
|
| 617 |
+
intermediates_only=intermediates_only,
|
| 618 |
+
output_fmt=text_output_fmt,
|
| 619 |
+
output_extra_tokens=text_output_extra_tokens,
|
| 620 |
+
)
|
| 621 |
+
if normalize and "text_features" in text_output:
|
| 622 |
+
text_output["text_features"] = F.normalize(text_output["text_features"], dim=-1)
|
| 623 |
+
output.update(text_output)
|
| 624 |
+
|
| 625 |
+
logit_scale_exp = self.logit_scale.exp() if output_logits or output_logit_scale_bias else None
|
| 626 |
+
|
| 627 |
+
if output_logits:
|
| 628 |
+
image_logits = logit_scale_exp * output["image_features"] @ output["text_features"].T
|
| 629 |
+
if self.logit_bias is not None:
|
| 630 |
+
image_logits += self.logit_bias
|
| 631 |
+
text_logits = image_logits.T
|
| 632 |
+
output["image_logits"] = image_logits
|
| 633 |
+
output["text_logits"] = text_logits
|
| 634 |
+
|
| 635 |
+
if output_logit_scale_bias:
|
| 636 |
+
output["logit_scale"] = logit_scale_exp
|
| 637 |
+
if self.logit_bias is not None:
|
| 638 |
+
output['logit_bias'] = self.logit_bias
|
| 639 |
+
|
| 640 |
+
return output
|
| 641 |
+
|
| 642 |
+
def forward(
|
| 643 |
+
self,
|
| 644 |
+
image: Optional[torch.Tensor] = None,
|
| 645 |
+
text: Optional[torch.Tensor] = None,
|
| 646 |
+
):
|
| 647 |
+
image_features = self.encode_image(image, normalize=True) if image is not None else None
|
| 648 |
+
text_features = self.encode_text(text, normalize=True) if text is not None else None
|
| 649 |
+
|
| 650 |
+
if self.output_dict:
|
| 651 |
+
out_dict = {
|
| 652 |
+
"image_features": image_features,
|
| 653 |
+
"text_features": text_features,
|
| 654 |
+
"logit_scale": self.logit_scale.exp()
|
| 655 |
+
}
|
| 656 |
+
if self.logit_bias is not None:
|
| 657 |
+
out_dict['logit_bias'] = self.logit_bias
|
| 658 |
+
return out_dict
|
| 659 |
+
|
| 660 |
+
if self.logit_bias is not None:
|
| 661 |
+
return image_features, text_features, self.logit_scale.exp(), self.logit_bias
|
| 662 |
+
return image_features, text_features, self.logit_scale.exp()
|
| 663 |
+
|
| 664 |
+
|
| 665 |
+
def convert_weights_to_lp(model: nn.Module, dtype=torch.float16):
|
| 666 |
+
"""Convert applicable model parameters to low-precision (bf16 or fp16)"""
|
| 667 |
+
|
| 668 |
+
def _convert_weights(l):
|
| 669 |
+
if isinstance(l, (nn.Conv1d, nn.Conv2d, nn.Linear)):
|
| 670 |
+
l.weight.data = l.weight.data.to(dtype)
|
| 671 |
+
if l.bias is not None:
|
| 672 |
+
l.bias.data = l.bias.data.to(dtype)
|
| 673 |
+
|
| 674 |
+
if isinstance(l, (nn.MultiheadAttention, Attention)):
|
| 675 |
+
for attr in [*[f"{s}_proj_weight" for s in ["in", "q", "k", "v"]], "in_proj_bias", "bias_k", "bias_v"]:
|
| 676 |
+
tensor = getattr(l, attr, None)
|
| 677 |
+
if tensor is not None:
|
| 678 |
+
tensor.data = tensor.data.to(dtype)
|
| 679 |
+
|
| 680 |
+
if isinstance(l, (CLIP, TextTransformer)):
|
| 681 |
+
# convert text nn.Parameter projections
|
| 682 |
+
attr = getattr(l, "text_projection", None)
|
| 683 |
+
if attr is not None:
|
| 684 |
+
attr.data = attr.data.to(dtype)
|
| 685 |
+
|
| 686 |
+
if isinstance(l, VisionTransformer):
|
| 687 |
+
# convert vision nn.Parameter projections
|
| 688 |
+
attr = getattr(l, "proj", None)
|
| 689 |
+
if attr is not None:
|
| 690 |
+
attr.data = attr.data.to(dtype)
|
| 691 |
+
|
| 692 |
+
model.apply(_convert_weights)
|
| 693 |
+
|
| 694 |
+
|
| 695 |
+
convert_weights_to_fp16 = convert_weights_to_lp # backwards compat
|
| 696 |
+
|
| 697 |
+
|
| 698 |
+
# used to maintain checkpoint compatibility
|
| 699 |
+
def convert_to_custom_text_state_dict(state_dict: dict):
|
| 700 |
+
if 'text_projection' in state_dict:
|
| 701 |
+
# old format state_dict, move text tower -> .text
|
| 702 |
+
new_state_dict = {}
|
| 703 |
+
for k, v in state_dict.items():
|
| 704 |
+
if any(k.startswith(p) for p in (
|
| 705 |
+
'text_projection',
|
| 706 |
+
'positional_embedding',
|
| 707 |
+
'token_embedding',
|
| 708 |
+
'transformer',
|
| 709 |
+
'ln_final',
|
| 710 |
+
)):
|
| 711 |
+
k = 'text.' + k
|
| 712 |
+
new_state_dict[k] = v
|
| 713 |
+
return new_state_dict
|
| 714 |
+
return state_dict
|
| 715 |
+
|
| 716 |
+
|
| 717 |
+
def build_model_from_openai_state_dict(
|
| 718 |
+
state_dict: dict,
|
| 719 |
+
quick_gelu=True,
|
| 720 |
+
cast_dtype=torch.float16,
|
| 721 |
+
):
|
| 722 |
+
vit = "visual.proj" in state_dict
|
| 723 |
+
|
| 724 |
+
if vit:
|
| 725 |
+
vision_width = state_dict["visual.conv1.weight"].shape[0]
|
| 726 |
+
vision_layers = len(
|
| 727 |
+
[k for k in state_dict.keys() if k.startswith("visual.") and k.endswith(".attn.in_proj_weight")])
|
| 728 |
+
vision_patch_size = state_dict["visual.conv1.weight"].shape[-1]
|
| 729 |
+
grid_size = round((state_dict["visual.positional_embedding"].shape[0] - 1) ** 0.5)
|
| 730 |
+
image_size = vision_patch_size * grid_size
|
| 731 |
+
else:
|
| 732 |
+
counts: list = [
|
| 733 |
+
len(set(k.split(".")[2] for k in state_dict if k.startswith(f"visual.layer{b}"))) for b in [1, 2, 3, 4]]
|
| 734 |
+
vision_layers = tuple(counts)
|
| 735 |
+
vision_width = state_dict["visual.layer1.0.conv1.weight"].shape[0]
|
| 736 |
+
output_width = round((state_dict["visual.attnpool.positional_embedding"].shape[0] - 1) ** 0.5)
|
| 737 |
+
vision_patch_size = None
|
| 738 |
+
assert output_width ** 2 + 1 == state_dict["visual.attnpool.positional_embedding"].shape[0]
|
| 739 |
+
image_size = output_width * 32
|
| 740 |
+
|
| 741 |
+
embed_dim = state_dict["text_projection"].shape[1]
|
| 742 |
+
context_length = state_dict["positional_embedding"].shape[0]
|
| 743 |
+
vocab_size = state_dict["token_embedding.weight"].shape[0]
|
| 744 |
+
transformer_width = state_dict["ln_final.weight"].shape[0]
|
| 745 |
+
transformer_heads = transformer_width // 64
|
| 746 |
+
transformer_layers = len(set(k.split(".")[2] for k in state_dict if k.startswith(f"transformer.resblocks")))
|
| 747 |
+
|
| 748 |
+
vision_cfg = CLIPVisionCfg(
|
| 749 |
+
layers=vision_layers,
|
| 750 |
+
width=vision_width,
|
| 751 |
+
patch_size=vision_patch_size,
|
| 752 |
+
image_size=image_size,
|
| 753 |
+
)
|
| 754 |
+
text_cfg = CLIPTextCfg(
|
| 755 |
+
context_length=context_length,
|
| 756 |
+
vocab_size=vocab_size,
|
| 757 |
+
width=transformer_width,
|
| 758 |
+
heads=transformer_heads,
|
| 759 |
+
layers=transformer_layers,
|
| 760 |
+
)
|
| 761 |
+
model = CLIP(
|
| 762 |
+
embed_dim,
|
| 763 |
+
vision_cfg=vision_cfg,
|
| 764 |
+
text_cfg=text_cfg,
|
| 765 |
+
quick_gelu=quick_gelu, # OpenAI models were trained with QuickGELU
|
| 766 |
+
cast_dtype=cast_dtype,
|
| 767 |
+
)
|
| 768 |
+
|
| 769 |
+
for key in ["input_resolution", "context_length", "vocab_size"]:
|
| 770 |
+
state_dict.pop(key, None)
|
| 771 |
+
convert_weights_to_fp16(model) # OpenAI state dicts are partially converted to float16
|
| 772 |
+
model.load_state_dict(state_dict)
|
| 773 |
+
return model.eval()
|
| 774 |
+
|
| 775 |
+
|
| 776 |
+
def trace_model(model, batch_size=256, device=torch.device('cpu')):
|
| 777 |
+
model.eval()
|
| 778 |
+
image_size = model.visual.image_size
|
| 779 |
+
example_images = torch.ones((batch_size, 3, image_size, image_size), device=device)
|
| 780 |
+
example_text = torch.zeros((batch_size, model.context_length), dtype=torch.int, device=device)
|
| 781 |
+
model = torch.jit.trace_module(
|
| 782 |
+
model,
|
| 783 |
+
inputs=dict(
|
| 784 |
+
forward=(example_images, example_text),
|
| 785 |
+
encode_text=(example_text,),
|
| 786 |
+
encode_image=(example_images,)
|
| 787 |
+
))
|
| 788 |
+
model.visual.image_size = image_size
|
| 789 |
+
return model
|
| 790 |
+
|
| 791 |
+
|
| 792 |
+
def resize_pos_embed(state_dict, model, interpolation: str = 'bicubic', antialias: bool = True):
|
| 793 |
+
# Rescale the grid of position embeddings when loading from state_dict
|
| 794 |
+
old_pos_embed = state_dict.get('visual.positional_embedding', None)
|
| 795 |
+
if old_pos_embed is None or not hasattr(model.visual, 'grid_size'):
|
| 796 |
+
return
|
| 797 |
+
grid_size = to_2tuple(model.visual.grid_size)
|
| 798 |
+
extra_tokens = 1 # FIXME detect different token configs (ie no class token, or more)
|
| 799 |
+
new_seq_len = grid_size[0] * grid_size[1] + extra_tokens
|
| 800 |
+
if new_seq_len == old_pos_embed.shape[0]:
|
| 801 |
+
return
|
| 802 |
+
|
| 803 |
+
if extra_tokens:
|
| 804 |
+
pos_emb_tok, pos_emb_img = old_pos_embed[:extra_tokens], old_pos_embed[extra_tokens:]
|
| 805 |
+
else:
|
| 806 |
+
pos_emb_tok, pos_emb_img = None, old_pos_embed
|
| 807 |
+
old_grid_size = to_2tuple(int(math.sqrt(len(pos_emb_img))))
|
| 808 |
+
|
| 809 |
+
logging.info('Resizing position embedding grid-size from %s to %s', old_grid_size, grid_size)
|
| 810 |
+
pos_emb_img = pos_emb_img.reshape(1, old_grid_size[0], old_grid_size[1], -1).permute(0, 3, 1, 2)
|
| 811 |
+
pos_emb_img = F.interpolate(
|
| 812 |
+
pos_emb_img,
|
| 813 |
+
size=grid_size,
|
| 814 |
+
mode=interpolation,
|
| 815 |
+
antialias=antialias,
|
| 816 |
+
align_corners=False,
|
| 817 |
+
)
|
| 818 |
+
pos_emb_img = pos_emb_img.permute(0, 2, 3, 1).reshape(1, grid_size[0] * grid_size[1], -1)[0]
|
| 819 |
+
if pos_emb_tok is not None:
|
| 820 |
+
new_pos_embed = torch.cat([pos_emb_tok, pos_emb_img], dim=0)
|
| 821 |
+
else:
|
| 822 |
+
new_pos_embed = pos_emb_img
|
| 823 |
+
state_dict['visual.positional_embedding'] = new_pos_embed
|
| 824 |
+
|
| 825 |
+
|
| 826 |
+
def resize_text_pos_embed(state_dict, model, interpolation: str = 'linear', antialias: bool = False):
|
| 827 |
+
pos_embed_key = 'positional_embedding' if 'positional_embedding' in state_dict else 'text.positional_embedding'
|
| 828 |
+
old_pos_embed = state_dict.get(pos_embed_key, None)
|
| 829 |
+
if old_pos_embed is None:
|
| 830 |
+
return
|
| 831 |
+
# FIXME add support for text cls_token
|
| 832 |
+
model_pos_embed = getattr(model, 'positional_embedding', None)
|
| 833 |
+
if model_pos_embed is None:
|
| 834 |
+
model_pos_embed = getattr(model.text, 'positional_embedding', None)
|
| 835 |
+
|
| 836 |
+
old_num_pos = old_pos_embed.shape[0]
|
| 837 |
+
old_width = old_pos_embed.shape[1]
|
| 838 |
+
num_pos = model_pos_embed.shape[0]
|
| 839 |
+
width = model_pos_embed.shape[1]
|
| 840 |
+
assert old_width == width, 'text pos_embed width changed!'
|
| 841 |
+
if old_num_pos == num_pos:
|
| 842 |
+
return
|
| 843 |
+
|
| 844 |
+
logging.info('Resizing text position embedding num_pos from %s to %s', old_num_pos, num_pos)
|
| 845 |
+
old_pos_embed = old_pos_embed.reshape(1, old_num_pos, old_width).permute(0, 2, 1)
|
| 846 |
+
old_pos_embed = F.interpolate(
|
| 847 |
+
old_pos_embed,
|
| 848 |
+
size=num_pos,
|
| 849 |
+
mode=interpolation,
|
| 850 |
+
antialias=antialias,
|
| 851 |
+
align_corners=False,
|
| 852 |
+
)
|
| 853 |
+
old_pos_embed = old_pos_embed.permute(0, 2, 1)[0]
|
| 854 |
+
new_pos_embed = old_pos_embed
|
| 855 |
+
|
| 856 |
+
state_dict[pos_embed_key] = new_pos_embed
|
| 857 |
+
|
| 858 |
+
|
| 859 |
+
def get_model_preprocess_cfg(model):
|
| 860 |
+
module = getattr(model, 'visual', model)
|
| 861 |
+
preprocess_cfg = getattr(module, 'preprocess_cfg', {})
|
| 862 |
+
if not preprocess_cfg:
|
| 863 |
+
# use separate legacy attributes if preprocess_cfg dict not found
|
| 864 |
+
size = getattr(module, 'image_size')
|
| 865 |
+
if size is not None:
|
| 866 |
+
preprocess_cfg['size'] = size
|
| 867 |
+
mean = getattr(module, 'image_mean', None)
|
| 868 |
+
if mean is not None:
|
| 869 |
+
preprocess_cfg['mean'] = mean
|
| 870 |
+
std = getattr(module, 'image_std', None)
|
| 871 |
+
if std is not None:
|
| 872 |
+
preprocess_cfg['std'] = std
|
| 873 |
+
return preprocess_cfg
|
| 874 |
+
|
| 875 |
+
|
| 876 |
+
def set_model_preprocess_cfg(model, preprocess_cfg: Dict[str, Any]):
|
| 877 |
+
module = getattr(model, 'visual', model)
|
| 878 |
+
module.image_mean = preprocess_cfg['mean'] # legacy attribute, keeping for bwd compat
|
| 879 |
+
module.image_std = preprocess_cfg['std'] # legacy attribute, keeping for bwd compat
|
| 880 |
+
module.preprocess_cfg = copy.deepcopy(preprocess_cfg) # new attr, package all pp cfg as dict
|
| 881 |
+
|
| 882 |
+
|
| 883 |
+
def get_model_tokenize_cfg(model):
|
| 884 |
+
module = getattr(model, 'text', model)
|
| 885 |
+
cfg = {}
|
| 886 |
+
context_length = getattr(module, 'context_length', None)
|
| 887 |
+
if context_length is not None:
|
| 888 |
+
cfg['context_length'] = context_length
|
| 889 |
+
vocab_size = getattr(module, 'vocab_size', None)
|
| 890 |
+
if vocab_size is not None:
|
| 891 |
+
cfg['vocab_size'] = vocab_size
|
| 892 |
+
return cfg
|