wikillm

Paper · 2022-02-07 · cs.CV, cs.CL

OFA: Unifying Architectures, Tasks, and Modalities Through a Simple Sequence-to-Sequence Learning Framework

OFA is one encoder-decoder Transformer for vision, language and cross-modal tasks. Each task is an instruction plus inputs that yields tokens (text, image codes or box bins). Pretrained on 20M public image-text pairs and unimodal data, it reports SOTA on VQA test-std (82.0), SNLI-VE and COCO CIDEr-optimised captioning (154.9). Author-reported; unimodal results are competitive, not always best.

Vision-language pre-trainingMultimodal language modelInstruction tuningConstrained decodingmultimodalpretrainingsequence-to-sequence

arXivPDFCodeMarkdown14 min read

AI-compiled by claude-haiku-5-5 on 2026-10-19, not yet reviewed by a human. Every claim cites its source; check it when a detail matters.

In plain words

Most systems that handle pictures and text are built for one job: one model writes captions, another answers questions about a picture, a third draws images. OFA tries to fold all of these into one model. It reads a short written instruction together with an input, which can be a picture, some text, or both, and it writes its answer as a sequence of tokens.

Words, picture fragments and box coordinates all share one vocabulary, so the same architecture and training recipe covers captioning, visual question answering, pointing at a region from a description, drawing an image, and plain language tasks. The instruction tells the model which job to do, so new tasks do not need new output layers.

The authors report strong results from a comparatively small pretraining set of public image-text pairs. Whether a single model beats specialised ones depends on the task, and the numbers on this card are the authors' own.

TL;DR

  • One encoder-decoder Transformer for vision, language and cross-modal tasks. Every task, pretraining included, is generation from an instruction plus inputs §1 §3.2.
  • Text tokens, discrete image codes and location (box) tokens share one vocabulary §3.1.
  • Pretrained on 20M public image-text pairs plus unimodal image and text data §1 §3.3. The pretraining set is much smaller than the 1.8B pairs of SimVLM tab. 2 caption.
  • Reports the best VQA test-std (82.0), SNLI-VE test (91.2) and COCO CIDEr-optimised captioning (154.9) among the models it lists tab. 2 tab. 3. Results are author-reported.
  • Unimodal results are competitive but not always best: ImageNet-1K top-1 is 85.6 against BEiT-384-L's 86.3 tab. 8.

Problem

Pretrained vision-language models often need task-specific parts: heads, adapters or soft prompts. Their pretraining and finetuning objectives also differ, and many rely on an object detector, which fails on open-domain images §1. The paper asks for a model that is task-agnostic (one task format for pretraining and finetuning), modality-agnostic (one input and output format for all modalities) and task-comprehensive (enough task variety to generalise) §1.

The paper argues that existing methods fail on at least one of these: they add learnable components for finetuning, use task-specific formulations, or entangle modality representation with detected objects §1. The headline efficiency comparison is with SimVLM, which uses 1.8B image-text pairs tab. 2 caption.

Method

Everything is a sequence-to-sequence problem. The input is an image (optional), an instruction and optional text. The output is a sequence over one shared vocabulary §3.1 §3.2. The architecture is a Transformer encoder-decoder used for every pretraining, finetuning and zero-shot task §3.1.

Architecture §3.1

  1. Image input: the first three ResNet blocks turn the image into patch features, following CoAtNet and SimVLM §3.1 app. A.2. Patch size is 16 app. A.2.
  2. Text input: byte-pair encoding (BPE), as in GPT and BART §3.1.
  3. Encoder and decoder are both stacks of Transformer layers. The decoder adds cross-attention to the encoder output §3.1.
  4. Stability changes: head scaling in self-attention, a post-attention LayerNorm, and a LayerNorm after the first FFN layer, following NormFormer §3.1. The released pretraining scripts enable all three (--scale-attn --scale-fc --scale-heads) pretrain_ofa_large.sh.
  5. Positions: two absolute position embeddings (text and image), decoupled from token and patch embeddings as in TUPE. Relative position bias is 1D for text and 2D for images §3.1.
  6. Embeddings and output softmax share parameters app. A.2.

Shared vocabulary §3.1

  • Text: BPE subwords.
  • Images: discrete image codes from an image quantiser (VQGAN-style). A 256×256 image becomes a 16×16 code sequence §3.1.
  • Boxes: each corner coordinate is uniformly discretised into integer location tokens. Object labels are plain BPE §3.1. The repository uses 1000 bins pretrain_ofa_large.sh and rounds the normalised coordinate times (bins − 1) unify_dataset.py.

Pseudocode of the input side

Pseudocode
# Image side: the first three ResNet blocks turn a picture into patches  [§3.1]
# [app. A.2]
def image_patches(image):
    # Output: (P, d) patch features, where d is the hidden size
    feature_map = resnet_first_three_blocks(image)
    return flatten_to_patches(feature_map)

# Text side: byte-pair encoding into subword ids, then embedding  [§3.1]
def text_tokens(text):
    # Output: ids from the shared BPE vocabulary
    return bpe_encode(text)

# Boxes become location tokens; labels stay BPE  [§3.1]
def box_tokens(x1, y1, x2, y2, num_bins):
    # Coordinates are normalised to [0, 1] before discretisation
    # [code: raw/code/2202.03052/data/pretrain_data/unify_dataset.py#L303-L306]
    bins = [round(c * (num_bins - 1)) for c in (x1, y1, x2, y2)]
    return [location_token(b) for b in bins]

# Target-side image: a quantiser maps the picture to discrete codes  [§3.1]
def image_codes(image):
    # A 256 x 256 image becomes a 16 x 16 sequence of code ids  [§3.1]
    return quantiser_encode(image)

Training objective §3.4

The loss is the negative log-likelihood of the target tokens given the image x, the instruction s and earlier target tokens. The paper writes it inline and does not number it.

Pseudocode
# Next-token cross-entropy over the target sequence  [§3.4]
def training_loss(model, source_tokens, target_tokens):
    # Teacher forcing: the decoder reads the target shifted right
    logits = model(source_tokens, shift_right(target_tokens))
    # Sum of -log P(y_i | y_<i, x, s) over all target positions  [§3.4]
    return cross_entropy_sum(logits, target_tokens)

Inference §3.4 app. B

Pseudocode
# Beam search over the shared vocabulary  [§3.4] [app. A.3]
def generate(model, source_tokens, beam_size, candidate_trie=None):
    beams = [start_beam()]
    for step in range(max_length):
        # Score every next token for each live beam  [§3.4]
        log_probs = model.next_token_log_probs(beams, source_tokens)
        # Closed label sets: tokens that leave the trie are masked  [app. B]
        if candidate_trie is not None:
            log_probs = mask_outside_trie(log_probs, beams, candidate_trie)
        # Keep the best beam_size continuations  [§3.4]
        beams = top_k_extensions(beams, log_probs, beam_size)
    return best_beam(beams)

Pretraining tasks §3.2

Cross-modal (image-text data):

  • Visual grounding: instruction "Which region does the text x^t describe?"; target is the box tokens.
  • Grounded captioning: the inverse. Instruction "What does the region describe?" followed by the region's box tokens; target is the caption.
  • Image-text matching: instruction "Does the image describe x^t?"; target "Yes" or "No". The negative pairs the image with a substituted caption.
  • Image captioning: instruction "What does the image describe?".
  • VQA: the question is the input and the answer is the target.

Unimodal:

  • Image infilling: the middle of the image is masked. Instruction "What is the image in the middle part?"; target is the image codes §3.2. Code: the masked square spans the central region of a 2×code-size canvas unify_dataset.py.
  • Object detection: instruction "What are the objects in the image?"; target is the sequence of box tokens and labels §3.2.
  • Text infilling: BART-style span masking §3.2. The repository's masking default is ratio 0.3 with Poisson span lengths unify_task.py.

