Skip to content

Commit cd15a7b

Browse files
committed
Add safeglobals to allow metaclip models to load with weights_only=True, add bigG metaclip while working with them
1 parent c82349a commit cd15a7b

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

src/open_clip/factory.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,20 @@
2626
_MODEL_CONFIGS = {} # directory (model_name: config) of model architecture configs
2727

2828

29+
try:
30+
import _codecs
31+
import numpy as np
32+
# add safe globals, known to be needed for metaclip weights
33+
torch.serialization.add_safe_globals([
34+
_codecs.encode, # now in pytorch main but some pytorch versions w/ weights_only flag don't have it
35+
np.core.multiarray.scalar,
36+
np.dtype,
37+
np.dtypes.Float64DType,
38+
])
39+
except Exception:
40+
pass
41+
42+
2943
def _natural_key(string_):
3044
return [int(s) if s.isdigit() else s for s in re.split(r'(\d+)', string_.lower())]
3145

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"embed_dim": 1280,
3+
"quick_gelu": true,
4+
"vision_cfg": {
5+
"image_size": 224,
6+
"layers": 48,
7+
"width": 1664,
8+
"head_width": 104,
9+
"mlp_ratio": 4.9231,
10+
"patch_size": 14
11+
},
12+
"text_cfg": {
13+
"context_length": 77,
14+
"vocab_size": 49408,
15+
"width": 1280,
16+
"heads": 20,
17+
"layers": 32
18+
}
19+
}

src/open_clip/pretrained.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,10 @@ def _mccfg(url='', hf_hub='', **kwargs):
280280
laion2b_s39b_b160k=_pcfg(hf_hub='laion/CLIP-ViT-bigG-14-laion2B-39B-b160k/'),
281281
)
282282

283+
_VITbigG14_quickgelu = dict(
284+
metaclip_fullcc=_pcfg(url='https://dl.fbaipublicfiles.com/MMPT/metaclip/G14_fullcc2.5b.pt'),
285+
)
286+
283287
_robertaViTB32 = dict(
284288
laion2b_s12b_b32k=_pcfg(hf_hub='laion/CLIP-ViT-B-32-roberta-base-laion2B-s12B-b32k/'),
285289
)
@@ -356,6 +360,7 @@ def _mccfg(url='', hf_hub='', **kwargs):
356360
"ViT-H-14-378-quickgelu": _VITH14_378_quickgelu,
357361
"ViT-g-14": _VITg14,
358362
"ViT-bigG-14": _VITbigG14,
363+
"ViT-bigG-14-quickgelu": _VITbigG14_quickgelu,
359364

360365
"roberta-ViT-B-32": _robertaViTB32,
361366
"xlm-roberta-base-ViT-B-32": _xlmRobertaBaseViTB32,

0 commit comments

Comments
 (0)