# ideogram-oss/ideogram4 architecture

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

- Interactive diagram: https://gitdiagram.com/ideogram-oss/ideogram4
- Repository: https://github.com/ideogram-oss/ideogram4

## Overview

#### Purpose and Entry Point
Ideogram 4 is an open-weight, flow-matching text-to-image inference package. The primary executable is `run_inference.py`, which accepts a prompt, provisions model components, runs generation, and writes an image. The installable Python package is rooted at `src/ideogram4/__init__.py`.

#### Prompt Intake and Expansion
Prompts are expected as structured JSON captions, enabling layout, typography, and palette controls. Plain-language input is converted to that schema through magic prompt logic, potentially using Ideogram’s hosted API or a user-provided LLM.
- `src/ideogram4/magic_prompt.py`
- `src/ideogram4/magic_prompt_system_prompts/v1.txt`
- `run_inference.py`

#### Safety Boundary
Inference-time moderation is an explicit boundary around generation: text can be screened before inference and generated images afterward. This integrates with Hive text and visual moderation services when credentials are supplied.
- `src/ideogram4/safety.py`
- `src/ideogram4/caption_verifier.py`
- `run_inference.py`

#### Pipeline Orchestration
The pipeline coordinates prompt conditioning, latent initialization, iterative denoising, decoding, and output handling. It is the central application-facing abstraction; the CLI is its main consumer.
- `src/ideogram4/pipeline_ideogram4.py`
- `src/ideogram4/constants.py`
- `run_inference.py`

#### Conditioning and DiT Model
The core network is a single-stream Diffusion Transformer: text and image tokens share a unified sequence through the model. The implementation owns model construction and forward behavior; the pipeline supplies conditioning and sampling inputs.
- `src/ideogram4/modeling_ideogram4.py`
- `src/ideogram4/latent_norm.py`
- `src/ideogram4/constants.py`

#### Latent Image Representation
Generation occurs in latent space rather than pixel space. The autoencoder transforms output latents into final images, while latent normalization maintains the distribution expected by the diffusion model.
- `src/ideogram4/autoencoder.py`
- `src/ideogram4/latent_norm.py`
- `src/ideogram4/pipeline_ideogram4.py`

#### Sampling and Scheduling
A scheduler evolves noise toward image latents under flow matching. Sampler presets centralize practical step/configuration choices, including quality-oriented settings, while the pipeline applies classifier-free guidance and resolution-dependent generation settings.
- `src/ideogram4/scheduler.py`
- `src/ideogram4/sampler_configs.py`
- `src/ideogram4/pipeline_ideogram4.py`

#### Weights, Runtimes, and External Dependencies
Weights are gated Hugging Face artifacts: NF4 targets CUDA and is compatible with Diffusers; FP8 targets broader hardware through this repository’s implementation. Quantized loading is isolated from inference orchestration. Material external services are Hugging Face authentication/downloads, the optional Ideogram magic-prompt API, and optional Hive moderation APIs.
- `src/ideogram4/quantized_loading.py`
- `src/ideogram4/modeling_ideogram4.py`
- `pyproject.toml`

Main entry points: [`src/ideogram4/pipeline_ideogram4.py`](https://github.com/ideogram-oss/ideogram4/blob/main/src/ideogram4/pipeline_ideogram4.py) (Ideogram pipeline), [`src/ideogram4/modeling_ideogram4.py`](https://github.com/ideogram-oss/ideogram4/blob/main/src/ideogram4/modeling_ideogram4.py) (Single-stream DiT), [`run_inference.py`](https://github.com/ideogram-oss/ideogram4/blob/main/run_inference.py) (Inference CLI), [`src/ideogram4/magic_prompt.py`](https://github.com/ideogram-oss/ideogram4/blob/main/src/ideogram4/magic_prompt.py) (Magic prompt)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry &amp; prompt"]
  node_cli["Inference CLI<br/>Python executable<br/>[run_inference.py]"]
  node_magic_prompt["Magic prompt<br/>prompt expansion<br/>[magic_prompt.py]"]
  node_prompt_template["Prompt schema template<br/>system prompt<br/>[v1.txt]"]
  node_safety["Safety moderation<br/>safety boundary<br/>[safety.py]"]
  node_caption_verifier["Caption verifier<br/>caption validation"]
end

subgraph group_pipeline["Generation pipeline"]
  node_pipeline_api["Ideogram pipeline<br/>orchestrator"]
  node_sampler_presets["Sampler presets<br/>sampling config<br/>[sampler_configs.py]"]
  node_scheduler["Flow-matching scheduler<br/>[scheduler.py]"]
  node_constants["Shared constants<br/>runtime settings<br/>[constants.py]"]
  node_image_output["Generated image<br/>artifact"]
end

subgraph group_model["Model &amp; latent runtime"]
  node_dit["Single-stream DiT<br/>diffusion transformer"]
  node_latent_norm["Latent normalization<br/>latent transform<br/>[latent_norm.py]"]
  node_autoencoder["Autoencoder decoder<br/>latent decoder<br/>[autoencoder.py]"]
  node_quantized_loader["Quantized loading<br/>weight loader"]
end

subgraph group_external["External services"]
  node_huggingface[("Hugging Face<br/>weight registry")]
  node_ideogram_api{{"Ideogram / user LLM<br/>optional prompt API"}}
  node_hive{{"Hive moderation APIs<br/>optional moderation API"}}
end

node_cli -->|"expands plain prompts"| node_magic_prompt
node_magic_prompt -->|"uses schema instructions"| node_prompt_template
node_magic_prompt -.->|"optional expansion"| node_ideogram_api
node_cli -->|"validates caption"| node_caption_verifier
node_cli -->|"enforces moderation"| node_safety
node_safety -.->|"optional text/image checks"| node_hive
node_cli -->|"invokes generation"| node_pipeline_api
node_pipeline_api -->|"selects preset"| node_sampler_presets
node_pipeline_api -->|"runs denoising steps"| node_scheduler
node_pipeline_api -->|"supplies conditioning and latents"| node_dit
node_scheduler -->|"sampling trajectory"| node_dit
node_dit -->|"uses normalized latents"| node_latent_norm
node_pipeline_api -->|"decodes final latent"| node_autoencoder
node_autoencoder -->|"produces pixels"| node_image_output
node_pipeline_api -->|"screens generated image"| node_safety
node_quantized_loader -->|"constructs weighted model"| node_dit
node_huggingface -->|"gated weights"| node_quantized_loader
node_constants -->|"generation settings"| node_pipeline_api
node_constants -->|"model settings"| node_dit

click node_cli "https://github.com/ideogram-oss/ideogram4/blob/main/run_inference.py"
click node_magic_prompt "https://github.com/ideogram-oss/ideogram4/blob/main/src/ideogram4/magic_prompt.py"
click node_prompt_template "https://github.com/ideogram-oss/ideogram4/blob/main/src/ideogram4/magic_prompt_system_prompts/v1.txt"
click node_safety "https://github.com/ideogram-oss/ideogram4/blob/main/src/ideogram4/safety.py"
click node_caption_verifier "https://github.com/ideogram-oss/ideogram4/blob/main/src/ideogram4/caption_verifier.py"
click node_pipeline_api "https://github.com/ideogram-oss/ideogram4/blob/main/src/ideogram4/pipeline_ideogram4.py"
click node_sampler_presets "https://github.com/ideogram-oss/ideogram4/blob/main/src/ideogram4/sampler_configs.py"
click node_scheduler "https://github.com/ideogram-oss/ideogram4/blob/main/src/ideogram4/scheduler.py"
click node_constants "https://github.com/ideogram-oss/ideogram4/blob/main/src/ideogram4/constants.py"
click node_dit "https://github.com/ideogram-oss/ideogram4/blob/main/src/ideogram4/modeling_ideogram4.py"
click node_latent_norm "https://github.com/ideogram-oss/ideogram4/blob/main/src/ideogram4/latent_norm.py"
click node_autoencoder "https://github.com/ideogram-oss/ideogram4/blob/main/src/ideogram4/autoencoder.py"
click node_quantized_loader "https://github.com/ideogram-oss/ideogram4/blob/main/src/ideogram4/quantized_loading.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_cli,node_magic_prompt,node_prompt_template,node_safety,node_caption_verifier toneBlue
class node_pipeline_api,node_sampler_presets,node_scheduler,node_constants,node_image_output toneAmber
class node_dit,node_latent_norm,node_autoencoder,node_quantized_loader toneMint
class node_huggingface,node_ideogram_api,node_hive toneRose
```

## Components

### Entry & prompt

- [Inference CLI](https://github.com/ideogram-oss/ideogram4/blob/main/run_inference.py): Python executable · Accepts a prompt and writes the generated image. · `run_inference.py`
- [Magic prompt](https://github.com/ideogram-oss/ideogram4/blob/main/src/ideogram4/magic_prompt.py): prompt expansion · Converts plain language into structured JSON captions. · `src/ideogram4/magic_prompt.py`
- [Prompt schema template](https://github.com/ideogram-oss/ideogram4/blob/main/src/ideogram4/magic_prompt_system_prompts/v1.txt): system prompt · `src/ideogram4/magic_prompt_system_prompts/v1.txt`
- [Safety moderation](https://github.com/ideogram-oss/ideogram4/blob/main/src/ideogram4/safety.py): safety boundary · Screens text before and images after generation. · `src/ideogram4/safety.py`
- [Caption verifier](https://github.com/ideogram-oss/ideogram4/blob/main/src/ideogram4/caption_verifier.py): caption validation · `src/ideogram4/caption_verifier.py`

### Generation pipeline

- [Ideogram pipeline](https://github.com/ideogram-oss/ideogram4/blob/main/src/ideogram4/pipeline_ideogram4.py): orchestrator · Coordinates conditioning, sampling, decoding, and output handling. · `src/ideogram4/pipeline_ideogram4.py`
- [Sampler presets](https://github.com/ideogram-oss/ideogram4/blob/main/src/ideogram4/sampler_configs.py): sampling config · Centralizes quality and step presets. · `src/ideogram4/sampler_configs.py`
- [Flow-matching scheduler](https://github.com/ideogram-oss/ideogram4/blob/main/src/ideogram4/scheduler.py): scheduler · Evolves noise into image latents. · `src/ideogram4/scheduler.py`
- [Shared constants](https://github.com/ideogram-oss/ideogram4/blob/main/src/ideogram4/constants.py): runtime settings · `src/ideogram4/constants.py`
- **Generated image**: artifact

### Model & latent runtime

- [Single-stream DiT](https://github.com/ideogram-oss/ideogram4/blob/main/src/ideogram4/modeling_ideogram4.py): diffusion transformer · Processes text and image tokens in one sequence. · `src/ideogram4/modeling_ideogram4.py`
- [Latent normalization](https://github.com/ideogram-oss/ideogram4/blob/main/src/ideogram4/latent_norm.py): latent transform · Maintains the latent distribution expected by the model. · `src/ideogram4/latent_norm.py`
- [Autoencoder decoder](https://github.com/ideogram-oss/ideogram4/blob/main/src/ideogram4/autoencoder.py): latent decoder · Transforms final latents into images. · `src/ideogram4/autoencoder.py`
- [Quantized loading](https://github.com/ideogram-oss/ideogram4/blob/main/src/ideogram4/quantized_loading.py): weight loader · Loads NF4 CUDA or FP8 model variants. · `src/ideogram4/quantized_loading.py`

### External services

- **Hugging Face**: weight registry · Provides gated model artifacts and authentication.
- **Ideogram / user LLM**: optional prompt API
- **Hive moderation APIs**: optional moderation API

## Connections

- Inference CLI → Magic prompt: expands plain prompts
- Magic prompt → Prompt schema template: uses schema instructions
- Magic prompt → Ideogram / user LLM: optional expansion
- Inference CLI → Caption verifier: validates caption
- Inference CLI → Safety moderation: enforces moderation
- Safety moderation → Hive moderation APIs: optional text/image checks
- Inference CLI → Ideogram pipeline: invokes generation
- Ideogram pipeline → Sampler presets: selects preset
- Ideogram pipeline → Flow-matching scheduler: runs denoising steps
- Ideogram pipeline → Single-stream DiT: supplies conditioning and latents
- Flow-matching scheduler → Single-stream DiT: sampling trajectory
- Single-stream DiT → Latent normalization: uses normalized latents
- Ideogram pipeline → Autoencoder decoder: decodes final latent
- Autoencoder decoder → Generated image: produces pixels
- Ideogram pipeline → Safety moderation: screens generated image
- Quantized loading → Single-stream DiT: constructs weighted model
- Hugging Face → Quantized loading: gated weights
- Shared constants → Ideogram pipeline: generation settings
- Shared constants → Single-stream DiT: model settings
