SuperAPIAI Directory

TinyLLaVA_Factory

github.com · AI developer platforms

A Framework of Small-scale Large Multimodal Models.

Open website Alternatives
PricingOpen source开源项目(可免费自部署)
PlatformsLinux

About this tool

TinyLLaVA Factory is an open-source modular codebase for small-scale large multimodal models (LMMs), implemented using PyTorch and HuggingFace, with a focus on concise code implementation, ease of extending new features, and reproducible training results. According to the official description, with this codebase, developers can customize their own large multimodal models with less coding effort and fewer coding errors.

Main capabilities and integrated models:

  • Language models (LLMs) support OpenELM, TinyLlama, StableLM, Qwen, Gemma, and Phi.
  • Vision towers support CLIP, SigLIP, Dino, and combinations of CLIP and Dino.
  • Connectors support MLP, Qformer, and Resampler.
  • Training recipes support freeze/full/partial fine-tuning, as well as LoRA/QLoRA fine-tuning.

Related versions and paper timeline: In January 2025, the new work TinyLLaVA-Video was released; on August 13, 2024, a simple visualization tool for explaining TinyLLaVA predictions was added; on May 21, 2024, the paper "TinyLLaVA Factory: A Modularized Codebase for Small-scale Large Multimodal Models" was released; on May 15, 2024, the new codebase TinyLLaVA Factory was released, and the old codebase TinyLLaVABench was moved to the tinyllava_bench branch; on May 4, 2024, TinyLLaVA Demo was released (access password is '1234'); on February 21, 2024, the paper "TinyLLaVA: A Framework of Small-scale Large Multimodal Models" was released. The official statement says that the best model TinyLLaVA-Phi-2-SigLIP-3.1B outperforms existing 7B models such as LLaVA-1.5 and Qwen-VL in overall performance.

Usage:

  • Installation and environment: The official instructions note that its environment requirements differ from LLaVA, and it is strongly recommended to create the environment from scratch, with steps including cloning the repository and entering the directory, creating and activating a conda environment, installing dependency packages, and installing additional packages.
  • Data preparation: Please refer to the Data Preparation section in the official documentation.
  • Training: The official example is given for training an LMM using Phi-2. You need to replace the data path in scripts/train/train_phi.sh, replace output_dir in scripts/train/pretrain.sh, replace pretrained_model_path and output_dir in scripts/train/finetune.sh, and adjust the GPU ids (localhost) and per_device_train_batch_size in pretrain.sh and finetune.sh. Important hyperparameters used in pretraining and fine-tuning: global batch size = number of GPUs x per_device_train_batch_size x gradient_accumulation_steps. The official recommendation is to always keep the above global batch size and learning rate except for LoRA fine-tuning. conv_version is a hyperparameter used to select different chat templates for different LLMs: in the pretraining stage, all LLMs use the same conv_version, using pretrain; in the fine-tuning stage, Phi-2, StableLM, and Qwen-1.5 use phi, TinyLlama and OpenELM use llama, and Gemma uses gemma.
  • Evaluation: Please refer to the Evaluation section in the official documentation.
  • Model library: Includes TinyLLaVA-Phi-2-SigLIP-3.1B, TinyLLaVA-Gemma-SigLIP-2.4B, TinyLLaVA-OpenELM-450M-SigLIP-0.89B, TinyLLaVA-Qwen2-0.5B-SigLIP, TinyLLaVA-Qwen2.5-3B-SigLIP trained using TinyLLaVA Factory, as well as historical models trained using the old codebase TinyLLaVABench; if there are still models trained by the old codebase that you wish to continue using, the official side provides TinyLLaVA-3.The 1B example explains how to use the historical model.
  • Local Demo launch: you can run the local Web Demo; inference via CLI is also supported; official examples are provided for locally launching self-trained or official models as well as for quick inference scripts.
  • Custom fine-tuning: if you need to fine-tune TinyLLaVA with a custom dataset, please refer to the official instructions.

Custom extensions:

  • Adding a new LLM: you need to create a chat template file and a language model file under the tinyllava/data/template/ and tinyllava/model/llm/ directories respectively. The official example uses adding the Gemma model: first create tinyllava/data/template/gemma_template.py (used in the fine-tuning stage), and ensure that the labels returned by the _make_masks function conform to the format—the answer and eos token id are not masked, and other tokens are masked with -100; then create tinyllava/model/llm/gemma.py; finally create scripts/train/train_gemma.sh, configuring the corresponding LLM_VERSION and CONV_VERSION.
  • Adding a new vision tower: you need to implement a new vision tower class that inherits from the base class VisionTower. The official example uses the MoF vision tower: first create tinyllava/model/vision_tower/mof.py, then modify the training script with the corresponding VT_VERSION.
  • Adding a new connector: you need to implement a new connector class that inherits from the base class Connector. The official example uses the Linear connector: first create tinyllava/model/connector/linear.py, then modify the training script with the corresponding CN_VERSION.

Other notes: The Demo was built by Lei Zhao, Luche Wang, Kaijun Luo, and Junchen Wang. If you have any questions, you can submit an Issue or contact us via WeChat (WeChat ID: TinyLLaVA). The official request is that if the paper and code are helpful to your research, please give it a star and cite it. This codebase is built on the LLaVA project and uses data from the ShareGPT4V project.

Up/Down to navigate · Enter to open · ESC to closeBrowse all tools