Views
No views yet
1conda create -n diffsynth python=3.10 -y
2conda activate diffsynth
3
4# 请根据你机器上的 CUDA 版本调整下面这条命令
5pip install torch==2.7.1 torchvision==0.22.1 --index-url https://download.pytorch.org/whl/cu118
6
7pip install -r requirements.txtrequirements.txt 包含的关键依赖:safetensors, transformers, einops, Pillow, numpy, tqdm, modelscope。| # | 名称 | 用途 | 来源 | 大小 |
|---|---|---|---|---|
| A | HiDream-O1-Image(base model) | 提供 tokenizer + image processor(AutoProcessor.from_pretrained) | ModelScope / HuggingFace | ~35 GB(含权重);若只要 tokenizer/processor 约 12 MB |
| B | IR fine-tuned checkpoint | DiT 网络的 IR 微调权重,直接覆盖 DiT 全部参数 | 内部产出(本仓库 fine-tune 得到的 step-*.safetensors) | ~14 GB |
AutoProcessor.from_pretrained(base_model_dir) 只用到 tokenizer + image processor 的配置,
并不加载 shard 权重。你有两种选择:1export BASE_MODEL_DIR=/path/to/hidream_o1_image
2
3modelscope download --model HiDream-ai/HiDream-O1-Image --local_dir $BASE_MODEL_DIR \
4 config.json generation_config.json chat_template.json \
5 preprocessor_config.json video_preprocessor_config.json \
6 tokenizer_config.json tokenizer.json vocab.json merges.txt说明:run_inference.py不会加载 base model 的 DiT/VAE 权重,DiT 权重完全由步骤 B 的 IR checkpoint 提供。 因此这种最小下载方式(约 12 MB)足以支撑本仓库的 IR 推理。
modelscope):1# 目标目录,随意起名,后面 run_inference.py 里要指向它
2export BASE_MODEL_DIR=/path/to/hidream_o1_image
3
4# 通过 modelscope CLI 下载
5modelscope download --model HiDream-ai/HiDream-O1-Image --local_dir $BASE_MODEL_DIR1pip install -U "huggingface_hub[cli]"
2huggingface-cli download HiDream-ai/HiDream-O1-Image --local-dir $BASE_MODEL_DIR$BASE_MODEL_DIR/
├── config.json
├── generation_config.json
├── chat_template.json
├── preprocessor_config.json
├── video_preprocessor_config.json
├── tokenizer_config.json
├── tokenizer.json
├── vocab.json
├── merges.txt
├── model.safetensors.index.json
├── model-00001-of-00008.safetensors ← 这些 shards 本次 IR 推理其实用不上
├── model-00002-of-00008.safetensors
├── ...
└── model-00008-of-00008.safetensorsexport IR_CKPT=/path/to/dreamIR/dreamir.safetensorsrun_inference.py,把顶部这两行改成你自己的路径:1# run_inference.py, line 21-22
2base_model_dir = "/path/to/hidream_o1_image" # ← 步骤 2.1 下载到的目录
3ir_checkpoint = "/path/to/dreamIR/dreamir.safetensors" # ← 步骤 2.2 拿到的文件output_folder(默认 results/)DEFAULT_INPUT_FOLDER(也可以命令行 --input_folder 传入,见下文)PROMPT(IR restoration 用的固定 prompt,一般不需要改).jpg / .jpeg / .png,脚本目前的实现假设图像为 512×512,
其他尺寸会按图像自身尺寸跑,但需保证宽高能被 patch size 整除):1YOUR_LQ_DATA_FOLDER_PATH=/path/to/your/LQ_images
2
3python run_inference.py --input_folder $YOUR_LQ_DATA_FOLDER_PATHInstantiating DiT architecture directly on cuda in torch.bfloat16...
Loading IR checkpoint directly to cuda: /path/to/dreamir.safetensors
Loading processor (tokenizer + image preprocessor)...
Pipeline ready.
Found N images. Saving to: results
IR Processing: 100%|██████████| N/N [xx:xx<00:00, ...]
Done. Saved to: resultsoutput_folder 中,同名文件(后缀改 .jpg)。dreamir/
├── README.md # 本文件
├── requirements.txt # Python 依赖
├── run_inference.py # 推理入口脚本
├── diffsynth/ # 精简过的 DiffSynth-Studio 代码(HiDream-O1-Image 相关模块)
│ ├── pipelines/hidream_o1_image.py
│ ├── models/
│ │ ├── hidream_o1_image_dit.py
│ │ └── hidream_common.py
│ └── ...
└── results/ # 推理产物默认保存目录1# 0. 装环境
2conda create -n diffsynth python=3.10 -y && conda activate diffsynth
3pip install torch==2.7.1 torchvision==0.22.1 --index-url https://download.pytorch.org/whl/cu118
4pip install -r requirements.txt
5
6# 1. 下载 base model 里 processor/tokenizer 相关的小文件(推理只需这些,约 12 MB)
7export BASE_MODEL_DIR=$PWD/checkpoints/hidream_o1_image
8modelscope download --model HiDream-ai/HiDream-O1-Image --local_dir $BASE_MODEL_DIR \
9 config.json generation_config.json chat_template.json \
10 preprocessor_config.json video_preprocessor_config.json \
11 tokenizer_config.json tokenizer.json vocab.json merges.txt
12
13# 2. 拿到 IR checkpoint(内部/自训练)
14export IR_CKPT=/path/to/dreamir.safetensors
15
16# 3. 把上面两个变量的值填进 run_inference.py 的 base_model_dir / ir_checkpoint
17
18# 4. 跑!
19python run_inference.py --input_folder /path/to/your/LQ_images