Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upload binarydm-paddle #1905

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions example/BinaryDM/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# BinaryDM in PaddlePaddle

## 1. 简介

本示例介绍了一种权重二值化的扩散模型的训练方法。通过可学习多基二值化器和低秩表示模仿来增强二值扩散模型的表征能力并提高优化表现,能支持将扩散模型应用于极限资源任务场景中。

技术详情见论文 [BinaryDM: Accurate Weight Binarization for Efficient Diffusion Models](https://arxiv.org/pdf/2404.05662v4)

![binarydm](.\imgs\binarydm.png)

## 2.训练

### 2.1 环境准备

- paddlepaddle>=2.0.1 (paddlepaddle-gpu>=2.0.1)
- visualdl
- lmdb

### 2.2 启动训练

```
python main_binarydm.py --config {DATASET}.yml --exp {PROJECT_PATH} --doc {MODEL_NAME} --ni
```

## 致谢

本实现源于下列开源仓库:

- [https://github.com/Xingyu-Zheng/BinaryDM](https://github.com/Xingyu-Zheng/BinaryDM) (official implementation of BinaryDM).
- [https://openi.pcl.ac.cn/iMon/ddim-paddle](https://openi.pcl.ac.cn/iMon/ddim-paddle) (PaddlePaddle version for DDIM).
- [https://github.com/ermongroup/ddim](https://github.com/ermongroup/ddim) (code structure).
50 changes: 50 additions & 0 deletions example/BinaryDM/configs/bedroom.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
data:
dataset: "LSUN"
category: "bedroom"
image_size: 256
channels: 3
logit_transform: false
uniform_dequantization: false
gaussian_dequantization: false
random_flip: true
rescaled: true
num_workers: 32

model:
type: "simple"
in_channels: 3
out_ch: 3
ch: 128
ch_mult: [1, 1, 2, 2, 4, 4]
num_res_blocks: 2
attn_resolutions: [16, ]
dropout: 0.0
var_type: fixedsmall
ema_rate: 0.999
ema: True
resamp_with_conv: True

diffusion:
beta_schedule: linear
beta_start: 0.0001
beta_end: 0.02
num_diffusion_timesteps: 1000

training:
batch_size: 64
n_epochs: 10000
n_iters: 5000000
snapshot_freq: 5000
validation_freq: 2000

sampling:
batch_size: 32
last_only: True

optim:
weight_decay: 0.000
optimizer: "Adam"
lr: 0.00002
beta1: 0.9
amsgrad: false
eps: 0.00000001
50 changes: 50 additions & 0 deletions example/BinaryDM/configs/celeba.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
data:
dataset: "CELEBA"
image_size: 64
channels: 3
logit_transform: false
uniform_dequantization: false
gaussian_dequantization: false
random_flip: true
rescaled: true
num_workers: 4

model:
type: "simple"
in_channels: 3
out_ch: 3
ch: 128
ch_mult: [1, 2, 2, 2, 4]
num_res_blocks: 2
attn_resolutions: [16, ]
dropout: 0.1
var_type: fixedlarge
ema_rate: 0.9999
ema: True
resamp_with_conv: True

diffusion:
beta_schedule: linear
beta_start: 0.0001
beta_end: 0.02
num_diffusion_timesteps: 1000

training:
batch_size: 128
n_epochs: 10000
n_iters: 5000000
snapshot_freq: 5000
validation_freq: 20000

sampling:
batch_size: 32
last_only: True

optim:
weight_decay: 0.000
optimizer: "Adam"
lr: 0.0002
beta1: 0.9
amsgrad: false
eps: 0.00000001
grad_clip: 1.0
50 changes: 50 additions & 0 deletions example/BinaryDM/configs/church.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
data:
dataset: "LSUN"
category: "church_outdoor"
image_size: 256
channels: 3
logit_transform: false
uniform_dequantization: false
gaussian_dequantization: false
random_flip: true
rescaled: true
num_workers: 32

model:
type: "simple"
in_channels: 3
out_ch: 3
ch: 128
ch_mult: [1, 1, 2, 2, 4, 4]
num_res_blocks: 2
attn_resolutions: [16, ]
dropout: 0.0
var_type: fixedsmall
ema_rate: 0.999
ema: True
resamp_with_conv: True

diffusion:
beta_schedule: linear
beta_start: 0.0001
beta_end: 0.02
num_diffusion_timesteps: 1000

training:
batch_size: 64
n_epochs: 10000
n_iters: 5000000
snapshot_freq: 5000
validation_freq: 2000

sampling:
batch_size: 32
last_only: True

optim:
weight_decay: 0.000
optimizer: "Adam"
lr: 0.00002
beta1: 0.9
amsgrad: false
eps: 0.00000001
50 changes: 50 additions & 0 deletions example/BinaryDM/configs/cifar10.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
data:
dataset: "CIFAR10"
image_size: 32
channels: 3
logit_transform: false
uniform_dequantization: false
gaussian_dequantization: false
random_flip: true
rescaled: true
num_workers: 4

model:
type: "simple"
in_channels: 3
out_ch: 3
ch: 128
ch_mult: [1, 2, 2, 2]
num_res_blocks: 2
attn_resolutions: [16, ]
dropout: 0.1
var_type: fixedlarge
ema_rate: 0.9999
ema: True
resamp_with_conv: True

diffusion:
beta_schedule: linear
beta_start: 0.0001
beta_end: 0.02
num_diffusion_timesteps: 1000

training:
batch_size: 128
n_epochs: 10000
n_iters: 5000000
snapshot_freq: 5000
validation_freq: 2000

sampling:
batch_size: 64
last_only: True

optim:
weight_decay: 0.000
optimizer: "Adam"
lr: 0.0002
beta1: 0.9
amsgrad: false
eps: 0.00000001
grad_clip: 1.0
51 changes: 51 additions & 0 deletions example/BinaryDM/configs/cifar10_improved.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
data:
dataset: "CIFAR10"
image_size: 32
channels: 3
logit_transform: false
uniform_dequantization: false
gaussian_dequantization: false
random_flip: true
rescaled: true
num_workers: 4

model:
type: "simple"
in_channels: 3
out_ch: 3
ch: 128
ch_mult: [1, 2, 2, 2]
num_res_blocks: 2
attn_resolutions: [16, ]
dropout: 0.1
var_type: fixedlarge
ema_rate: 0.9999
ema: True
resamp_with_conv: True
use_scale_shift_norm: True

diffusion:
beta_schedule: cosine
beta_start: null
beta_end: null
num_diffusion_timesteps: 1000

training:
batch_size: 128
n_epochs: 10000
n_iters: 5000000
snapshot_freq: 5000
validation_freq: 2000

sampling:
batch_size: 64
last_only: True

optim:
weight_decay: 0.000
optimizer: "Adam"
lr: 0.0002
beta1: 0.9
amsgrad: false
eps: 0.00000001
grad_clip: 1.0
Loading