How tinyllava/tinyllava_factory works
Major Components
• Language Model (LLM) Module – This component includes various LLM implementations (e.g., OpenELM, TinyLlama, StableLM, Qwen, Gemma, Phi). It resides in the “tinyllava/model/llm” directory and is responsible for text generation and conversational capabilities.
• Vision Tower Module – Located under “tinyllava/model/vision_tower”, this part handles image processing. Different vision models (CLIP, SigLIP, Dino, etc.) are supported.
• Connector Module – Found in “tinyllava/model/connector”, this component integrates the outputs of the vision tower with the LLM by transforming visual representations to a form the text model can process (via MLP, Qformer, or Resampler).
• Data Processing & Templates – Under “tinyllava/data” and specifically “tinyllava/data/template”, the project defines how to format inputs and convert raw data (images and text) into training-ready sequences.
• Training & Recipes – The “tinyllava/train” and “tinyllava/training_recipe” folders hold the training pipelines, including pretraining, finetuning, and specialized recipes such as LoRA/QLoRA tuning.
• Evaluation Suite – All evaluation scripts in “tinyllava/eval” and the “scripts/eval” folder enable running benchmarks (e.g., VQA, GQA, SQA) on trained multimodal models.
• Serving & Demo – The “tinyllava/serve” folder contains the web app and CLI interfaces used for inference (Gradio-based and script-driven demos).
• Ancillary Scripts – The “scripts” folder (e.g., training and conversion scripts) provides automation for data preparation, training runs, and evaluation across different configurations.
Relationships and Data Flow
• Input Data Pipelines: Start with raw data preparation (images and text) that are processed by modules under “tinyllava/data” (and supported by conversion scripts under “scripts/convert_*”). Clearly label data conversion and template formatting.
• Model Training Workflow: Create a flow from data preparation → training recipes → separate pipelines for pretraining and finetuning. Show how training scripts in “scripts/train” invoke training methods in “tinyllava/train” and use modules from “tinyllava/model” (LLM, vision tower, connector) as well as utils.
• Modular Registries: Note that the project uses factory/registration mechanisms (e.g., @register_template, @register_llm, etc.). Represent these as connectors within the system design that allow plugging in additional models or modules.
Architectural Patterns & Design Principles
• Technology Stack: Annotate components with the frameworks/technologies they use (e.g., PyTorch for model implementations, HuggingFace for transformers and tokenizers, Gradio for demos).
Final Assembly
1. Data Preparation: Raw data → Preprocessing & Template Formatting (scripts + tinyllava/data)
2. Model Construction: Modular assembly of LLM, Vision Tower, and Connector (tinyllava/model submodules)
3. Training Workflow: Training recipes (tinyllava/train, training_recipe) controlled by bash/Python scripts (scripts/train)
4. Evaluation & Inference: Evaluation scripts and serving interfaces (tinyllava/eval, tinyllava/serve, tinyllava_visualizer)
• Within the “Model Construction” area, show how the connectors allow integration between text and image models, emphasizing the modular design.