Skip to content

[Modular] Support Ideogram4 Image2Image and Inpaint - #14364

Open
lucasruan1618 wants to merge 4 commits into
huggingface:mainfrom
lucasruan1618:feature/ideogram4-modular-img2img-inpaint
Open

[Modular] Support Ideogram4 Image2Image and Inpaint#14364
lucasruan1618 wants to merge 4 commits into
huggingface:mainfrom
lucasruan1618:feature/ideogram4-modular-img2img-inpaint

Conversation

@lucasruan1618

@lucasruan1618 lucasruan1618 commented Aug 3, 2026

Copy link
Copy Markdown

What does this PR do?

This PR adds img2img and inpainting support for Ideogram 4 through the Diffusers modular pipeline. The pipeline automatically selects the appropriate workflow from the supplied inputs:

  • Passing image runs img2img.
  • Passing both image and mask_image runs inpainting.

Img2img example

import torch

from diffusers import Ideogram4PromptEnhancerHead, ModularPipeline
from diffusers.utils import load_image


MODEL_ID = "ideogram-ai/ideogram-4-nf4-diffusers"
PROMPT_ENHANCER_ID = "diffusers/qwen3-vl-8b-instruct-lm-head"

pipe = ModularPipeline.from_pretrained(MODEL_ID)
pipe.load_components(dtype=torch.bfloat16)
pipe.update_components(
    prompt_enhancer_head=Ideogram4PromptEnhancerHead.from_pretrained(
        PROMPT_ENHANCER_ID, dtype=torch.bfloat16
    )
)
pipe.to("cuda")

init_image = load_image(
    "https://github.com/lucasruan1618/Image_storage/blob/main/Input/cute_cat.png?raw=true"
).convert("RGB")

prompt = "wizard dog, Gandalf-inspired, Lord of the Rings aesthetic, majestic yet cute, Studio Ghibli style"

for strength in [0.6, 0.7, 0.8, 0.9, 1.0]:
    image = pipe(
        prompt=prompt,
        image=init_image,
        height=init_image.height,
        width=init_image.width,
        strength=strength,
        prompt_upsampling=True,
        generator=torch.Generator(device="cuda").manual_seed(42),
        output="images",
    )[0]
    image.save(f"ideogram4_modular_img2img_{strength}.png")

Inpainting example

import torch

from diffusers import Ideogram4PromptEnhancerHead, ModularPipeline
from diffusers.utils import load_image


MODEL_ID = "ideogram-ai/ideogram-4-nf4-diffusers"
PROMPT_ENHANCER_ID = "diffusers/qwen3-vl-8b-instruct-lm-head"

pipe = ModularPipeline.from_pretrained(MODEL_ID)
pipe.load_components(dtype=torch.bfloat16)
pipe.update_components(
    prompt_enhancer_head=Ideogram4PromptEnhancerHead.from_pretrained(
        PROMPT_ENHANCER_ID, dtype=torch.bfloat16
    )
)
pipe.to("cuda")

init_image = load_image(
    "https://github.com/lucasruan1618/Image_storage/blob/main/Input/cute_cat.png?raw=true"
).convert("RGB")
mask_image = load_image(
    "https://github.com/lucasruan1618/Image_storage/blob/main/Input/mask_cat.png?raw=true"
).convert("L")

prompt = "cat wizard with red hat, gandalf, lord of the rings, detailed, fantasy, cute, adorable, Pixar, Disney"

for strength in [0.6, 0.7, 0.8, 0.9, 1.0]:
    image = pipe(
        prompt=prompt,
        image=init_image,
        mask_image=mask_image,
        height=init_image.height,
        width=init_image.width,
        strength=strength,
        prompt_upsampling=True,
        generator=torch.Generator(device="cuda").manual_seed(42),
        output="images",
    )[0]
    image.save(f"ideogram4_modular_inpaint_{strength}.png")

Img2img results at different strengths

Init image
0.6
0.7
0.8
0.9
1.0

Inpainting results at different strengths

Init image
Mask image
0.6
0.7
0.8
0.9
1.0

Known limitation

Ideogram 4 inpainting at strength=1.0 may produce a visible artifact in or around the masked region. At this strength, the input is fully noised and all denoising steps are used, so less information from the original masked content is preserved.

Before submitting

  • Did you use an AI agent (Claude Code, Codex, Cursor, etc.) to help with this PR? If so:
    • Did you read the Coding with AI agents guide?
    • Did you run the self-review skill on the diff?
    • Did you share the final self-review notes in the PR description or a comment?
  • Did you read the contributor guideline?
  • Did you read our philosophy doc? (important for complex PRs)
  • Was this discussed/approved via a GitHub issue or the forum? Please add a link to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?
  • Are you the author (or part of the team) of the model/pipeline (only applicable for model/pipeline related PRs)?

Who can review?

-->

@github-actions github-actions Bot added documentation Improvements or additions to documentation tests modular-pipelines size/L PR with diff > 200 LOC labels Aug 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation modular-pipelines size/L PR with diff > 200 LOC tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant