How tosiyuki/llava-jp works
Project Overview
• This project is a multimodal training framework that adapts the LLaVA approach to train a lightweight but powerful Japanese LLM integrated with image processing capabilities. The goal is to create a chat/visual language model that accepts images and text inputs, processes them through a combined vision and language pipeline, and produces multimodal responses.
• From the README that there are multiple training stages (pretraining, fine-tuning, and LoRA tuning) and demo scripts for inference, so you must include both training and inference/lifecycle elements.
Identifying Main Components
• Data Sources:
• The “dataset” directory and associated data-preparation tools (e.g., tools/merge_data.py, tools/translate_llava.py) indicate that raw training and evaluation data is key.
• Model Architecture (in the “llava” directory):
• Core model components include:
• Vision Encoders: Modules such as clip_encoder.py, convnext_clip_encoder.py, vision_projector.py, and submodules in image_models.
• Language Processing: Different LLM variants are provided in llava_gpt2.py, llava_gpt_neox.py, and llava_llama.py.
• Integration/Architecture Bridging: The “llava_arch.py” module likely ties the vision and language components into a single multimodal architecture.
• Conversation Module: “llava/conversation.py” handles dialogue specifics.
• Utility Wrappers: “llava/s2wrapper” is used for integrating functionalities, potentially for converting between data formats or processing tree structures.
• Training Pipeline:
• The “llava/train” directory (with llava_trainer.py, dataset.py, arguments_dataclass.py) contains the training logic.
• Main training script “train_llava.py” and additional shell scripts (in scripts/pretrain and scripts/finetune directories) orchestrate the pretraining and fine-tuning processes.
• Inference/Demo Interfaces:
• Demo scripts such as “demo_llava.py” and “demo_llava_gradio.py” show how the model is deployed (e.g., using Gradio for interactive demos).
• Tools and Utility Scripts:
• Various tools (e.g., create_loss_graph.py, stair_caption_to_llava_format.py) assist in data processing, visualization, and format conversion during training/inference.
Relationships and Interactions
• Data Flow:
• Training Data from “dataset” is preprocessed (optionally using tools) and fed into the training pipeline.
• The training pipeline (scripts plus llava/train modules) loads the integrated model (vision encoder and language model combined via llava_arch) and performs learning.
• Model Composition:
• The vision part extracts features from images through encoder modules.
• The language part processes textual inputs (or conversation states) via one of the LLM modules.
• The conversation component synthesizes multimodal inputs and produces outputs.
• Training Stages:
• Pretraining stage uses “scripts/pretrain” for initial training.
• Fine-tuning and LoRA tuning are executed via “scripts/finetune” to refine performance.
• Inference:
• After training, demo scripts run the model in interactive settings (e.g., with Gradio).
Architectural Patterns and Technologies
• Modular design: The separation of vision encoders, language models, and integration (llava_arch) suggests a highly modular design.
• Multi-stage training: Clear division between pretraining and fine-tuning (including LoRA tuning) is visible.
• Pipeline orchestration: Shell scripts manage different training stages, which would need to be represented as separate orchestration components.
• External Libraries/Frameworks: Integration with Gradio for demos and the dependency on external models (e.g., from Hugging Face) should be noted.