forked from ronghanghu/moco_v3_tpu
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathslip_models.py
654 lines (513 loc) · 23.9 KB
/
slip_models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
# Modified from github.com/openai/CLIP
from collections import OrderedDict
import numpy as np
import timm
import torch
from torch import nn
import losses
from torchvision.models import mobilenet_v3_small, resnet18
import parallel_transformer
import parallel_protonet
import bagnet
from ldm.models.autoencoder import AutoencoderKL, VQModel
from omegaconf import OmegaConf
def text_binary_call():
# base is 512 8 12
# quadrating in width, linear in depth
# to reduce by 64 can reudce width by 8
# I don't think heads matters, but could be wrong.
# dropping down to maintain more width for each head
return CLIP(embed_dim=1,
vision_width=1,
vision_model=None,
context_length=77,
vocab_size=49408,
transformer_width=64,
transformer_heads=4,
transformer_layers=12
)
class MultiBinaryText(nn.Module):
def __init__(self, num_models=64):
super().__init__()
self.model_list = nn.ModuleList([text_binary_call() for _ in range(num_models)])
def forward(self, x):
# this is raw logits, should sigmoid or tanh
return torch.cat([m.encode_text(x) for m in self.model_list], dim=1)
def vision_binary_call():
net = mobilenet_v3_small(num_classes=1)
net.classifier[2].p = 0
return net
class MultiResNet(nn.Module):
def __init__(self, num_models=64, output_dim_per_model=64):
super().__init__()
self.model_list = nn.ModuleList([resnet18(num_classes=output_dim_per_model) for _ in range(num_models)])
def forward(self, x):
# this is raw logits, should sigmoid or tanh
return torch.cat([m(x) for m in self.model_list], dim=1)
class MultiBinaryVision(nn.Module):
def __init__(self, num_models=64):
super().__init__()
self.model_list = nn.ModuleList([vision_binary_call() for _ in range(num_models)])
def forward(self, x):
# this is raw logits, should sigmoid or tanh
return torch.cat([m(x) for m in self.model_list], dim=1)
class MultiBinaryCLIP(nn.Module):
def __init__(self,
num_models,
):
super().__init__()
self.visual = MultiBinaryVision(num_models)
self.language = MultiBinaryText(num_models)
self.logit_scale = nn.Parameter(torch.ones([]) * np.log(1 / 0.07))
def encode_image(self, image):
return self.visual(image)
def encode_text(self, text):
return self.language(text)
def forward(self, image, text, return_logit_scale=True):
image_embed = self.encode_image(image)
text_embed = self.encode_text(text)
return {'image_embed': image_embed,
'text_embed': text_embed,
'logit_scale':self.logit_scale.exp() if return_logit_scale else None}
def VisionParallelTextStandard(num_models, output_dim_per_model):
embed_dim = num_models * output_dim_per_model
viz_model = parallel_protonet.make_protonet_v2(num_models, output_dim_per_model)
clip_model = CLIP(embed_dim, embed_dim, viz_model, 77, vocab_size=49408,
transformer_width=512, transformer_heads=8, transformer_layers=12)
clip_model.image_projection.data = torch.eye(embed_dim)
clip_model.image_projection.requires_grad = False
return clip_model
def VisionMultiResNetTextStandard(num_models, output_dim_per_model,
large_text_model=False):
embed_dim = num_models * output_dim_per_model
viz_model = MultiResNet(num_models, output_dim_per_model)
if large_text_model:
clip_model = CLIP(embed_dim, embed_dim,
viz_model, 77, vocab_size=49408,
transformer_width=1024,
transformer_heads=16,
transformer_layers=12)
else:
clip_model = CLIP(embed_dim, embed_dim,
viz_model, 77, vocab_size=49408,
transformer_width=512,
transformer_heads=8,
transformer_layers=12)
clip_model.image_projection.data = torch.eye(embed_dim)
clip_model.image_projection.requires_grad = False
return clip_model
def VisionStandardTextParallel():
base_model = ParallelMultiBinaryCLIP(64)
base_model.visual = nn.Sequential(timm.create_model('vit_base_patch16_224', num_classes=0),
nn.Linear(768, 64, bias=False))
return base_model
class ParallelMultiBinaryCLIP(nn.Module):
def __init__(self, num_models):
super().__init__()
# self.visual = parallel_protonet.make_simple_protonet(3, 64*64, 64)
self.visual = parallel_protonet.make_protonet_v2(64)
self.language = parallel_transformer.ParallelTextEncoder(num_models=64,
output_dim_per_model=1,
context_length=77,
vocab_size=49408,
transformer_width=64,
transformer_heads=4,
transformer_layers=6)
self.logit_scale = nn.Parameter(torch.ones([]) * np.log(1 / 0.07))
def encode_image(self, image):
return self.visual(image)
def encode_text(self, text):
return self.language(text)
def forward(self, image, text, return_logit_scale=True):
image_embed = self.encode_image(image)
text_embed = self.encode_text(text)
return {'image_embed': image_embed,
'text_embed': text_embed,
'logit_scale':self.logit_scale.exp() if return_logit_scale else None}
class ParallelMultiBinaryCLIP(nn.Module):
def __init__(self, num_models):
super().__init__()
# self.visual = parallel_protonet.make_simple_protonet(3, 64*64, 64)
self.visual = parallel_protonet.make_protonet_v2(64)
self.language = parallel_transformer.ParallelTextEncoder(num_models=64,
output_dim_per_model=1,
context_length=77,
vocab_size=49408,
transformer_width=64,
transformer_heads=4,
transformer_layers=6)
self.logit_scale = nn.Parameter(torch.ones([]) * np.log(1 / 0.07))
def encode_image(self, image):
return self.visual(image)
def encode_text(self, text):
return self.language(text)
def forward(self, image, text, return_logit_scale=True):
image_embed = self.encode_image(image)
text_embed = self.encode_text(text)
return {'image_embed': image_embed,
'text_embed': text_embed,
'logit_scale':self.logit_scale.exp() if return_logit_scale else None}
class LayerNorm(nn.LayerNorm):
"""Subclass torch's LayerNorm to handle fp16."""
def forward(self, x: torch.Tensor):
orig_type = x.dtype
ret = super().forward(x.type(torch.float32))
return ret.type(orig_type)
class QuickGELU(nn.Module):
def forward(self, x: torch.Tensor):
return x * torch.sigmoid(1.702 * x)
class ResidualAttentionBlock(nn.Module):
def __init__(self, d_model: int, n_head: int, attn_mask: torch.Tensor = None):
super().__init__()
self.attn = nn.MultiheadAttention(d_model, n_head)
self.ln_1 = LayerNorm(d_model)
self.mlp = nn.Sequential(OrderedDict([
("c_fc", nn.Linear(d_model, d_model * 4)),
("gelu", QuickGELU()),
("c_proj", nn.Linear(d_model * 4, d_model))
]))
self.ln_2 = LayerNorm(d_model)
self.attn_mask = attn_mask
def attention(self, x: torch.Tensor):
self.attn_mask = self.attn_mask.to(dtype=x.dtype, device=x.device) if self.attn_mask is not None else None
return self.attn(x, x, x, need_weights=False, attn_mask=self.attn_mask)[0]
def forward(self, x: torch.Tensor):
x = x + self.attention(self.ln_1(x))
x = x + self.mlp(self.ln_2(x))
return x
class Transformer(nn.Module):
def __init__(self, width: int, layers: int, heads: int, attn_mask: torch.Tensor = None):
super().__init__()
self.width = width
self.layers = layers
self.resblocks = nn.Sequential(*[ResidualAttentionBlock(width, heads, attn_mask) for _ in range(layers)])
def forward(self, x: torch.Tensor):
return self.resblocks(x)
class CLIP(nn.Module):
def __init__(self,
embed_dim: int,
# vision
vision_width: int,
vision_model: nn.Module,
# text
context_length: int,
vocab_size: int,
transformer_width: int,
transformer_heads: int,
transformer_layers: int,
**kwargs,
):
super().__init__()
self.context_length = context_length
self.vision_width = vision_width
self.visual = vision_model
self.transformer = Transformer(
width=transformer_width,
layers=transformer_layers,
heads=transformer_heads,
attn_mask=self.build_attention_mask(),
)
self.vocab_size = vocab_size
self.token_embedding = nn.Embedding(vocab_size, transformer_width)
self.positional_embedding = nn.Parameter(torch.empty(self.context_length, transformer_width))
self.ln_final = LayerNorm(transformer_width)
self.image_projection = nn.Parameter(torch.empty(vision_width, embed_dim))
self.text_projection = nn.Parameter(torch.empty(transformer_width, embed_dim))
self.logit_scale = nn.Parameter(torch.ones([]) * np.log(1 / 0.07))
self.initialize_parameters()
def initialize_parameters(self):
nn.init.normal_(self.token_embedding.weight, std=0.02)
nn.init.normal_(self.positional_embedding, std=0.01)
proj_std = (self.transformer.width ** -0.5) * ((2 * self.transformer.layers) ** -0.5)
attn_std = self.transformer.width ** -0.5
fc_std = (2 * self.transformer.width) ** -0.5
for block in self.transformer.resblocks:
nn.init.normal_(block.attn.in_proj_weight, std=attn_std)
nn.init.normal_(block.attn.out_proj.weight, std=proj_std)
nn.init.normal_(block.mlp.c_fc.weight, std=fc_std)
nn.init.normal_(block.mlp.c_proj.weight, std=proj_std)
nn.init.normal_(self.image_projection, std=self.vision_width ** -0.5)
nn.init.normal_(self.text_projection, std=self.transformer.width ** -0.5)
def build_attention_mask(self):
# lazily create causal attention mask, with full attention between the vision tokens
# pytorch uses additive attention mask; fill with -inf
mask = torch.empty(self.context_length, self.context_length)
mask.fill_(float("-inf"))
mask.triu_(1) # zero out the lower diagonal
return mask
def encode_image(self, image):
x = self.visual(image)
x = x @ self.image_projection
return x
def encode_text(self, text):
x = self.token_embedding(text) # [batch_size, n_ctx, d_model]
x = x + self.positional_embedding
x = x.permute(1, 0, 2) # NLD -> LND
x = self.transformer(x)
x = x.permute(1, 0, 2) # LND -> NLD
x = self.ln_final(x)
# x.shape = [batch_size, n_ctx, transformer.width]
# take features from the eot embedding (eot_token is the highest number in each sequence)
x = x[torch.arange(x.shape[0]), text.argmax(dim=-1)] @ self.text_projection
return x
def forward(self, image, text, return_logit_scale=True):
image_embed = self.encode_image(image)
text_embed = self.encode_text(text)
return {'image_embed': image_embed,
'text_embed': text_embed,
'logit_scale': self.logit_scale.exp() if return_logit_scale else None}
class SIMCLR(nn.Module):
def __init__(self,
# vision
vision_width: int,
vision_model: nn.Module,
# ssl
ssl_mlp_dim: int,
ssl_emb_dim: int,
**kwargs,
):
super().__init__()
self.vision_width = vision_width
self.visual = vision_model
self.image_mlp = self._build_mlp(in_dim=vision_width, mlp_dim=ssl_mlp_dim, out_dim=ssl_emb_dim)
def _build_mlp(self, in_dim, mlp_dim, out_dim):
return nn.Sequential(OrderedDict([
("layer1", nn.Linear(in_dim, mlp_dim)),
("bn1", nn.SyncBatchNorm(mlp_dim)),
("relu1", nn.ReLU(inplace=True)),
("layer2", nn.Linear(mlp_dim, mlp_dim)),
("bn2", nn.SyncBatchNorm(mlp_dim)),
("relu2", nn.ReLU(inplace=True)),
("layer3", nn.Linear(mlp_dim, out_dim)),
]))
def encode_image(self, image):
x = self.visual(image)
return x
def forward(self, aug1, aug2):
h1 = self.visual(aug1)
h2 = self.visual(aug2)
aug1_embed = self.image_mlp(h1)
aug2_embed = self.image_mlp(h2)
return {'aug1_embed': aug1_embed,
'aug2_embed': aug2_embed}
class SLIP(CLIP):
def __init__(self,
ssl_mlp_dim: int,
ssl_emb_dim: int,
**kwargs,
):
super().__init__(**kwargs)
self.image_mlp = self._build_mlp(in_dim=self.vision_width, mlp_dim=ssl_mlp_dim, out_dim=ssl_emb_dim)
def _build_mlp(self, in_dim, mlp_dim, out_dim):
return nn.Sequential(OrderedDict([
("layer1", nn.Linear(in_dim, mlp_dim)),
("bn1", nn.SyncBatchNorm(mlp_dim)),
("relu1", nn.ReLU(inplace=True)),
("layer2", nn.Linear(mlp_dim, mlp_dim)),
("bn2", nn.SyncBatchNorm(mlp_dim)),
("relu2", nn.ReLU(inplace=True)),
("layer3", nn.Linear(mlp_dim, out_dim)),
]))
def forward(self, image, text, aug1, aug2):
aug1_embed = self.image_mlp(self.visual(aug1))
aug2_embed = self.image_mlp(self.visual(aug2))
image_embed = self.encode_image(image)
text_embed = self.encode_text(text)
return {'image_embed': image_embed,
'text_embed': text_embed,
'logit_scale': self.logit_scale.exp(),
'aug1_embed': aug1_embed,
'aug2_embed': aug2_embed}
def get_loss(model, ssl_temp, ssl_scale):
if model.startswith('SLIP'):
ssl_loss = losses.SIMCLRLoss(temperature=ssl_temp)
return losses.SLIPLoss(ssl_loss, ssl_scale)
if model.startswith('CLIP'):
return losses.CLIPLoss()
if model.startswith('SIMCLR'):
return losses.SIMCLRLoss(temperature=ssl_temp)
def get_metric_names(model):
if model.startswith('SLIP'):
return ['loss', 'clip_loss', 'ssl_loss', 'clip_acc', 'ssl_acc']
elif model.startswith('CLIP'):
return ['loss', 'clip_loss', 'clip_acc']
else:
return ['loss', 'ssl_loss', 'ssl_acc']
@timm.models.registry.register_model
def vit_small_mocov3_patch16_224(**kwargs):
model_kwargs = dict(patch_size=16, embed_dim=384, depth=12, num_heads=12, **kwargs)
model = timm.models.vision_transformer._create_vision_transformer('vit_small_patch16_224', **model_kwargs)
return model
def CLIP_MobileNetV3Small(embed_dim=512, **kwargs):
vision_model = mobilenet_v3_small(num_classes=1)
vision_model.classifier = torch.nn.Identity()
model = CLIP(embed_dim=embed_dim, vision_width=576, vision_model=vision_model, context_length=77, vocab_size=49408,
transformer_width=512, transformer_heads=8, transformer_layers=12, **kwargs)
return model
def create_ae(ae_str='kl-f8'):
# config = OmegaConf.load(f'configs/autoencoder/autoencoder_{ae_str}.yaml')
model_dir = f'models/first_stage_models/{ae_str}'
config = OmegaConf.load(f'{model_dir}/config.yaml')
# sd = torch.load(f'models/first_stage_models/{ae_str_to_first_stage_id[ae_str]}/model.ckpt',
sd = torch.load(f'{model_dir}/model.ckpt',
map_location=torch.device('cpu'))['state_dict']
if 'kl' in ae_str:
ae = AutoencoderKL(config['model']['params']['ddconfig'],
config['model']['params']['lossconfig'],
config['model']['params']['embed_dim'])
elif 'vq' in ae_str:
ae = VQModel(config['model']['params']['ddconfig'],
config['model']['params']['lossconfig'],
config['model']['params']['n_embed'],
config['model']['params']['embed_dim'])
else:
raise NotImplementedError
ae.load_state_dict(sd)
ae = ae.eval()
return ae
class AE_Encoder(torch.nn.Module):
def __init__(self, ae_str):
super().__init__()
self.ae = create_ae(ae_str)
self.type = ae_str.split('-')[0]
assert self.type in {'vq', 'kl'}
def forward(self, x):
if self.type == 'kl':
# TODO: Consider doing sampling here instead of mode
return self.ae.encode(x).mode()
elif self.type == 'vq':
# TODO: Consider adding non-quantized capability here
# The other return items of encode are a loss and a list including the token idx
return self.ae.encode(x)[0]
else:
raise NotImplementedError
def CLIP_AE_ResNet(embed_dim=512,
ae_str='kl-f8',
large_text_model=False,
**kwargs):
enc = AE_Encoder(ae_str)
for p in enc.parameters():
p.requires_grad = False
clf = resnet18()
clf.fc = torch.nn.Identity()
ae_to_in_channels = {'kl-f8':4, 'vq-f4':3}
new_in_channels = ae_to_in_channels[ae_str]
clf.conv1 = nn.Conv2d(new_in_channels, clf.conv1.out_channels, kernel_size=7, stride=2, padding=3, bias=False)
nn.init.kaiming_normal_(clf.conv1.weight, mode="fan_out", nonlinearity="relu")
vision_model = torch.nn.Sequential(enc, clf)
if large_text_model:
model = CLIP(embed_dim=embed_dim, vision_width=512,
vision_model=vision_model, context_length=77,
vocab_size=49408,
transformer_width=1024,
transformer_heads=16,
transformer_layers=12,
**kwargs)
else:
model = CLIP(embed_dim=embed_dim, vision_width=512,
vision_model=vision_model, context_length=77,
vocab_size=49408,
transformer_width=512,
transformer_heads=8,
transformer_layers=12,
**kwargs)
return model
def CLIP_BagNet(embed_dim=512,
patch_size=33, avg_pool=False,
large_text_model=False,
**kwargs):
bagnet_call_dict = {9:bagnet.bagnet9,
17:bagnet.bagnet17,
33:bagnet.bagnet33}
bagnet_call = bagnet_call_dict[patch_size]
vision_model = bagnet_call(avg_pool=avg_pool)
# with avg_pool=False will get bs x spatial x spatial x embed_dim
# This can be hit with proj fine
# size is 27, 26, 24 for patches repsectiveyl
# (note that patches have overlap)
vision_model.fc = torch.nn.Identity()
if large_text_model:
model = CLIP(embed_dim=embed_dim, vision_width=2048,
vision_model=vision_model, context_length=77,
vocab_size=49408,
transformer_width=1024,
transformer_heads=16,
transformer_layers=12,
**kwargs)
else:
model = CLIP(embed_dim=embed_dim, vision_width=2048,
vision_model=vision_model, context_length=77,
vocab_size=49408,
transformer_width=512,
transformer_heads=8,
transformer_layers=12,
**kwargs)
return model
def CLIP_ResNet18(embed_dim=512,
large_text_model=False,
**kwargs):
vision_model = resnet18(num_classes=1)
vision_model.fc = torch.nn.Identity()
if large_text_model:
model = CLIP(embed_dim=embed_dim, vision_width=512,
vision_model=vision_model, context_length=77,
vocab_size=49408,
transformer_width=1024,
transformer_heads=16,
transformer_layers=12,
**kwargs)
else:
model = CLIP(embed_dim=embed_dim, vision_width=512,
vision_model=vision_model, context_length=77,
vocab_size=49408,
transformer_width=512,
transformer_heads=8,
transformer_layers=12,
**kwargs)
return model
def CLIP_VITS16(**kwargs):
vision_model = timm.create_model('vit_small_mocov3_patch16_224', num_classes=0)
model = CLIP(embed_dim=512, vision_width=384, vision_model=vision_model, context_length=77, vocab_size=49408,
transformer_width=512, transformer_heads=8, transformer_layers=12, **kwargs)
return model
def SIMCLR_VITS16(**kwargs):
vision_model = timm.create_model('vit_small_mocov3_patch16_224', num_classes=0)
model = SIMCLR(vision_width=384, vision_model=vision_model, **kwargs)
return model
def SLIP_VITS16(**kwargs):
vision_model = timm.create_model('vit_small_mocov3_patch16_224', num_classes=0)
model = SLIP(embed_dim=512, vision_width=384, vision_model=vision_model, context_length=77, vocab_size=49408,
transformer_width=512, transformer_heads=8, transformer_layers=12, **kwargs)
return model
def CLIP_VITB16(embed_dim=512, **kwargs):
vision_model = timm.create_model('vit_base_patch16_224', num_classes=0)
model = CLIP(embed_dim=embed_dim, vision_width=768, vision_model=vision_model, context_length=77, vocab_size=49408,
transformer_width=512, transformer_heads=8, transformer_layers=12, **kwargs)
return model
def SIMCLR_VITB16(**kwargs):
vision_model = timm.create_model('vit_base_patch16_224', num_classes=0)
model = SIMCLR(vision_width=768, vision_model=vision_model, **kwargs)
return model
def SLIP_VITB16(**kwargs):
vision_model = timm.create_model('vit_base_patch16_224', num_classes=0)
model = SLIP(embed_dim=512, vision_width=768, vision_model=vision_model, context_length=77, vocab_size=49408,
transformer_width=512, transformer_heads=8, transformer_layers=12, **kwargs)
return model
def CLIP_VITL16(**kwargs):
vision_model = timm.create_model('vit_large_patch16_224', num_classes=0)
model = CLIP(embed_dim=512, vision_width=1024, vision_model=vision_model, context_length=77, vocab_size=49408,
transformer_width=512, transformer_heads=8, transformer_layers=12, **kwargs)
return model
def SIMCLR_VITL16(**kwargs):
vision_model = timm.create_model('vit_large_patch16_224', num_classes=0)
model = SIMCLR(vision_width=1024, vision_model=vision_model, **kwargs)
return model
def SLIP_VITL16(**kwargs):
vision_model = timm.create_model('vit_large_patch16_224', num_classes=0)
model = SLIP(embed_dim=512, vision_width=1024, vision_model=vision_model, context_length=77, vocab_size=49408,
transformer_width=512, transformer_heads=8, transformer_layers=12, **kwargs)
return model