1、依赖关系和安装
首先克隆存储库:
git clone https://github.com/tencent/HunyuanDiT
cd HunyuanDiT
unzip HunyuanDiT-main.zip
2、一个environment.yml
用于设置 Conda 环境的文件一个environment.yml
用于设置 Conda 环境的文件
conda create -n hunyuandit python==3.8.12
conda activate hunyuandit
pip install -r requirements.txt -i https://pypi.mirrors.ustc.edu.cn/simple
3、 (Optional) Install flash attention v2 for acceleration (requires CUDA 11.6 or above)
这个命令的目的是从GitHub仓库安装flash attention v2的v2.1.2.post3版本。要运行此命令,请确保您已经安装了Git和Python的pip包管理器(注意,这个命令需要CUDA 11.6或更高版本)
python -m pip install git+https://github.com/Dao-AILab/flash-attention.git@v2.1.2.post3
下载预训练模型
要下载模型,请首先安装huggingface-cli。 (详细说明可在此处找到。)
python -m pip install "huggingface_hub[cli]"
然后使用以下命令下载模型:
# Create a directory named 'ckpts' where the model will be saved, fulfilling the prerequisites for running the demo.
mkdir ckpts
# Use the huggingface-cli tool to download the model.
# The download time may vary from 10 minutes to 1 hour depending on network conditions.
huggingface-cli download Tencent-Hunyuan/HunyuanDiT --local-dir ./ckpts
注意:如果No such file or directory: 'ckpts/.huggingface/.gitignore.lock'
在下载过程中出现类似错误,可以忽略该错误并通过执行重试该命令huggingface-cli download Tencent-Hunyuan/HunyuanDiT --local-dir ./ckpts
所有模型都会自动下载。有关该模型的更多信息,请访问此处的Hugging Face 存储库。
如模型文件无法下载使用如下命令:
git clone https://huggingface.co/Tencent-Hunyuan/HunyuanDiT
推理
使用渐变
在运行以下命令之前,请确保您已激活 conda 环境。
# By default, we start a Chinese UI.
python app/hydit_app.py# Using Flash Attention for acceleration.
python app/hydit_app.py --infer-mode fa# You can disable the enhancement model if the GPU memory is insufficient.
# The enhancement will be unavailable until you restart the app without the `--no-enhance` flag.
python app/hydit_app.py --no-enhance# Start with English UI
python app/hydit_app.py --lang en
使用命令行
我们提供3种模式来快速启动:
# Prompt Enhancement + Text-to-Image. Torch mode
python sample_t2i.py --prompt "渔舟唱晚"# Only Text-to-Image. Torch mode
python sample_t2i.py --prompt "渔舟唱晚" --no-enhance# Only Text-to-Image. Flash Attention mode
python sample_t2i.py --infer-mode fa --prompt "渔舟唱晚"# Generate an image with other image sizes.
python sample_t2i.py --prompt "渔舟唱晚" --image-size 1280 768
更多示例提示可以在example_prompts.txt中找到
更多配置
我们列出了一些更有用的配置以方便使用:
争论 | 默认 | 描述 |
---|---|---|
--prompt | 没有任何 | 图像生成的文字提示 |
--image-size | 1024 1024 | 生成图像的大小 |
--seed | 42 | 用于生成图像的随机种子 |
--infer-steps | 100 | 采样步数 |
--negative | - | 图像生成的负面提示 |
--infer-mode | 火炬 | 推理模式(torch 或 fa) |
--sampler | DDPM | 扩散采样器(ddpm、ddim 或 dpmms) |
--no-enhance | 错误的 | 禁用提示增强模型 |
--model-root | 控制点 | 模型检查点的根目录 |
--load-key | 埃玛 | 加载学生模型或EMA模型(ema或模块) |