big_vision
repository·main·Indexed 25 days ago
https://github.com/google-research/big_visionA high-performance research codebase for training large-scale vision and multimodal models using JAX, Flax, and TensorFlow Datasets, optimized for Cloud TPUs and GPUs. It includes implementations and configurations for models such as CapPa, CLIPPO, BiT, FlexiViT, and GIVT.
What's inside big_vision
- JetFormer is an autoregressive decoder-only transformer designed for joint generative modeling of raw images and text. Unlike models that rely on separately pretrained modality-specific encoders and decoders, JetFormer is trained to directly maximize the likelihood of raw data. It utilizes a normalizing flow model to obtain soft-token image representations, which serves as both an image encoder for perception and an image decoder for generation. This allows the model to perform high-fidelity text-to-image generation and robust image understanding without relying on complex mixtures of perceptual losses or pretrained autoencoders.
Overview of LiT (Locked-image text Tuning)
mainLiT (Zero-Shot Transfer with Locked-image text Tuning) is a method for multimodal research. It allows for zero-shot transfer by tuning text models to vision models while keeping the vision models locked.
Key resources:
Overview of Big Vision
mainBig Vision is a codebase designed for training large-scale vision models on Cloud TPU VMs or GPU machines. It is built using the Jax and Flax libraries and utilizes tf.data and TensorFlow Datasets for scalable, reproducible input pipelines.
Key features include:
- Seamless scaling from a single TPU core to distributed setups with up to 2048 TPU cores.
- Implementation of various research projects in architecture, multimodal learning, and training techniques.
- Support for large-scale vision experiments out-of-the-box.
Overview of PaliGemma Vision-Language Model
mainPaliGemma is an open vision-language model (VLM) inspired by PaLI-3. It is designed for a wide range of vision-language tasks, including:
- Image and short video captioning
- Visual Question Answering (VQA)
- Text reading
- Object detection
- Object segmentation
Architecture Details:
- Visual Encoder: SigLIP (specifically SigLIP-So400m/14).
- Language Model: Gemma (PaliGemma uses Gemma 2B; PaliGemma 2 uses Gemma 2 {2B, 9B, 27B}).
- Mechanism: Images are converted into "soft tokens" by the SigLIP encoder. Input text (the "prefix") is tokenized by Gemma. Image tokens and prefix tokens are concatenated and passed to the Gemma decoder with full block-attention to generate an output text (the "suffix") auto-regressively with masked attention.
Research Projects in Big Vision
mainThe codebase contains implementations and configurations for numerous research papers across several domains:
Architecture Research
Includes implementations for Transformers for Image Recognition (ViT), MLP-Mixer, UViM, FlexiViT, Dual PatchNorm, GIVT, Jet, and JetFormer.
Multimodal Research
Includes implementations for LiT (Locked-image Text Tuning), CLIPPO, SigLIP, SigLIP 2, CAPPA, Three Towers, PaLI, PaLI-3, LocCa, and PaliGemma/PaliGemma 2.
Training Techniques
Includes implementations for Knowledge Distillation, Sharpness-Aware Minimization (SAM), Surrogate Gap Minimization (GSAM), and VeLO.
Explore Image/text multimodal learning projects
mainThe
big_vision/configs/proj/image_text/directory contains configurations and Colab notebooks for various image/text multimodal learning projects.Key projects available in this directory include:
- LiT (Locked-image text Tuning): Focuses on zero-shot transfer. See
README_lit.mdfor details. - SigLIP 2: Focuses on multilingual vision-language encoders with improved semantic understanding, localization, and dense features. See
README_siglip2.mdfor details.
- LiT (Locked-image text Tuning): Focuses on zero-shot transfer. See
Prepare TFDS datasets
mainBig Vision usestensorflow_datasets(tfds). You can automatically download and prepare most datasets using thebig_vision.tools.download_tfds_datasetsmodule. For datasets requiring manual downloads (likeimagenet2012), you must manually place the official files in$TFDS_DATA_DIR/downloads/manual/before running the preparation tool.Set up Cloud TPU VMs
mainTo run on multi-host TPU slices, first create the TPU VMs usinggcloud. Then, copy thebig_visionrepository to all hosts and run therun_tpu.shscript to install dependencies across the cluster.Download PaliGemma checkpoints from Kaggle
mainPaliGemma checkpoints are hosted on Kaggle and require a Kaggle account and acknowledgment of the license terms. You must set your
KAGGLE_USERNAMEandKAGGLE_KEYenvironment variables to download them viacurl.Available checkpoint types include:
- Pretrained (pt):
pt-224,pt-448,pt-896. Use these for fine-tuning initialization. - Mixture (mix):
mix-224,mix-448. These are trained on a mixture of transfer tasks and are designed for out-of-the-box prediction with natural language prompts. - Transfers: Specialized checkpoints for specific tasks (e.g., Captioning, QA, Segmentation) available on Kaggle.
export KAGGLE_USERNAME= export KAGGLE_KEY= # Example for downloading a specific model export MODEL_NAME=paligemma2-3b-pt-224 mkdir ckpts/ cd ckpts/ curl -L -u $KAGGLE_USERNAME:$KAGGLE_KEY\ -o pt_3b_224.bf16.npz \ https://www.kaggle.com/api/v1/models/google/paligemma-2/jax/$MODEL_NAME/1/download/$MODEL_NAME.b16.npz- Pretrained (pt):
Train a CLIPPO model on TPU
mainTo launch CLIPPO training on Google Cloud TPU VMs, use the
run_tpu.shscript.Note on Data: By default, the configuration trains on MS-COCO Captions (via TFDS) and initializes with ImageNet21k weights for sanity checking. To train on large datasets like LAION-400M or YFCC-100M, you must first wrap your dataset using TensorFlow Datasets (TFDS) and update the config.
To train with custom data and ImageNet1k evaluations, append the following flags to the config path:
--config big_vision/configs/proj/clippo/train_clippo.py:test_with_coco=False,i1k_eval=Truegcloud alpha compute tpus tpu-vm ssh $NAME --zone=$ZONE --worker=all \ --command "TFDS_DATA_DIR=gs://$GS_BUCKET_NAME/tensorflow_datasets bash big_vision/run_tpu.sh big_vision.trainers.proj.image_text.contrastive --config big_vision/configs/proj/clippo/train_clippo.py --workdir gs://$GS_BUCKET_NAME/big_vision/workdir/`date '+%m-%d_%H%M'`"Fine-tune PaliGemma on a single T4 GPU
mainYou can perform light fine-tuning of PaliGemma using the
big_visioncodebase on a single free T4 GPU via Google Colab. This is useful for transferring the model to specific tasks or datasets of interest.https://colab.research.google.com/github/google-research/big_vision/blob/main/big_vision/configs/proj/paligemma/finetune_paligemma.ipynbTrain GIVT generative models
mainTo train GIVT (Generative Infinite-Vocabulary Transformers) models on ImageNet 2012, use the
big_vision.trainers.proj.givt.generativemodule. You must provide a config path and a Google Cloud Storage work directory.Note: The default
givt_imagenet2012.pyconfig uses Imagenette to allow for immediate testing without a manual ImageNet download. This will overfit quickly; for paper-reproducible results, download ImageNet and update your configuration.You can override configuration parameters by appending
:key=valueto the config path.python -m big_vision.trainers.proj.givt.generative \ --config big_vision/configs/proj/givt/givt_imagenet2012.py \ --workdir gs://$GS_BUCKET_NAME/big_vision/`date '+%m-%d_%H%M'` # Example with config override: python -m big_vision.trainers.proj.givt.generative \ --config big_vision/configs/proj/givt/givt_imagenet2012.py:model_size=large \ --workdir gs://$GS_BUCKET_NAME/big_vision/`date '+%m-%d_%H%M'`