Views
No views yet
Image → CLIP ViT-B/16 (frozen) → patch tokens (CLS + 196 patches, 768-dim)
│
▼
Perceiver Resampler (3 layers, 8 heads)
│
▼
64 compressed visual tokens (768-dim)
│
┌─────────────────────────────┼─────────────────────────────┐
▼ ▼ ▼
GPT-2 layer 3 ──tanh-gated── GPT-2 layer 7 ──tanh-gated── GPT-2 layer 11 ──tanh-gated──
cross-attn cross-attn cross-attn
│ │ │
└──────────────► GPT-2 self-attention stack (12 layers, frozen) ◄──────────────┘
│
▼
Generated captionopenai/clip-vit-base-patch16, frozen. The full patch-token
sequence (CLS + 196 patches) is passed through, not just the pooled embedding, so the
resampler has access to full spatial detail.[3, 7, 11]. Each gate is
tanh(alpha), zero-initialized so training starts as a pure, unmodified GPT-2 language
model and gradually learns how much to attend to the image.gpt2 weights and kept frozen during training.resampler.* and cross_blocks.* are trainable — everything else is frozen,
pretrained weight.| Text backbone | GPT-2 small (12 layers, 12 heads, 768-dim, 128 token context) |
| Vision encoder | CLIP ViT-B/16 (openai/clip-vit-base-patch16), frozen |
| Visual tokens | 64 (Perceiver Resampler, depth 3, 8 heads) |
| Cross-attention positions | GPT-2 layers 3, 7, 11 |
| Cross-attention gate | tanh(alpha), zero-init |
| Precision | float32 weights, torch.amp.autocast (fp16 matmuls) on GPU |
| Training data | AKCIT/coco2017-captioning (5 references/image) |
1pip install -r requirements.txt
2python app.pyconfig.json and model_trainable.safetensors from the Hub repo
set by the MODEL_REPO_ID environment variable (defaults to
gurumurthy3/gpt2vl-stackformer-v3) on startup, then reconstructs the frozen GPT-2 and
CLIP weights locally before loading the trained adapter tensors on top.app.py # Gradio Space — model definition + UI
config.json # architecture hyperparameters (on the Hub repo)
model_trainable.safetensors # trained adapter weights (resampler.* + cross_blocks.*)
samples/ # example images for the Quick Examples bar