# allenai/molmo architecture

> Architecture diagram of the GitHub repository allenai/molmo, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/allenai/molmo
- Repository: https://github.com/allenai/molmo

## Overview

##### Project Type & Purpose
- Molmo is a full-stack ML project for multimodal (vision + language) model training and evaluation.
- Its purpose is to facilitate the development of open, state-of-the-art multimodal models with support for pretrained models, multitask training (including dense captioning, visual question answering, and multiple evaluation benchmarks), and integration with external datasets and libraries (e.g., Hugging Face datasets, Megablocks).
- The README clearly shows that the project supports both training (pre-training, fine-tuning, multitask training) and evaluation workflows, and it includes multiple entry-points for various tasks (captions, downstream evaluation, etc.).

##### Main Components & Their Roles (Identify these
● Data Acquisition & Pre-processing
- Components: olmo/data (with modules such as academic_datasets, collator, dataset, etc.), olmo/hf_datasets (interface for Hugging Face datasets), and scripts/download_data.py.
- Functionality: Handling data ingestion (downloading, dataset formatting, collating), data preprocessing, and integration with external data sources (PixMo and more).
● Model Components & Core Libraries
- Components: olmo/model.py, olmo/config.py, olmo/tokenizer.py, olmo/image_vit.py, olmo/initialization.py, and olmo/optim.py.
- Functionality: Defining the multimodal model’s architecture, creating configurations, managing tokenization, initializing and incorporating different model backbones (vision encoders such as CLIP and language models such as Qwen2).
● Training Pipelines
- Components: launch_scripts (train_captioner.py, train_multitask_model.py) and scripts/train.py.
- Functionality: Creating training jobs including single-node debugging runs, multi-node distributed training (using torchrun), and multitask training configurations. Also integrates logging (W&B) and supports training adjustments (FS-DP for large models, use of environment variables).
● Evaluation & Inference Modules
- Components: olmo/eval (evaluators & various task-specific evaluation scripts) and launch_scripts/eval_downstream.py.
- Functionality: Running in-depth evaluations on various tasks, handling high-resolution and low-resolution evaluation settings, and supporting both local evaluation and alternative evaluation tools (VLMEvalKit). Uses directional flags (e.g., --fsdp, --device_batch_size) to fine-tune evaluation performance.
● Utility and Supporting Scripts
- Components: scripts (e.g., build_submission_file.py, convert_hf_to_molmo.py, dataset_visualize.py, download_data.py) and utilities in launch_scripts/utils.py.
- Functionality: Converting pretrained models to the Molmo-compatible format, visualizing datasets, building submission files, testing (in tests/), and overall project management (configuration, checkpoint management, beam search).

##### Relationships & Data Flow (How to represent interactions)
- Processed data then flows into the Model Components (feeding both vision and language models) where configuration files (olmo/config.py) set up the training architecture.
- Outputs flow into the Training Pipeline, where the training scripts launch jobs and manage distributed processing (using torchrun). This block interacts with both the model component for forward passes and external logging services (W&B).
- Once trained, model checkpoints and configurations are utilized by the Evaluation & Inference block. This block may also interface with external evaluation frameworks (e.g., VLMEvalKit) and generate performance metrics.
- The Utility Scripts work side-by-side and are invoked by each of these blocks as helper functions (e.g., conversion of HF models, data visualization).

