HiDream-I1 Documentation

repository·main·Indexed 25 days ago

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

An open-source 17B parameter image generative foundation model using a Sparse Diffusion Transformer. It includes three model variants—Full, Dev, and Fast—optimized for different balances of quality and speed, and is compatible with the diffusers library and Llama-3.1-8B-Instruct.

Tokens
1.1K
Snippets
4
Records
5
Agent score
32%

What's inside HiDream-I1

  1. Overview of HiDream-I1 Models

    main

    HiDream-I1 offers three model variants optimized for different balance points between quality and speed:

    NameScriptInference StepsHuggingFace repo
    HiDream-I1-Full./inference.py50HiDream-ai/HiDream-I1-Full
    HiDream-I1-Dev./inference.py28HiDream-ai/HiDream-I1-Dev
    HiDream-I1-Fast./inference.py16HiDream-ai/HiDream-I1-Fast
  2. Run HiDream-I1 inference via CLI

    main

    You can use the inference.py script to generate images using different model versions by specifying the --model_type flag.

    Available model types:

    • full: Uses the HiDream-I1-Full model (50 inference steps).
    • dev: Uses the distilled HiDream-I1-Dev model (28 inference steps).
    • fast: Uses the distilled HiDream-I1-Fast model (16 inference steps).
    # For full model inference
    python ./inference.py --model_type full
    
    # For distilled dev model inference
    python ./inference.py --model_type dev
    
    # For distilled fast model inference
    python ./inference.py --model_type fast
  3. Install HiDream-I1 dependencies

    main

    To set up the environment for HiDream-I1, you must install Flash Attention (recommended CUDA version 12.4) and the project requirements.

    Note: The inference script automatically attempts to download meta-llama/Llama-3.1-8B-Instruct. You must agree to the Llama model license on Hugging Face and authenticate using huggingface-cli login before running.

    pip install -r requirements.txt
    pip install -U flash-attn --no-build-isolation
  4. Use HiDream-I1 with the Diffusers library

    main

    HiDream-I1 is supported by the diffusers library. It is recommended to install diffusers from source for optimal compatibility.

    To use the pipeline, you must provide a tokenizer_4 and a text_encoder_4 initialized from the meta-llama/Meta-Llama-3.1-8B-Instruct model.

    Parameter Notes:

    • guidance_scale: Use 5.0 for the full model. For dev and fast models, use 0.0.
    • num_inference_steps: Use 50 for full, 28 for dev, and 16 for fast.
    import torch
    from transformers import PreTrainedTokenizerFast, LlamaForCausalLM
    from diffusers import HiDreamImagePipeline
    
    tokenizer_4 = PreTrainedTokenizerFast.from_pretrained("meta-llama/Meta-Llama-3.1-8B-Instruct")
    text_encoder_4 = LlamaForCausalLM.from_pretrained(
        "meta-llama/Meta-Llama-3.1-8B-Instruct",
        output_hidden_states=True,
        output_attentions=True,
        torch_dtype=torch.bfloat16,
    )
    
    pipe = HiDreamImagePipeline.from_pretrained(
        "HiDream-ai/HiDream-I1-Full",  # "HiDream-ai/HiDream-I1-Dev" | "HiDream-ai/HiDream-I1-Fast"
        tokenizer_4=tokenizer_4,
        text_encoder_4=text_encoder_4,
        torch_dtype=torch.bfloat16,
    )
    
    pipe = pipe.to('cuda')
    
    image = pipe(
        'A cat holding a sign that says "HiDream.ai".',
        height=1024,
        width=1024,
        guidance_scale=5.0,  # 0.0 for Dev&Fast
        num_inference_steps=50,  # 28 for Dev and 16 for Fast
        generator=torch.Generator("cuda").manual_seed(0),
    ).images[0]
    image.save("output.png")