Architectures / Multimodal
๐ CLIP ViT-B/32
Dual-encoder contrastive model โ a ViT image tower and a Transformer text tower projected into a shared embedding space (OpenAI 2021)
From Radford et al. (2021). Learning Transferable Visual Models From Natural Language Supervision. ICML 2021. This page is the graph, not the PDF: open it, edit it, verify it, export it.
Every number on this page is computed from the graph by the same functions the app runs, not written by hand.
When to pick it
Structure
40 layers. Output shapes are propagated from the input shape, batch dimension excluded.
| Layer | Type | Parameters | Output shape | |
|---|---|---|---|---|
| 1 | image | Input | shape=[3, 224, 224] | 3 ร 224 ร 224 |
| 2 | patch_embed | Patch Embed | embedDim=768, patchSize=32 | 49 ร 768 |
| 3 | vis_pos | Positional Encoding | embedDim=768, maxLen=50 | 49 ร 768 |
| 4 | vis_block_1 | Transformer Block | embedDim=768, numHeads=12, ffDim=3072 | 49 ร 768 |
| 5 | vis_block_2 | Transformer Block | embedDim=768, numHeads=12, ffDim=3072 | 49 ร 768 |
| 6 | vis_block_3 | Transformer Block | embedDim=768, numHeads=12, ffDim=3072 | 49 ร 768 |
| 7 | vis_block_4 | Transformer Block | embedDim=768, numHeads=12, ffDim=3072 | 49 ร 768 |
| 8 | vis_block_5 | Transformer Block | embedDim=768, numHeads=12, ffDim=3072 | 49 ร 768 |
| 9 | vis_block_6 | Transformer Block | embedDim=768, numHeads=12, ffDim=3072 | 49 ร 768 |
| 10 | vis_block_7 | Transformer Block | embedDim=768, numHeads=12, ffDim=3072 | 49 ร 768 |
| 11 | vis_block_8 | Transformer Block | embedDim=768, numHeads=12, ffDim=3072 | 49 ร 768 |
| 12 | vis_block_9 | Transformer Block | embedDim=768, numHeads=12, ffDim=3072 | 49 ร 768 |
| 13 | vis_block_10 | Transformer Block | embedDim=768, numHeads=12, ffDim=3072 | 49 ร 768 |
| 14 | vis_block_11 | Transformer Block | embedDim=768, numHeads=12, ffDim=3072 | 49 ร 768 |
| 15 | vis_block_12 | Transformer Block | embedDim=768, numHeads=12, ffDim=3072 | 49 ร 768 |
| 16 | vis_norm | LayerNorm | normalizedShape=768 | 49 ร 768 |
| 17 | to_channels_vis | Permute | 768 ร 49 | |
| 18 | vis_pool | GlobalAvgPool1D | 768 | |
| 19 | img_proj | Linear | outFeatures=512, inFeatures=768 | 512 |
| 20 | tokens | Input | shape=[77] | 77 |
| 21 | tok_embed | Embedding | 77 ร 512 | |
| 22 | txt_pos | Positional Encoding | embedDim=512, maxLen=77 | 77 ร 512 |
| 23 | txt_block_1 | Transformer Block | embedDim=512, numHeads=8, ffDim=2048 | 77 ร 512 |
| 24 | txt_block_2 | Transformer Block | embedDim=512, numHeads=8, ffDim=2048 | 77 ร 512 |
| 25 | txt_block_3 | Transformer Block | embedDim=512, numHeads=8, ffDim=2048 | 77 ร 512 |
| 26 | txt_block_4 | Transformer Block | embedDim=512, numHeads=8, ffDim=2048 | 77 ร 512 |
| 27 | txt_block_5 | Transformer Block | embedDim=512, numHeads=8, ffDim=2048 | 77 ร 512 |
| 28 | txt_block_6 | Transformer Block | embedDim=512, numHeads=8, ffDim=2048 | 77 ร 512 |
| 29 | txt_block_7 | Transformer Block | embedDim=512, numHeads=8, ffDim=2048 | 77 ร 512 |
| 30 | txt_block_8 | Transformer Block | embedDim=512, numHeads=8, ffDim=2048 | 77 ร 512 |
| 31 | txt_block_9 | Transformer Block | embedDim=512, numHeads=8, ffDim=2048 | 77 ร 512 |
| 32 | txt_block_10 | Transformer Block | embedDim=512, numHeads=8, ffDim=2048 | 77 ร 512 |
| 33 | txt_block_11 | Transformer Block | embedDim=512, numHeads=8, ffDim=2048 | 77 ร 512 |
| 34 | txt_block_12 | Transformer Block | embedDim=512, numHeads=8, ffDim=2048 | 77 ร 512 |
| 35 | txt_norm | LayerNorm | normalizedShape=512 | 77 ร 512 |
| 36 | to_channels_txt | Permute | 512 ร 77 | |
| 37 | txt_pool | GlobalAvgPool1D | 512 | |
| 38 | txt_proj | Linear | outFeatures=512, inFeatures=512 | 512 |
| 39 | similarity | MatMul | 512 | |
| 40 | logits | Output | 512 |
What the verifier says
The same 43 single-graph checks that run on every edit in the app, on this graph.
No finding. Shapes propagate end to end, every divisibility condition holds, and no advisory rule fires. See the checks.
The PyTorch it exports
Generated from the graph above. First 46 lines; the app exports the whole file, plus the training loop, the data contract and a deploy bundle.
# Architecture designed with Neurarch: https://neurarch.com
# PyTorch: compatible with Python 3.8+ and torch>=1.12
# Colab: pip install torch torchvision (usually pre-installed)
import torch
import torch.nn as nn
import torch.nn.functional as F
from typing import Tuple
class CLIPViT_B32(nn.Module):
def __init__(self):
super().__init__()
self.patchEmbed_1 = nn.Conv2d(3, 768, kernel_size=32, stride=32) # Patch embedding (ViT-style)
self.transformerBlock_1 = nn.TransformerEncoderLayer(d_model=768, nhead=12, dim_feedforward=3072, batch_first=True)
self.transformerBlock_2 = nn.TransformerEncoderLayer(d_model=768, nhead=12, dim_feedforward=3072, batch_first=True)
self.transformerBlock_3 = nn.TransformerEncoderLayer(d_model=768, nhead=12, dim_feedforward=3072, batch_first=True)
self.transformerBlock_4 = nn.TransformerEncoderLayer(d_model=768, nhead=12, dim_feedforward=3072, batch_first=True)
self.transformerBlock_5 = nn.TransformerEncoderLayer(d_model=768, nhead=12, dim_feedforward=3072, batch_first=True)
self.transformerBlock_6 = nn.TransformerEncoderLayer(d_model=768, nhead=12, dim_feedforward=3072, batch_first=True)
self.transformerBlock_7 = nn.TransformerEncoderLayer(d_model=768, nhead=12, dim_feedforward=3072, batch_first=True)
self.transformerBlock_8 = nn.TransformerEncoderLayer(d_model=768, nhead=12, dim_feedforward=3072, batch_first=True)
self.transformerBlock_9 = nn.TransformerEncoderLayer(d_model=768, nhead=12, dim_feedforward=3072, batch_first=True)
self.transformerBlock_10 = nn.TransformerEncoderLayer(d_model=768, nhead=12, dim_feedforward=3072, batch_first=True)
self.transformerBlock_11 = nn.TransformerEncoderLayer(d_model=768, nhead=12, dim_feedforward=3072, batch_first=True)
self.transformerBlock_12 = nn.TransformerEncoderLayer(d_model=768, nhead=12, dim_feedforward=3072, batch_first=True)
self.layerNorm_1 = nn.LayerNorm(768)
self.linear_1 = nn.Linear(768, 512)
self.embedding_1 = nn.Embedding(49408, 512)
self.transformerBlock_13 = nn.TransformerEncoderLayer(d_model=512, nhead=8, dim_feedforward=2048, batch_first=True)
self.transformerBlock_14 = nn.TransformerEncoderLayer(d_model=512, nhead=8, dim_feedforward=2048, batch_first=True)
self.transformerBlock_15 = nn.TransformerEncoderLayer(d_model=512, nhead=8, dim_feedforward=2048, batch_first=True)
self.transformerBlock_16 = nn.TransformerEncoderLayer(d_model=512, nhead=8, dim_feedforward=2048, batch_first=True)
self.transformerBlock_17 = nn.TransformerEncoderLayer(d_model=512, nhead=8, dim_feedforward=2048, batch_first=True)
self.transformerBlock_18 = nn.TransformerEncoderLayer(d_model=512, nhead=8, dim_feedforward=2048, batch_first=True)
self.transformerBlock_19 = nn.TransformerEncoderLayer(d_model=512, nhead=8, dim_feedforward=2048, batch_first=True)
self.transformerBlock_20 = nn.TransformerEncoderLayer(d_model=512, nhead=8, dim_feedforward=2048, batch_first=True)
self.transformerBlock_21 = nn.TransformerEncoderLayer(d_model=512, nhead=8, dim_feedforward=2048, batch_first=True)
self.transformerBlock_22 = nn.TransformerEncoderLayer(d_model=512, nhead=8, dim_feedforward=2048, batch_first=True)
self.transformerBlock_23 = nn.TransformerEncoderLayer(d_model=512, nhead=8, dim_feedforward=2048, batch_first=True)
self.transformerBlock_24 = nn.TransformerEncoderLayer(d_model=512, nhead=8, dim_feedforward=2048, batch_first=True)
self.layerNorm_2 = nn.LayerNorm(512)
self.linear_2 = nn.Linear(512, 512)
def forward(self, src, tgt=None):
# image shape: [3,224,224]
For agents
This architecture is machine-readable end to end. An agent can list the set, fetch this graph, edit it, and have the edit verified before any GPU time is spent.