English
liushanyuan18 commited on
Commit
9ca56c3
·
verified ·
1 Parent(s): 8e0c107

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +325 -3
README.md CHANGED
@@ -1,3 +1,325 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ language:
4
+ - en
5
+ ---
6
+
7
+ <p align="center">
8
+ <img src="assets/logo.png" alt="RPiAE Logo" width="200">
9
+ </p>
10
+
11
+ <h1 align="center">RPiAE: A Representation-Pivoted Autoencoder Enhancing Both Image Generation and Editing</h1>
12
+
13
+ [![Project Page](https://img.shields.io/badge/Project%20Page-RPiAE-1f6feb?style=flat)](https://arthuring.github.io/RPiAE-page/)
14
+ [![GitHub](https://img.shields.io/badge/GitHub-360CVGroup%2FRPiAE-181717?style=flat&logo=github)](https://github.com/360CVGroup/RPiAE)
15
+ [![Hugging Face](https://img.shields.io/badge/Hugging%20Face-RPiAE-ff9900?style=flat)](https://huggingface.co/qihoo360/RPiAE)
16
+ [![arXiv](https://img.shields.io/badge/arXiv-2603.19206-B31B1B?style=flat)](https://arxiv.org/abs/2603.19206)
17
+
18
+ This repository contains the PyTorch implementation of **RPiAE** and the corresponding latent diffusion training pipeline.
19
+
20
+ RPiAE follows a two-stage pipeline:
21
+ - **Stage 1 (image reconstruction):** train the RPiAE model to learn high-quality latent representations and reconstruction.
22
+ - **Stage 2 (class conditional image generation):** train a diffusion transformer in the pretrained RPiAE latent space for image generation.
23
+
24
+ ## TODO
25
+
26
+ - [x] Release the RPiAE model
27
+ - [x] Release the training code for RPiAE
28
+ - [x] Release pretrained weights
29
+ - [ ] Release the training code for T2I
30
+
31
+ ## Environment
32
+
33
+ ### Dependency Setup
34
+ 1. Create environment and install via `uv`:
35
+ ```bash
36
+ conda create -n rpiae python=3.10 -y
37
+ conda activate rpiae
38
+ pip install uv
39
+
40
+ # Install PyTorch 2.8.0 with CUDA 12.9 # or your own cuda version
41
+ uv pip install torch==2.8.0 torchvision torchaudio --index-url https://download.pytorch.org/whl/cu129
42
+
43
+ # Install other dependencies
44
+ uv pip install -r requirements.txt
45
+ ```
46
+
47
+ ## Data & Model Preparation
48
+
49
+ ### Download Pre-trained Models
50
+
51
+ Pretrained checkpoints are available on [Hugging Face](https://huggingface.co/qihoo360/RPiAE).
52
+
53
+ Download the pretrain weights to `./model_weights`:
54
+
55
+ ```bash
56
+ hf download qihoo360/RPiAE \
57
+ --repo-type model \
58
+ --local-dir ./model_weights
59
+ ```
60
+
61
+ ### Prepare Dataset
62
+
63
+ 1. Download ImageNet-1k.
64
+ 2. Point scripts to the training split or validation split via `--data-path`.
65
+
66
+ ## Config-based Initialization
67
+
68
+ All training and sampling entrypoints are driven by OmegaConf YAML files. A
69
+ single config describes the Stage 1 autoencoder, the Stage 2 diffusion model,
70
+ and the solver used during training or inference. A minimal example looks like:
71
+
72
+ ```yaml
73
+ stage_1:
74
+ target: stage1.RPiAE / stage1.RPiAE_VB
75
+ params: { ... }
76
+ ckpt: <path_to_ckpt>
77
+
78
+ stage_2:
79
+ target: stage2.models.lightningDiT.LightningDiT
80
+ params: { ... }
81
+ ckpt: <path_to_ckpt>
82
+
83
+ transport:
84
+ params:
85
+ path_type: Linear
86
+ prediction: velocity
87
+ ...
88
+ sampler:
89
+ mode: ODE
90
+ params:
91
+ num_steps: 50
92
+ ...
93
+ guidance:
94
+ method: cfg/autoguidance
95
+ scale: 1.0
96
+ ...
97
+ misc:
98
+ latent_size: [64, 16, 16]
99
+ num_classes: 1000
100
+ training:
101
+ ...
102
+ eval:
103
+ ...
104
+ ```
105
+
106
+ - `stage_1` defines the **RPiAE training process** (reconstruction-oriented training).
107
+ - `stage_2` defines the **generation model** (LightningDiT) in the RPiAE latent space.
108
+ - `transport`, `sampler`, and `guidance` control ODE/SDE solving and guidance strategy.
109
+ - `misc` stores latent shape and shared constants.
110
+ - `training` and `eval` contain optimization and online evaluation settings.
111
+ - Stage 1 training configs additionally include a top-level `gan` block for discriminator and loss schedule.
112
+
113
+ ### Provided Configs
114
+
115
+ #### Stage1
116
+
117
+ - Pretrained:
118
+ - `configs/stage1/pretrained/DINOv2-B_decXL_RPiAE.yaml`
119
+ - Training:
120
+ - `configs/stage1/training/DINOv2-B_decXL_RPiAE_stage1.yaml`
121
+ - `configs/stage1/training/DINOv2-B_decXL_RPiAE_stage2.yaml`
122
+ - `configs/stage1/training/DINOv2-B_decXL_RPiAE_stage3.yaml`
123
+
124
+ #### Stage2
125
+
126
+ - Training:
127
+ - `configs/stage2/training/ImageNet256/LightingDiT-XL_f16d64rpiae-v2b_vitxl.yaml`
128
+ - Sampling:
129
+ - `configs/stage2/sampling/ImageNet256/LightingDiT-XL_d64rpiae-v2b_vitxl.yaml`
130
+ - `configs/stage2/sampling/ImageNet256/LightingDiT-XL_d64rpiae-v2b_vitxl_AG.yaml`
131
+
132
+ ## RPiAE Training & image reconstruction evaluation
133
+ Use the provided shell scripts with the corresponding configs.
134
+
135
+ If you use wandb logging, also configure:
136
+
137
+ ```bash
138
+ EXPERIMENT_NAME=
139
+ ENTITY=
140
+ PROJECT=
141
+ ```
142
+
143
+ ### Single-GPU Training
144
+
145
+ #### Train Stage 1
146
+
147
+ ```bash
148
+ bash run_train_stage1_rpiae_s1.sh \
149
+ configs/stage1/training/DINOv2-B_decXL_RPiAE_stage1.yaml
150
+ ```
151
+
152
+ #### Train Stage 2
153
+
154
+ ```bash
155
+ bash run_train_stage1_rpiae_s23.sh \
156
+ configs/stage1/training/DINOv2-B_decXL_RPiAE_stage2.yaml
157
+ ```
158
+
159
+ #### Train Stage 3
160
+
161
+ ```bash
162
+ bash run_train_stage1_rpiae_s23.sh \
163
+ configs/stage1/training/DINOv2-B_decXL_RPiAE_stage3.yaml
164
+ ```
165
+
166
+ ### Multi-GPU Training
167
+
168
+ For multi-GPU or multi-node training, please use the `*_mult*.sh` scripts instead.
169
+
170
+ Before launching, configure the distributed variables in the shell script:
171
+
172
+ ```bash
173
+ RANK=
174
+ MASTER_ADDR=
175
+ GPUS_PER_NODE=
176
+ NNODES=
177
+ MASTER_PORT=
178
+ ```
179
+
180
+
181
+ Then run the corresponding multi-GPU scripts.
182
+
183
+ #### Train Stage 1
184
+
185
+ ```bash
186
+ bash run_train_stage1_mult_rpiae_s1.sh \
187
+ configs/stage1/training/DINOv2-B_decXL_RPiAE_stage1.yaml
188
+ ```
189
+
190
+ #### Train Stage 2
191
+
192
+ ```bash
193
+ bash run_train_stage1_mult_rpiae_s23.sh \
194
+ configs/stage1/training/DINOv2-B_decXL_RPiAE_stage2.yaml
195
+ ```
196
+
197
+ #### Train Stage 3
198
+
199
+ ```bash
200
+ bash run_train_stage1_mult_rpiae_s23.sh \
201
+ configs/stage1/training/DINOv2-B_decXL_RPiAE_stage3.yaml
202
+ ```
203
+
204
+ ### Reconstruction Evaluation
205
+
206
+ ```bash
207
+ bash run_sample_reconstruction_eval.sh \
208
+ configs/stage1/pretrained/DINOv2-B_decXL_RPiAE.yaml
209
+ ```
210
+
211
+ ## Latent Diffusion Transformer Training & Class conditional Image Generation Evaluation
212
+
213
+ ### Training
214
+
215
+ ```bash
216
+ torchrun --standalone --nnodes=1 --nproc_per_node=N \
217
+ src/train_diffusion_rpiae.py \
218
+ --config <training_config> \
219
+ --data-path <imagenet_train_split> \
220
+ --results-dir ckpts/diffusion \
221
+ --compile \
222
+ --precision fp32
223
+ ```
224
+
225
+ For multi-GPU / multi-node training, use:
226
+
227
+ ```bash
228
+ bash run_train_mult_diffusion.sh \
229
+ configs/stage2/training/ImageNet256/LightingDiT-XL_f16d64rpiae-v2b_vitxl.yaml
230
+ ```
231
+
232
+ For multi-node launch, set:
233
+
234
+ ```bash
235
+ export RANK=<node_rank>
236
+ export MASTER_ADDR=<master_node_ip_or_hostname>
237
+ ```
238
+
239
+ Although `bf16` is supported, we recommend using **fp32** for more stable training.
240
+
241
+ ### Sampling
242
+
243
+ `src/sample.py` uses the same config schema to draw a small batch of images on a
244
+ single device and saves them to `sample.png`:
245
+
246
+ ```bash
247
+ python src/sample.py \
248
+ --config <sample_config> \
249
+ --seed 42
250
+ ```
251
+
252
+ ### Distributed sampling for evaluation
253
+
254
+ `src/sample_ddp.py` parallelises sampling across GPUs, producing PNGs and an
255
+ FID-ready `.npz`:
256
+
257
+ ```bash
258
+ torchrun --standalone --nnodes=1 --nproc_per_node=N \
259
+ src/sample_ddp.py \
260
+ --config <sample_config> \
261
+ --sample-dir samples \
262
+ --precision fp32/bf16 \
263
+ --label-sampling equal
264
+ ```
265
+
266
+ `--label-sampling {equal,random}`: `equal` uses exactly 50 images per class for FID-50k; `random` uniformly samples labels. We use `equal` by default. We recommend using fp32 when model FID is low.
267
+
268
+ Autoguidance and classifier-free guidance are controlled via the config’s `guidance` block.
269
+
270
+ ## Evaluation
271
+
272
+ ### ADM Suite FID setup
273
+
274
+ Use the ADM evaluation suite to score generated samples:
275
+
276
+ 1. Clone the repo:
277
+
278
+ ```bash
279
+ git clone https://github.com/openai/guided-diffusion.git
280
+ cd guided-diffusion/evaluation
281
+ ```
282
+
283
+ 2. Create an environment and install dependencies:
284
+
285
+ ```bash
286
+ conda create -n adm-fid python=3.10
287
+ conda activate adm-fid
288
+ pip install 'tensorflow[and-cuda]'==2.19 scipy requests tqdm
289
+ ```
290
+
291
+ 3. Download ImageNet statistics (256×256 shown here):
292
+
293
+ ```bash
294
+ wget https://openaipublic.blob.core.windows.net/diffusion/jul-2021/ref_batches/imagenet/256/VIRTUAL_imagenet256_labeled.npz
295
+ ```
296
+
297
+ 4. Evaluate:
298
+
299
+ ```bash
300
+ python evaluator.py VIRTUAL_imagenet256_labeled.npz /path/to/samples.npz
301
+ ```
302
+
303
+ ## Acknowledgement
304
+
305
+ This code is built upon the following repositories:
306
+
307
+ * [SiT](https://github.com/willisma/sit)
308
+ * [DDT](https://github.com/MCG-NJU/DDT)
309
+ * [LightningDiT](https://github.com/hustvl/LightningDiT/)
310
+ * [MAE](https://github.com/facebookresearch/mae)
311
+ * [RAE](https://github.com/bytetriper/RAE)
312
+
313
+ ## Citation
314
+ If you find this repository useful, please consider citing our paper:
315
+ ```
316
+ @misc{RPiAE,
317
+ title={RPiAE: A Representation-Pivoted Autoencoder Enhancing Both Image Generation and Editing},
318
+ author={Yue Gong and Hongyu Li and Shanyuan Liu and Bo Cheng and Yuhang Ma and Liebucha Wu and Xiaoyu Wu and Manyuan Zhang and Dawei Leng and Yuhui Yin and Lijun Zhang},
319
+ year={2026},
320
+ eprint={2603.19206},
321
+ archivePrefix={arXiv},
322
+ primaryClass={cs.CV},
323
+ url={https://arxiv.org/abs/2603.19206},
324
+ }
325
+ ```