# chenguolin/diffsplat architecture

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

- Interactive diagram: https://gitdiagram.com/chenguolin/diffsplat
- Repository: https://github.com/chenguolin/diffsplat

## Overview

##### Main Components and Their Roles
- Data & Asset Management:
- Assets Folder: Stores demo images, videos, and prompt examples for visualization.
- Dataset Preprocessing: Found in src/data (e.g., gobjaverse_parquet_dataset.py) which handles preprocessing and packaging large-scale datasets (from G-Objaverse).
- Configuration & Setup:
- Configs Directory: Contains YAML configuration files (e.g., gsdiff_sd15.yaml, elevest.yaml) for various training and inference experiments.
- Settings: Contains requirements and setup scripts (setup.sh, requirements.txt) to initialize the environment.
- Model Architecture:
- Model Modules in src/models: Implements core model classes (GSRecon, GSVAEs, and network modules such as attention and rendering utilities).
- Extensions (extensions/diffusers_diffsplat): Contains modifications to the diffusers library. This includes new attention mechanisms (“multi-view attention”), custom UNet/Transformer initializations (via from_pretrained_new), and pipelines for variants like PixArt, SD1.5, SD3.5m, and ControlNet.
- Training Pipelines:
- Training Scripts (src/train_*.py): Separate scripts for training each component (e.g., train_gsdiff_sd.py, train_gsvae.py) with corresponding options defined in both src/options.py and YAML config files.
- Shell Scripts (scripts/train.sh): Environment setup and orchestration to kick off training processes.
- Inference Pipelines:
- Inference Scripts (src/infer_*.py): Scripts specific to running inference for different modes – text-conditioned, image-conditioned, and controlnet-based generation.
- Shell Scripts (scripts/infer.sh): Wrappers that set proper arguments (including model checkpoint usage) and environment variables.
- Checkpoint Management:
- download_ckpt.py: Handles downloading and organizing pretrained models from HuggingFace, ensuring that both text- and image-conditioned weights are readily available.

##### Out the Interactions and Data Flow
- Start from “Input” Sources:
- Data sources include text prompts, single-view images, control signals (e.g., canny or normal maps), and precomputed text embeddings (from extensions/encode_prompt_embeds.py).
- Preprocessing and Data Pipeline:
- Raw data is preprocessed using dataset utilities (src/data) and stored in efficient formats (e.g., parquet) before being fed into training or inference modules.
- Model Training Flow:
- Training scripts read configuration from the YAML files (configs) and options defined in src/options.py.
- The modified diffusers library (in extensions/diffusers_diffsplat) is used by model classes under src/models to perform training (using multi-view attention and flexible UNet architectures).
- Training involves both reconstruction (GSRecon, GSVAEs) and diffusion-based generation (DiffSplat) modes. Optionally, a tiny decoder may be employed to speed up rendering-loss calculations.
- Inference Flow:
- Wrapped by scripts/infer.sh, inference scripts load pretrained models (downloaded via download_ckpt.py) and run through the modified pipeline (that may include control signals from ControlNet).
- The output is a rendered 3D Gaussian splats video/gif along with optional ply file generation.
- External Dependencies:
- The system integrates with HuggingFace for model downloading and caching, and leverages PyTorch and the diffusers library (with custom modifications).

##### Implementation Steps
- Within the Model Architecture, subdivide into core models (GSRecon, GSVAEs, DiffSplat) and extensions (modified diffusers, control modules).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data & Preprocessing Layer
    subgraph "Data & Preprocessing Layer"
        DA["Assets Folder"]:::data
        DP["Dataset Preprocessing"]:::data
    end

    %% Configuration & Setup Layer
    subgraph "Configuration & Setup Layer"
        CF["Configurations"]:::config
        ST["Settings"]:::config
    end

    %% Model Architecture Layer
    subgraph "Model Architecture Layer"
        subgraph "Core Models"
            CM["Core Model Modules"]:::model
        end
        subgraph "Extensions"
            EX["Modified Diffusers & Extensions"]:::model
            PE["Precomputed Text Embeddings"]:::extension
        end
    end

    %% Execution Layer
    subgraph "Execution Layer"
        subgraph "Training Pipeline"
            TO["Training Options (src/options.py)"]:::exec
            TG["Training Script: gsdiff_sd"]:::exec
            TV["Training Script: gsvae"]:::exec
            TS["Training Orchestration (scripts/train.sh)"]:::exec
        end
        subgraph "Inference Pipeline"
            IG["Inference Script: gsdiff_sd"]:::exec
            IS["Inference Orchestration (scripts/infer.sh)"]:::exec
            OP["Output Generation"]:::exec
        end
    end

    %% Checkpoint & External Services
    subgraph "Checkpoint & External Services"
        CK["Checkpoint Management (download_ckpt.py)"]:::checkpoint
        HF["HuggingFace Hub"]:::external
    end

    %% Data Flow & Relationships
    %% Data Layer to Preprocessing
    DA --> DP
    DP --> TO

    %% Configuration to Training & Inference
    CF --> TO
    ST --> TO
    CF --> IG
    ST --> IG

    %% Model Architecture Integration into Training Pipeline
    TO --> CM
    TO --> EX
    CM --> TG
    EX --> TG
    PE --> TG
    PE --> IG

    %% Training Scripts Flow
    TO --> TG
    TO --> TV
    TG --> TS
    TV --> TS

    %% Checkpoint Integration
    HF --> CK
    CK --> TG
    CK --> TV
    CK --> IG
    TS --> CK

    %% Inference Pipeline Flow
    IG --> IS
    IS --> OP

    %% Class Definitions
    classDef data fill:#d0e7ff,stroke:#0077cc,stroke-width:2px;
    classDef config fill:#d0ffd0,stroke:#00cc44,stroke-width:2px;
    classDef model fill:#fff7d0,stroke:#cc9900,stroke-width:2px;
    classDef extension fill:#ffe6f7,stroke:#cc66aa,stroke-width:2px;
    classDef exec fill:#f0f0f0,stroke:#999999,stroke-width:2px;
    classDef checkpoint fill:#ffcccc,stroke:#ff0000,stroke-width:2px;
    classDef external fill:#e6ccff,stroke:#aa66cc,stroke-width:2px;

    %% Click Events
    click DA "https://github.com/chenguolin/diffsplat/tree/main/assets"
    click DP "https://github.com/chenguolin/diffsplat/blob/main/src/data/gobjaverse_parquet_dataset.py"
    click CF "https://github.com/chenguolin/diffsplat/tree/main/configs"
    click ST "https://github.com/chenguolin/diffsplat/blob/main/settings/setup.sh"
    click CM "https://github.com/chenguolin/diffsplat/tree/main/src/models"
    click EX "https://github.com/chenguolin/diffsplat/tree/main/extensions/diffusers_diffsplat"
    click PE "https://github.com/chenguolin/diffsplat/blob/main/extensions/encode_prompt_embeds.py"
    click TO "https://github.com/chenguolin/diffsplat/blob/main/src/options.py"
    click TG "https://github.com/chenguolin/diffsplat/blob/main/src/train_gsdiff_sd.py"
    click TV "https://github.com/chenguolin/diffsplat/blob/main/src/train_gsvae.py"
    click TS "https://github.com/chenguolin/diffsplat/blob/main/scripts/train.sh"
    click IG "https://github.com/chenguolin/diffsplat/blob/main/src/infer_gsdiff_sd.py"
    click IS "https://github.com/chenguolin/diffsplat/blob/main/scripts/infer.sh"
    click CK "https://github.com/chenguolin/diffsplat/blob/main/download_ckpt.py"
```