##### Architectural Patterns & Design Principles
- The project is modular: each major function (data, model, training, evaluation) has its own directory.
- It leverages abstraction and separation of concerns: pre-processing is decoupled from model training, and evaluation scripts are kept independent.
- Support for distributed and scalable training is evident (using torchrun and FSDP) so indicate how the training nodes, multi-node clustering, and caching (using environment variables for offline datasets) interact.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Sources and Libraries
    ED["External Data Sources"]:::external
    HF["Hugging Face Datasets"]:::external
    LOG["Logging & Monitoring(W&B)"]:::external
    PT["Deep Learning Framework(PyTorch)"]:::external
    MEG["External Libraries(Megablocks,VLMEvalKit)"]:::external

    %% Data Acquisition & Pre-processing
    subgraph "Data Acquisition & Pre-processing"
        D1["olmo/data"]:::data
        D2["olmo/hf_datasets"]:::data
        D3["scripts/download_data.py"]:::data
    end

    %% Model Components & Core Libraries
    subgraph "Model Components & Core Libraries"
        M1["olmo/model.py"]:::model
        M2["olmo/config.py"]:::model
        M3["olmo/tokenizer.py"]:::model
        M4["olmo/image_vit.py"]:::model
        M5["olmo/initialization.py"]:::model
        M6["olmo/optim.py"]:::model
    end

    %% Training Pipelines
    subgraph "Training Pipelines"
        T1["launch_scripts/train_captioner.py"]:::train
        T2["launch_scripts/train_multitask_model.py"]:::train
        T3["scripts/train.py"]:::train
        T4["olmo/train.py"]:::train
    end

    %% Evaluation & Inference Modules
    subgraph "Evaluation & Inference Modules"
        E1["olmo/eval"]:::eval
        E2["launch_scripts/eval_downstream.py"]:::eval
        E3["launch_scripts/eval_captioner.py"]:::eval
    end

    %% Utility & Supporting Scripts
    subgraph "Utility & Supporting Scripts"
        U1["scripts/convert_hf_to_molmo.py"]:::util
        U2["scripts/build_submission_file.py"]:::util
        U3["scripts/dataset_visualize.py"]:::util
        U4["launch_scripts/utils.py"]:::util
    end

    %% Data Flow Connections
    ED -->|"dataIngestion"| D1
    ED -->|"dataIngestion"| D2
    HF -->|"cachedData"| D2
    D1 -->|"preProcessing"| D3
    D2 -->|"preProcessing"| D3

    D3 -->|"processedData"| M1
    M2 --> M1
    M3 --> M1
    M4 --> M1
    M5 --> M1
    M6 --> M1

    M1 -->|"forwardPass"| T1
    M1 --> T2
    M1 --> T3
    M1 --> T4

    T1 -->|"checkpointLogs"| LOG
    T2 --> LOG
    T3 --> LOG
    T4 --> LOG

    T1 -->|"distributedSetup"| T4
    T2 -->|"distributedSetup"| T4

    T4 -->|"modelCheckpoints"| E1
    E2 -->|"evaluationMetrics"| E1
    E3 -->|"evaluationScripts"| E1

    %% Utility Scripts Interactions
    U1 ---|"modelConversion"| M1
    U2 ---|"submissionFile"| E1
    U3 ---|"dataVisualization"| D1
    U4 ---|"supportConfig"| T1

    %% External Dependencies
    PT -->|"supportsComputation"| M1
    PT --> T1
    PT --> T2
    PT --> T3
    PT --> T4

    MEG -->|"externalTools"| E1

    %% Click Events for Component Mapping
    click D1 "https://github.com/allenai/molmo/tree/main/olmo/data"
    click D2 "https://github.com/allenai/molmo/tree/main/olmo/hf_datasets"
    click D3 "https://github.com/allenai/molmo/blob/main/scripts/download_data.py"

    click M1 "https://github.com/allenai/molmo/blob/main/olmo/model.py"
    click M2 "https://github.com/allenai/molmo/blob/main/olmo/config.py"
    click M3 "https://github.com/allenai/molmo/blob/main/olmo/tokenizer.py"
    click M4 "https://github.com/allenai/molmo/blob/main/olmo/image_vit.py"
    click M5 "https://github.com/allenai/molmo/blob/main/olmo/initialization.py"
    click M6 "https://github.com/allenai/molmo/blob/main/olmo/optim.py"

    click T1 "https://github.com/allenai/molmo/blob/main/launch_scripts/train_captioner.py"
    click T2 "https://github.com/allenai/molmo/blob/main/launch_scripts/train_multitask_model.py"
    click T3 "https://github.com/allenai/molmo/blob/main/scripts/train.py"
    click T4 "https://github.com/allenai/molmo/blob/main/olmo/train.py"

    click E1 "https://github.com/allenai/molmo/tree/main/olmo/eval"
    click E2 "https://github.com/allenai/molmo/blob/main/launch_scripts/eval_downstream.py"
    click E3 "https://github.com/allenai/molmo/blob/main/launch_scripts/eval_captioner.py"

    click U1 "https://github.com/allenai/molmo/blob/main/scripts/convert_hf_to_molmo.py"
    click U2 "https://github.com/allenai/molmo/blob/main/scripts/build_submission_file.py"
    click U3 "https://github.com/allenai/molmo/blob/main/scripts/dataset_visualize.py"
    click U4 "https://github.com/allenai/molmo/blob/main/launch_scripts/utils.py"

    %% Styles
    classDef data fill:#f9f,stroke:#333,stroke-width:2px;
    classDef model fill:#bbf,stroke:#333,stroke-width:2px;
    classDef train fill:#bfb,stroke:#333,stroke-width:2px;
    classDef eval fill:#ffb,stroke:#333,stroke-width:2px;
    classDef util fill:#fdf,stroke:#333,stroke-width:2px;
    classDef external fill:#ddd,stroke:#333,stroke-width:2px;
```