Masking for text infilling (cites are for the repository's implementation)

Pseudocode
# Text infilling: mask word spans, then reconstruct the text  [§3.2]
def mask_text(subword_ids, mask_ratio=0.3):
    # Mask about mask_ratio of the words; span lengths follow a Poisson law
    # [code: raw/code/2202.03052/tasks/pretrain_tasks/unify_task.py#L66-L80]
    masked_ids = span_mask(subword_ids, mask_ratio)
    # Instruction used by the repository; the paper gives none for this task
    # [code: raw/code/2202.03052/data/pretrain_data/unify_dataset.py#L376]
    source = instruction_tokens(masked_ids)
    return source, subword_ids

Pretraining data §3.3 app. A.1 tab. 11

TypeTaskSourceImagesSamples
Vision & languageImage captioning and image-text matchingCC12M, CC3M, SBU, COCO, VG captions14.78M15.25M
Vision & languageVQAVQAv2, VG-QA, GQA178K2.92M
Vision & languageVisual grounding and grounded captioningRefCOCO, RefCOCO+, RefCOCOg, VG captions131K3.20M
VisionDetectionOpenImages, Object365, VG, COCO2.98M3.00M
VisionImage infillingOpenImages, YFCC100M, ImageNet-21K36.27Mnot applicable
LanguageText infillingPile (filtered)not applicable140 GB storage

Images appearing in downstream validation and test sets were excluded §3.3.

Model sizes §3.5 tab. 1

The paper scales five models from 33M to 930M parameters (§3.5 says 940M; the table says 930M). Base and Large are sized like BART-Base and BART-Large §3.5.

Hyperparameters

Model configuration tab. 1:

NameValueWhereNotes
OFA Tiny33M params; ResNet50; hidden 256; FFN 1024; 4 heads; 4 enc / 4 dec layerstab. 1
OFA Medium93M; ResNet101; hidden 512; FFN 2048; 8 heads; 4 enc / 4 dectab. 1
OFA Base182M; ResNet101; hidden 768; FFN 3072; 12 heads; 6 enc / 6 dectab. 1
OFA Large472M; ResNet152; hidden 1024; FFN 4096; 16 heads; 12 enc / 12 dectab. 1
OFA Huge930M; ResNet152; hidden 1280; FFN 5120; 16 heads; 24 enc / 12 dectab. 1§3.5 says 940M

Pretraining app. A.2:

NameValueWhereNotes
OptimizerAdamW, betas (0.9, 0.999), eps 1e-8app. A.2Repository: adam with the same betas and eps pretrain_ofa_large.sh
Peak learning rate2e-4app. A.2Repository pretraining scripts use 1e-4 pretrain_ofa_large.sh. See Paper vs code
LR schedulelinear decay, warmup ratio 0.01app. A.2Repository: polynomial decay with power 1.0, i.e. linear polynomial_decay_schedule.py
Weight decay0.01app. A.2Repository matches pretrain_ofa_large.sh
Dropout0.1app. A.2Repository matches pretrain_ofa_large.sh
Stochastic depth0.1 in encoder and decoder; none in conv blocksapp. A.2Repository: 0.1 encoder and decoder, 0.0 for ResNet pretrain_ofa_large.sh
Label smoothingnot statedapp. A.2Repository: 0.0 pretrain_ofa_large.sh
Gradient clippingnot statednot applicableRepository: clip norm 5.0 pretrain_ofa_large.sh
Batch composition2048 vision-language, 256 detection, 256 image-only, 512 text-only per batchapp. A.2Not checkable from the scripts: they run one GPU with batch 4 pretrain_ofa_large.sh
Training lengthat least 300K stepsapp. A.2Repository sets max_epoch=50 pretrain_ofa_large.sh
Image resolution256 (Tiny, Medium); 384 (Base); 384 then 480 (Large, Huge)app. A.2See Paper vs code
Patch size16 × 16app. A.2
Sampled patchesPaper: random patch sampling gave no additional benefitapp. A.2Repository sets 196 per example. See Paper vs code
Text lengthmax 256 for encoder and decoderapp. A.2See Paper vs code
InitialisationBART-Base and BART-Large weights for Base and Large; other sizes pretrained with the BART recipeapp. A.2
Image codes256×256 input, 16×16 codes§3.1

Finetuning app. A.3:

TaskSettingWhere
Image captioningCross-entropy: 2 epochs, batch 128, lr 1e-5, label smoothing 0.1. Then CIDEr optimisation: 3 epochs, batch 64, dropout and stochastic depth offapp. A.3
VQA40,000 steps, batch 512, lr 5e-5, label smoothing 0.1. Input 480 (640 for Large and Huge). EMA decay 0.9999. Trie over the 3,129 most frequent answers. Position embeddings interpolatedapp. A.3
Visual entailment (SNLI-VE)6 epochs, lr 2e-5, batch 256. Labels mapped to yes/maybe/no. Trie over the labelsapp. A.3
RefCOCO, RefCOCO+, RefCOCOgAbout 10 epochs, batch 128, lr 3e-5, label smoothing 0.1. Input 512. Maximum generated length 4app. A.3
Text-to-imageStage 1: about 50 epochs, batch 512, lr 1e-3. Stage 2 (CLIPSIM): 5,000 steps, batch 32, lr 1e-6. Evaluation: 24 samples at 256, best one chosen by CLIPapp. A.3
ImageNet-1K32 epochs, batch 256, lr 5e-5, label smoothing 0.1, LE 0.75 encouraging loss, RandAug, random erasing, Mixup and CutMix with probability 0.5 (alpha 0.8 and 1.0). Trie over 1,000 labelsapp. A.3
GLUEGrid: epochs {5, 7, 10}, lr {3e-5, 5e-5, 6e-5, 7e-5, 1e-4}, batch {32, 64, 128}, weight decay {0.01, 0.05}, dropout {0.0, 0.1}. Best dev score per taskapp. A.3
Gigaword6 epochs, batch 512, lr 1e-4, label smoothing 0.1, input 512. Beam 6, length penalty 0.7, maximum output 32app. A.3

Downstream instructions tab. 12: captioning "What does the image describe?"; VQA the question itself; visual entailment "Can image and text1 ... imply text2 ...?"; referring expressions "Which region does the text ... describe?"; image generation "What is the complete image? caption: ..."; GLUE tasks as yes/no questions.

Results

Author-reported. Setup: pretraining on the public data in tab. 11; models from Tiny to Huge tab. 1. Baselines are the strongest listed prior work in each table. Hardware is not stated in the LaTeX source.

Task (setting)MetricBest prior in tableOFA (author-reported)Source
VQA, test-stdaccuracy80.4 (Florence)82.0tab. 2
SNLI-VE, testaccuracy86.3 (SimVLM)91.2tab. 2
COCO captions, cross-entropyCIDEr143.3 (SimVLM)145.3tab. 3
COCO captions, CIDEr optimisationCIDEr145.5 (LEMON)154.9tab. 3
RefCOCO val / testA / testBAcc@0.588.29 / 90.42 / 83.06 (UNICORN)92.04 / 94.03 / 88.44tab. 4
RefCOCO+ val / testA / testBAcc@0.580.30 / 85.05 / 71.88 (UNICORN)87.86 / 91.70 / 80.71tab. 4
RefCOCOg val-u / test-uAcc@0.583.44 / 83.93 (UNICORN)88.07 / 88.78tab. 4
Text-to-image, COCOFID, lower is better12.2 (GLIDE)10.5tab. 5
Text-to-image, COCOIS, higher is better27.2 (NÜWA)31.1tab. 5
Text-to-image, COCOCLIPSIM, higher is better34.3 (NÜWA)34.4tab. 5
Gigaword summarisationROUGE-1 / -2 / -L39.71 / 20.37 / 36.88 (UNIMO)39.81 / 20.66 / 37.11tab. 7
ImageNet-1K, top-1accuracy86.3 (BEiT-384-L/16)85.6tab. 8

GLUE tab. 6, OFA per task: SST-2 96.6, RTE 91.0, MRPC 91.7, QQP 92.5, MNLI 90.2, QNLI 94.8. OFA is not best on every task: XLNet has 97.0 on SST-2 and DeBERTa 91.9 on MRPC tab. 6.

Zero-shot tab. 9: OFA-Base against Uni-Perceiver. SST-2 71.6 vs 70.6; RTE 56.7 vs 55.6; MRPC F1 79.5 vs 76.1; QQP F1 54.0 vs 53.6; QNLI 51.4 vs 51.0; MNLI 37.3 vs 49.6 (worse); SNLI-VE dev/test 49.71 / 49.18 (Uni-Perceiver not listed).

Ablations, pretrained 250K steps, Base size tab. 10: full model CIDEr 135.6, VQA 76.0, ImageNet 82.2, image generation FID 20.8 / CLIPSIM 31.6 / IS 21.5. Removing text infilling: 134.8, 75.6, 83.2, 20.3 / 31.7 / 21.8. Removing image infilling: 136.3, 76.3, 81.8, 23.2 / 31.0 / 20.0. Removing detection: 133.3, 75.4, 81.4, 20.9 / 31.5 / 21.6. Removing grounding: 134.2, 75.5, 82.0, 21.2 / 31.5 / 21.5.

Trie-based search on Base, 250K steps tab. 13: VQA 76.03 vs 75.86 without Trie; SNLI-VE 89.2 vs 89.0; ImageNet 82.2 vs 81.9; MRPC F1 90.6 vs 90.1; QQP F1 88.4 vs 88.2.

Paper vs code

The official repository is linked from the abstract: https://github.com/OFA-Sys/OFA, Apache-2.0, commit a36b91ce86ff105ac8d9e513aa88f42b85e33479. The following differences were checked against the repository's scripts and code. The pretraining scripts are single-GPU examples.

Pitfalls

  • Batch sizes are not reproducible from the scripts. The scripts use one GPU with batch 4 pretrain_ofa_large.sh pretrain_ofa_large.sh. The paper's per-step batch composition is not reproduced by these scripts, and the per-device split is not stated.
  • Data is not in the repository. The pretraining TSV files, the negative-caption lists and the VQA answer vocabulary must be rebuilt from public sources. The paper describes filtering out downstream validation and test images §3.3; the repository files read here contain no such filter.
  • Headline data size. The abstract says 20M image-text pairs. Table 11 lists 15.25M captioning/ITM samples, 2.92M VQA samples and 3.20M grounding samples tab. 11. The text does not explain how the two figures relate.
  • Model size. §3.5 says 940M parameters; Table 1 says 930M for Huge §3.5 tab. 1.
  • Trie-constrained decoding gives small gains in the authors' ablation: 0.17 to 0.5 points on each task tab. 13. The paper's stated reason for it is that the model may otherwise generate labels outside the closed set §3.4.
  • Image generation sampling differs from the baselines. OFA samples 24 images and keeps the best by CLIP app. A.3. The paper says DALLE uses 512 samples and CogView and NÜWA use 60 §4.1. FID and IS are not computed under the same sampling budget.
  • Zero-shot is brittle. The paper says results are highly sensitive to instruction wording and that sentence-pair tasks score below 60% §4.3. On MNLI, OFA-Base scores 37.3 against Uni-Perceiver's 49.6 tab. 9.
  • No variance reported. The ablation tables show one number per setting, with differences of 0.2 to 0.5 points in several rows tab. 10 tab. 13. The tables give no spread across runs.
  • Table and section numbers were counted from the LaTeX source of arXiv v2 (updated 2022-06-01), not from a rendered PDF. Check against the PDF before citing a number to a reader.
  • No images on this card. The paper's figures show generation and grounding examples. They are described here only by section (§4.1, §4.3, app. C).

Lineage

  • Builds on: BART (architecture and BPE tokenizer) §3.1 app. A.2; VQGAN-style image quantisation §3.1; patch features from ResNet blocks, following CoAtNet and SimVLM §3.1; discrete coordinate tokens following Pix2Seq §3.1; instruction-based task formatting from FLAN and T0 §3.2; NormFormer stability changes §3.1; TUPE position decoupling §3.1; BEiT-style masked image modelling §3.2; E2E-VLP for detection-style pretraining §3.2. The paper calls this work the latest in the authors' M6 series §1.
  • Compared against: SimVLM, VLMo, UNICORN, VinVL, UNIMO, LEMON, ALBEF, METER, Florence (classification and captioning) tab. 2 tab. 3; MDETR and UNICORN (grounding) tab. 4; DALLE, CogView, GLIDE and NÜWA (image generation) tab. 5; Uni-Perceiver (zero-shot) tab. 9. For unimodal tasks, RoBERTa, XLNet, ELECTRA, DeBERTa, BEiT and MAE tab. 6 tab. 8.
  • Superseded by: not stated in content already on this wiki.

Source and license

Adapted from “OFA: Unifying Architectures, Tasks, and Modalities Through a Simple Sequence-to-Sequence Learning Framework” by Peng Wang, An Yang, Rui Men, Junyang Lin, Shuai Bai, Zhikang Li, Jianxin Ma, Chang Zhou, Jingren Zhou, Hongxia Yang (arXiv:2202.03052), used under CC BY-SA 4.0. Changes: condensed and restructured for implementation, with tables, equations and algorithms taken from the paper and its code, each cited to its source. Not affiliated with or endorsed by the authors. This page is licensed under CC BY-SA 4.0. Code citations refer to https://github.com/OFA-Sys/OFA at commit a36b91ce86ff (Apache-2.0). Any quoted code is shown under that license.