# gligen/gligen architecture

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

- Interactive diagram: https://gitdiagram.com/gligen/gligen
- Repository: https://github.com/gligen/gligen

## Overview

GLIGEN is a research system for grounded text-to-image generation and inpainting. Its main inference workflow prepares text, boxes, images, keypoints, or spatial maps as conditioning, then denoises with a configured diffusion model and sampler to produce an image. Training starts with registered datasets and grounding-input adapters, then optimizes the model through the trainer. The README documents several supported grounding modalities whose individual runtime wiring is not fully sampled here; those branches are included without asserting unverified calls.

Main entry points: [`dataset/tsv_dataset.py`](https://github.com/gligen/gligen/blob/master/dataset/tsv_dataset.py) (Grounded TSV data), [`gligen_inference.py`](https://github.com/gligen/gligen/blob/master/gligen_inference.py) (Inference runner), [`trainer.py`](https://github.com/gligen/gligen/blob/master/trainer.py) (Trainer), [`ldm/models/diffusion/ldm.py`](https://github.com/gligen/gligen/blob/master/ldm/models/diffusion/ldm.py) (Diffusion model)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Product entry points"]
  node_inference["Inference runner"]
  node_training_entry["Training entry<br/>[main.py]"]
  node_trainer["Trainer<br/>[trainer.py]"]
end

subgraph group_data["Training data"]
  node_dataset_registry["Dataset registry<br/>[catalog.py]"]
  node_dataset_combine["Dataset combiner<br/>[concat_dataset.py]"]
  node_tsv_dataset["Grounded TSV data<br/>[tsv_dataset.py]"]
  node_tsv_storage[("TSV storage<br/>[tsv.py]")]
  node_data_prepare["Annotation preparation"]
end

subgraph group_grounding["Grounding conditions"]
  node_text_grounding["Text grounding"]
  node_image_text_grounding["Text-image grounding"]
  node_keypoint_grounding["Keypoint grounding"]
  node_spatial_grounding["Spatial-map grounding"]
end

subgraph group_models["Generation models"]
  node_autoencoder["Latent autoencoder<br/>[autoencoder.py]"]
  node_diffusion["Diffusion model<br/>[ldm.py]"]
  node_attention["Gated attention<br/>[attention.py]"]
  node_grounding_networks["Grounding networks"]
  node_unet["Diffusion U-Net<br/>[openaimodel.py]"]
  node_ddim["DDIM sampler<br/>[ddim.py]"]
  node_plms["PLMS sampler<br/>[plms.py]"]
end

node_researcher(("Researcher"))
node_generated_image["Generated image"]

node_researcher -->|"runs generation"| node_inference
node_researcher -->|"starts training"| node_training_entry
node_training_entry -->|"starts trainer"| node_trainer
node_trainer -->|"loads datasets"| node_dataset_combine
node_dataset_combine -->|"uses registered names"| node_dataset_registry
node_dataset_combine -->|"constructs dataset"| node_tsv_dataset
node_tsv_dataset -->|"reads rows"| node_tsv_storage
node_data_prepare -.->|"writes TSV"| node_tsv_storage
node_tsv_dataset -.->|"adapts batch"| node_text_grounding
node_tsv_dataset -.->|"adapts batch"| node_image_text_grounding
node_tsv_dataset -.->|"adapts batch"| node_keypoint_grounding
node_tsv_dataset -.->|"adapts batch"| node_spatial_grounding
node_trainer -->|"trains model"| node_diffusion
node_inference -->|"loads model"| node_diffusion
node_diffusion -->|"encodes latents"| node_autoencoder
node_diffusion -.->|"predicts denoising"| node_unet
node_grounding_networks -.->|"supplies grounding"| node_attention
node_trainer -->|"uses sampler"| node_ddim
node_trainer -->|"uses sampler"| node_plms
node_inference -->|"selects sampler"| node_ddim
node_inference -->|"selects sampler"| node_plms
node_inference -.->|"saves result"| node_generated_image

click node_inference "https://github.com/gligen/gligen/blob/master/gligen_inference.py"
click node_training_entry "https://github.com/gligen/gligen/blob/master/main.py"
click node_trainer "https://github.com/gligen/gligen/blob/master/trainer.py"
click node_dataset_registry "https://github.com/gligen/gligen/blob/master/dataset/catalog.py"
click node_dataset_combine "https://github.com/gligen/gligen/blob/master/dataset/concat_dataset.py"
click node_tsv_dataset "https://github.com/gligen/gligen/blob/master/dataset/tsv_dataset.py"
click node_tsv_storage "https://github.com/gligen/gligen/blob/master/dataset/tsv.py"
click node_data_prepare "https://github.com/gligen/gligen/blob/master/DATA/process_grounding.py"
click node_text_grounding "https://github.com/gligen/gligen/blob/master/grounding_input/text_grounding_tokinzer_input.py"
click node_image_text_grounding "https://github.com/gligen/gligen/blob/master/grounding_input/text_image_grounding_tokinzer_input.py"
click node_keypoint_grounding "https://github.com/gligen/gligen/blob/master/grounding_input/keypoint_grounding_tokinzer_input.py"
click node_spatial_grounding "https://github.com/gligen/gligen/blob/master/grounding_input/canny_grounding_tokinzer_input.py"
click node_autoencoder "https://github.com/gligen/gligen/blob/master/ldm/models/autoencoder.py"
click node_diffusion "https://github.com/gligen/gligen/blob/master/ldm/models/diffusion/ldm.py"
click node_attention "https://github.com/gligen/gligen/blob/master/ldm/modules/attention.py"
click node_grounding_networks "https://github.com/gligen/gligen/blob/master/ldm/modules/diffusionmodules/text_grounding_net.py"
click node_unet "https://github.com/gligen/gligen/blob/master/ldm/modules/diffusionmodules/openaimodel.py"
click node_ddim "https://github.com/gligen/gligen/blob/master/ldm/models/diffusion/ddim.py"
click node_plms "https://github.com/gligen/gligen/blob/master/ldm/models/diffusion/plms.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_inference,node_training_entry,node_trainer toneBlue
class node_dataset_registry,node_dataset_combine,node_tsv_dataset,node_tsv_storage,node_data_prepare toneAmber
class node_text_grounding,node_image_text_grounding,node_keypoint_grounding,node_spatial_grounding toneMint
class node_autoencoder,node_diffusion,node_attention,node_grounding_networks,node_unet,node_ddim,node_plms toneRose
class node_researcher,node_generated_image toneIndigo
```

## Components

### Product entry points

- [Inference runner](https://github.com/gligen/gligen/blob/master/gligen_inference.py): `gligen_inference.py`
- [Training entry](https://github.com/gligen/gligen/blob/master/main.py): `main.py`
- [Trainer](https://github.com/gligen/gligen/blob/master/trainer.py): `trainer.py`

### Training data

- [Dataset registry](https://github.com/gligen/gligen/blob/master/dataset/catalog.py): `dataset/catalog.py`
- [Dataset combiner](https://github.com/gligen/gligen/blob/master/dataset/concat_dataset.py): `dataset/concat_dataset.py`
- [Grounded TSV data](https://github.com/gligen/gligen/blob/master/dataset/tsv_dataset.py): `dataset/tsv_dataset.py`
- [TSV storage](https://github.com/gligen/gligen/blob/master/dataset/tsv.py): `dataset/tsv.py`
- [Annotation preparation](https://github.com/gligen/gligen/blob/master/DATA/process_grounding.py): `DATA/process_grounding.py`

### Grounding conditions

- [Text grounding](https://github.com/gligen/gligen/blob/master/grounding_input/text_grounding_tokinzer_input.py): `grounding_input/text_grounding_tokinzer_input.py`
- [Text-image grounding](https://github.com/gligen/gligen/blob/master/grounding_input/text_image_grounding_tokinzer_input.py): `grounding_input/text_image_grounding_tokinzer_input.py`
- [Keypoint grounding](https://github.com/gligen/gligen/blob/master/grounding_input/keypoint_grounding_tokinzer_input.py): `grounding_input/keypoint_grounding_tokinzer_input.py`
- [Spatial-map grounding](https://github.com/gligen/gligen/blob/master/grounding_input/canny_grounding_tokinzer_input.py): `grounding_input/canny_grounding_tokinzer_input.py`

### Generation models

- [Latent autoencoder](https://github.com/gligen/gligen/blob/master/ldm/models/autoencoder.py): `ldm/models/autoencoder.py`
- [Diffusion model](https://github.com/gligen/gligen/blob/master/ldm/models/diffusion/ldm.py): `ldm/models/diffusion/ldm.py`
- [Gated attention](https://github.com/gligen/gligen/blob/master/ldm/modules/attention.py): `ldm/modules/attention.py`
- [Grounding networks](https://github.com/gligen/gligen/blob/master/ldm/modules/diffusionmodules/text_grounding_net.py): `ldm/modules/diffusionmodules/text_grounding_net.py`
- [Diffusion U-Net](https://github.com/gligen/gligen/blob/master/ldm/modules/diffusionmodules/openaimodel.py): `ldm/modules/diffusionmodules/openaimodel.py`
- [DDIM sampler](https://github.com/gligen/gligen/blob/master/ldm/models/diffusion/ddim.py): `ldm/models/diffusion/ddim.py`
- [PLMS sampler](https://github.com/gligen/gligen/blob/master/ldm/models/diffusion/plms.py): `ldm/models/diffusion/plms.py`

### Other components

- **Researcher**
- **Generated image**

## Connections

- Researcher → Inference runner: runs generation (evidence: `README.md`)
- Researcher → Training entry: starts training (evidence: `README.md`)
- Training entry → Trainer: starts trainer (evidence: `main.py`)
- Trainer → Dataset combiner: loads datasets (evidence: `trainer.py`)
- Dataset combiner → Dataset registry: uses registered names (evidence: `dataset/concat_dataset.py`)
- Dataset combiner → Grounded TSV data: constructs dataset (evidence: `dataset/concat_dataset.py`)
- Grounded TSV data → TSV storage: reads rows (evidence: `dataset/tsv_dataset.py`)
- Annotation preparation → TSV storage: writes TSV
- Grounded TSV data → Text grounding: adapts batch
- Grounded TSV data → Text-image grounding: adapts batch
- Grounded TSV data → Keypoint grounding: adapts batch
- Grounded TSV data → Spatial-map grounding: adapts batch
- Trainer → Diffusion model: trains model (evidence: `trainer.py`)
- Inference runner → Diffusion model: loads model (evidence: `gligen_inference.py`)
- Diffusion model → Latent autoencoder: encodes latents (evidence: `ldm/models/autoencoder.py`)
- Diffusion model → Diffusion U-Net: predicts denoising
- Grounding networks → Gated attention: supplies grounding
- Trainer → DDIM sampler: uses sampler (evidence: `trainer.py`)
- Trainer → PLMS sampler: uses sampler (evidence: `trainer.py`)
- Inference runner → DDIM sampler: selects sampler (evidence: `gligen_inference.py`)
- Inference runner → PLMS sampler: selects sampler (evidence: `gligen_inference.py`)
- Inference runner → Generated image: saves result
