HiDream-E1 Documentation

repository·main·Indexed 21 days ago

https://github.com/hidream-ai/hidream-e1

HiDream-E1 is an instruction-based image editing model built on the HiDream-I1 foundation. It enables image modification via natural language instructions. The repository includes HiDream-E1-Full, which operates at a fixed 768x768 resolution and requires specific instruction formatting, and HiDream-E1.1, which supports dynamic resolutions up to 1M pixels and direct instruction processing.

Tokens
1.1K
Snippets
7
Records
8
Agent score
24%

What's inside HiDream-E1

  1. Control editing vs refinement with refine_strength

    main

    The pipeline includes a refine_strength parameter to balance the editing and refinement stages:

    • Editing Stage: Occurs during the first (1 - refine_strength) portion of denoising steps.
    • Refinement Stage: The remaining refine_strength portion uses HiDream-I1-Full for img2img refinement to enhance the result.
    • Disable Refinement: Set refine_strength to 0.0 to skip the refinement stage.
  2. Format instructions for HiDream-E1-Full

    main

    When using HiDream-E1-Full, you must provide instructions in the following specific format:

    Editing Instruction: {instruction}. Target Image Description: {description}

    Example: Editing Instruction: Convert the image into a Ghibli style. Target Image Description: A person in a light pink t-shirt with short dark hair, depicted in a Ghibli style against a plain background.

    Editing Instruction: {instruction}. Target Image Description: {description}
  3. Refine instructions for HiDream-E1-Full

    main

    If you are using HiDream-E1-Full, you can use the instruction_refinement.py script to automatically generate the required target image descriptions. This script requires a VLM API key (either via a local vllm instance or OpenAI's API).

    python ./instruction_refinement.py --src_image ./test.jpeg --src_instruction "convert the image into a Ghibli style"
  4. Run inference for HiDream-E1-Full

    main

    HiDream-E1-Full operates at a fixed resolution of 768x768. Unlike version 1.1, it requires instructions to be formatted with both an editing instruction and a target image description. Use the inference.py script to generate images.

    python ./inference.py
  5. Run inference for HiDream-E1.1

    main

    HiDream-E1.1 supports dynamic resolution (up to 1M pixels) and accepts direct instructions (e.g., convert the image into a Ghibli style) without needing manual prompt refinement. Use the inference_e1_1.py script to generate images.

    python ./inference_e1_1.py
  6. Install HiDream-E1

    main

    To set up the environment for HiDream-E1, you must install the project requirements along with Flash Attention and the latest version of Diffusers. It is recommended to use CUDA version 12.4 for manual installations.

    Prerequisites:

    • Flash Attention
    • Latest Diffusers
    • HuggingFace account with access to meta-llama/Llama-3.1-8B-Instruct (required for automatic model downloading).
    pip install -r requirements.txt
    pip install -U flash-attn --no-build-isolation
    pip install -U git+https://github.com/huggingface/diffusers.git
  7. Launch Gradio demos

    main

    You can run interactive Gradio demos for either model version:

    For HiDream-E1.1:

    python gradio_demo_1_1.py

    For HiDream-E1-Full:

    python gradio_demo.py
    # For E1.1
    python gradio_demo_1_1.py 
    
    # For E1-Full
    python gradio_demo.py 
  8. Reference: Available HiDream-E1 Models

    main

    The following models are available in the repository:

    NameScriptInference StepsResolutionHuggingFace repo
    HiDream-E1-Fullinference.py28768x768HiDream-E1-Full
    HiDream-E1.1inference_e1_1.py28Dynamic (1M pixels)HiDream-E1.1
    | Name | Script | Inference Steps | Resolution | HuggingFace repo |
    | --- | --- | --- | --- | --- |
    | HiDream-E1-Full | inference.py | 28 | 768x768 | 🤗 [HiDream-E1-Full](https://huggingface.co/HiDream-ai/HiDream-E1-Full) |
    | HiDream-E1.1 | inference_e1_1.py | 28 | Dynamic(1M pixels) | 🤗 [HiDream-E1.1](https://huggingface.co/HiDream-ai/HiDream-E1-1) |