How ideogram-oss/ideogram4 works
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: pipeline_ideogram4.py Ideogram pipeline · modeling_ideogram4.py Single-stream DiT · run_inference.py Inference CLI · magic_prompt.py Magic prompt
Components 17
Entry & prompt
- Inference CLI · Accepts a prompt and writes the generated image.
run_inference.py - Magic prompt · Converts plain language into structured JSON captions.
src/ideogram4/magic_prompt.py - Prompt schema template
src/ideogram4/magic_prompt_system_prompts/v1.txt - Safety moderation · Screens text before and images after generation.
src/ideogram4/safety.py - Caption verifier
src/ideogram4/caption_verifier.py
Generation pipeline
- Ideogram pipeline · Coordinates conditioning, sampling, decoding, and output handling.
src/ideogram4/pipeline_ideogram4.py - Sampler presets · Centralizes quality and step presets.
src/ideogram4/sampler_configs.py - Flow-matching scheduler · Evolves noise into image latents.
src/ideogram4/scheduler.py - Shared constants
src/ideogram4/constants.py - Generated image
Model & latent runtime
- Single-stream DiT · Processes text and image tokens in one sequence.
src/ideogram4/modeling_ideogram4.py - Latent normalization · Maintains the latent distribution expected by the model.
src/ideogram4/latent_norm.py - Autoencoder decoder · Transforms final latents into images.
src/ideogram4/autoencoder.py - Quantized loading · Loads NF4 CUDA or FP8 model variants.
src/ideogram4/quantized_loading.py
External services
- Hugging Face · Provides gated model artifacts and authentication.
- Ideogram / user LLM
- Hive moderation APIs
Connections 19
- 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