Ideogram 4 Documentation

repository·main·Indexed 25 days ago

https://github.com/ideogram-oss/ideogram4

Inference code and technical documentation for Ideogram 4, an open-weight text-to-image foundation model. It features a single-stream Diffusion Transformer (DiT) architecture, native 2k resolution support, and a structured JSON prompting interface for high-quality graphic design, typography, and photorealism. The model utilizes Qwen3-VL-8B-Instruct as a text encoder and is available in nf4 and fp8 quantization formats.

Tokens
11.2K
Snippets
15
Records
63
Agent score
83%

What's inside Ideogram 4

  1. How Classifier-Free Guidance (CFG) is applied

    main

    Ideogram 4 uses Asymmetric CFG to improve prompt adherence. At each sampling step, the model performs two forward passes:

    1. Conditional (positive): Uses full text features + noisy image latents.
    2. Unconditional (negative): Uses zeroed text features + noisy image latents (processing only image tokens to save computation).

    The guided velocity v_guided is calculated as: v_guided = gw * v_conditional + (1 - gw) * v_unconditional

    Where gw is the guidance weight. A higher gw amplifies the text signal. Guidance weights can be scheduled per step (e.g., high guidance during early steps and lower guidance for 'polishing' near t=0).

    v_guided = gw * v_conditional + (1 - gw) * v_unconditional
  2. Understand the Ideogram4Transformer sequence layout

    main

    The Ideogram4Transformer uses a single-stream architecture where text tokens and image latent tokens are concatenated into a single sequence. This allows both modalities to be processed through the same self-attention layers.

    Sequence Structure:

    • Text tokens: Up to 2048 tokens, derived from Qwen3-VL features.
    • Image latent tokens: A grid of size grid_h × grid_w, representing noisy latents z_t.
    Sequence layout (per sample):
    
      ┌───────────────────┬────────────────────────┐
      │  text tokens      │  image latent tokens   │
      │  (up to 2048)     │  (grid_h × grid_w)     │
      └───────────────────┴────────────────────────┘
               ▲                    ▲
         Qwen3-VL features    noisy latents z_t
  3. Understand the Ideogram 4 Model Architecture

    main

    Ideogram 4 is a foundation model built on a fully single-stream Diffusion Transformer (DiT) architecture. Unlike models with separate text and image branches, Ideogram 4 concatenates text and image tokens into a single sequence processed by a 34-layer transformer, allowing for deep cross-modal interaction at every layer.

    Key Architectural Components:

    • Text Encoder: Uses Qwen3-VL-8B-Instruct (a vision-language model) instead of traditional text-only encoders like CLIP or T5. It extracts and concatenates hidden states from 13 intermediate layers to provide multi-scale semantic features.
    • Classifier-Free Guidance: Features a dual-branch system where conditional (positive) and unconditional (negative) branches can be independently refined for control over prompt adherence and image quality.
    • Resolution Support: Natively supports any resolution from 256 to 2048 (must be multiples of 16), with aspect ratios up to 6:1.
  4. Use JSON caption schema for fine-grained prompt control

    main

    Ideogram 4 supports structured JSON prompts, which provide significantly more control over composition, color palettes, typography, and spatial layout compared to plain-text prompts. Using this schema allows you to explicitly define high-level descriptions, stylistic attributes, and a detailed compositional deconstruction of the scene.

    The JSON schema consists of three primary keys:

    • high_level_description: A prose description of the overall scene.
    • style_description: An object defining the aesthetic properties of the image.
    • compositional_deconstruction: An object detailing the background and specific elements within the scene.

    Within compositional_deconstruction, you can define:

    • background: A description of the environment.
    • elements: An array of objects representing specific items, people, or text. Each element can have a type (e.g., obj or text), a bbox (bounding box), a desc (description), and for text elements, the specific text content.
    {
      "high_level_description": "A medium-shot photograph of Formula 1 driver Max Verstappen...",
      "style_description": {
        "aesthetics": "saturated primary colors, rule of thirds, joyful and triumphant",
        "lighting": "overcast daylight, diffused, soft subtle shadows",
        "photo": "shallow depth of field, sharp focus, eye-level, telephoto",
        "medium": "photograph"
      },
      "compositional_deconstruction": {
        "background": "The background is an out-of-focus racing paddock...",
        "elements": [
          {
            "type": "obj",
            "bbox": [55, 642, 1000, 937],
            "desc": "An older man standing in profile..."
          },
          {
            "type": "text",
            "bbox": [657, 0, 755, 142],
            "text": "F1",
            "desc": "Large, stylized red logo..."
          }
        ]
      }
    }
  5. Understand the Ideogram4 Model Architecture

    main

    Ideogram4 is a single-stream Diffusion Transformer (DiT). It processes text and image information by concatenating text tokens (derived from Qwen3-VL-8B-Instruct hidden states) and image latent tokens into a single sequence.

    Key architectural components include:

    • Ideogram4Transformer: Composed of 34 Ideogram4TransformerBlock layers.
    • Ideogram4Attention: Utilizes QK-RMSNorm and 3D MRoPE (Multimodal Rotary Positional Embedding) to ensure text and image tokens share a unified positional space.
    • Ideogram4MLP: Uses SwiGLU activation.
    • Modulation: Per-block modulation is performed via AdaLN (Adaptive Layer Norm) scaled/gated by a timestep embedding.
    • Sampling: Uses an Euler flow-matching sampler with a logit-normal schedule and asymmetric CFG (Classifier-Free Guidance).
    • Output: The process produces denoised image latents which are then decoded via a VAE into a PIL.Image.
  6. How the Ideogram 4 inference pipeline works

    main

    Ideogram 4 is a flow-matching text-to-image model utilizing a single-stream Diffusion Transformer (DiT). The end-to-end pipeline consists of four main stages:

    1. Text Encoder (Qwen3-VL-8B-Instruct): A frozen vision-language model that tokenizes the prompt and extracts multi-scale hidden states from 13 specific layers (0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 35) to create a rich text representation.
    2. DiT Backbone (Ideogram4Transformer): A 34-layer trainable transformer that processes concatenated text and image latent tokens in a single sequence. It uses Flow Matching to predict a velocity field and an Euler sampler for integration.
    3. Classifier-Free Guidance (CFG): A mechanism that combines conditional (text + image) and unconditional (image only) velocity predictions to amplify prompt adherence.
    4. VAE Decoder (KL Autoencoder): A frozen decoder that unpatches and denormalizes the denoised latents to produce the final RGB image.
    ┌─────────────┐   ┌──────────────────────┐   ┌──────────────┐   ┌───────────┐
     │  Qwen3-VL   │   │  Ideogram4           │   │  KL VAE      │   │           │
     │  Text       ├──►│  Transformer (DiT)   ├──►│  VAE         ├──►│  Image    │
     └─────────────┘   └──────────────────────┘   └──────────────┘   └───────────┘
         frozen              trainable                 frozen
  7. Control colors with Color Palette Conditioning

    main

    You can steer the dominant colors of an image by providing a color_palette array of hex colors.

    • Global Palette: Use style_description.color_palette for the overall image. Supports up to 16 colors.
    • Per-Element Palette: Use compositional_deconstruction.elements[*].color_palette for specific objects. Supports up to 5 colors.

    Requirements:

    • Use uppercase hex strings only: #RRGGBB (e.g., #1B1B2F).
    • Do not use shorthand (e.g., #fff is invalid).
    • For controlled lighting, include both highlight and shadow colors in the palette.
    • Include background colors to ensure the environment matches the intended mood.
  8. Access gated model weights on Hugging Face

    main

    The model weights are gated on Hugging Face. To download them, you must first accept the license on the model page and then authenticate your environment.

    1. Visit the model page (ideogram-ai/ideogram-4-nf4 or ideogram-ai/ideogram-4-fp8) and click Agree and access repository.
    2. Create a Hugging Face access token at huggingface.co/settings/tokens.
    3. Authenticate via the CLI or by setting an environment variable.
  9. Install ideogram4 in editable mode for development

    main

    To develop on the package, it is recommended to use an isolated environment because dependencies include several GB of CUDA-built wheels. Installing in editable mode allows changes to the source tree to be picked up immediately without requiring a reinstall.

    Using standard venv:

    python -m venv .venv && source .venv/bin/activate
    pip install -e .

    Using uv:

    uv venv && source .venv/bin/activate
    uv pip install -e .
    pip install -e .
  10. Report safety violations and misuse

    main

    If you observe violations of usage policies, such as content the model should not have produced, or deployments that have removed/overridden the required safety mitigations, please report them to the Ideogram safety team.

    Contact: safety@ideogram.ai

    What to include in your report:

    • Prompts used
    • Image hashes
    • URLs
    • Screenshots
    • Deployment context
  11. Run pre-commit hooks manually

    main

    You can manually trigger the pre-commit hooks against all files in the repository. This is useful for the initial setup or within CI environments. Note that the first run will download the necessary environments (e.g., ruff, mypy) into ~/.cache/pre-commit/ and may take a few minutes.

    To run against all files:

    pre-commit run --all-files
    pre-commit run --all-files
  12. Expand plain-text prompts using Magic Prompt

    main

    If you do not want to write JSON captions manually, you can use Magic Prompt to expand a casual plain-text prompt into a structured JSON caption using an LLM.

    You can use the ClaudeOpusMagicPromptV1 class directly or use the run_inference.py CLI with the --magic-prompt-model flag.

    import os
    from ideogram4 import ClaudeOpusMagicPromptV1, PRESETS
    
    magic = ClaudeOpusMagicPromptV1(api_key=os.environ["MAGIC_PROMPT_API_KEY"])
    caption = magic.expand("a golden retriever on a skateboard", aspect_ratio="1:1")
    preset = PRESETS["V4_QUALITY_48"]
    images = pipe(
      caption,
      height=1024,
      width=1024,
      num_steps=preset.num_steps,
      guidance_schedule=preset.guidance_schedule,
      mu=preset.mu,
      std=preset.std,
    )