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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: apache-2.0
|
3 |
+
tags:
|
4 |
+
- text-to-image
|
5 |
+
- safetensors
|
6 |
+
---
|
7 |
+
|
8 |
+
# Lumina-Next-SFT
|
9 |
+
|
10 |
+
The `Lumina-Next-SFT` is a Next-DiT model containing 2B parameters and utilizes [Gemma-2B](https://huggingface.co/google/gemma-2b) as the text encoder, enhanced through high-quality supervised fine-tuning (SFT).
|
11 |
+
|
12 |
+
Our generative model has `Next-DiT` as the backbone, the text encoder is the `Gemma` 2B model, and the VAE uses a version of `sdxl` fine-tuned by stabilityai.
|
13 |
+
|
14 |
+
- Generation Model: Next-DiT
|
15 |
+
- Text Encoder: [Gemma-2B](https://huggingface.co/google/gemma-2b)
|
16 |
+
- VAE: [stabilityai/sdxl-vae](https://huggingface.co/stabilityai/sdxl-vae)
|
17 |
+
|
18 |
+
[paper](https://arxiv.org/abs/2405.05945)
|
19 |
+
|
20 |
+
## 📰 News
|
21 |
+
|
22 |
+
- [2024-06-08] 🎉🎉🎉 We have released the `Lumina-Next-SFT` model.
|
23 |
+
|
24 |
+
- [2024-05-28] We updated the `Lumina-Next-T2I` model to support 2K Resolution image generation.
|
25 |
+
|
26 |
+
- [2024-05-16] We have converted the `.pth` weights to `.safetensors` weights. Please pull the latest code to use `demo.py` for inference.
|
27 |
+
|
28 |
+
- [2024-05-12] We release the next version of `Lumina-T2I`, called `Lumina-Next-T2I` for faster and lower memory usage image generation model.
|
29 |
+
|
30 |
+
## 🎮 Model Zoo
|
31 |
+
|
32 |
+
More checkpoints of our model will be released soon~
|
33 |
+
|
34 |
+
| Resolution | Next-DiT Parameter| Text Encoder | Prediction | Download URL |
|
35 |
+
| ---------- | ----------------------- | ------------ | -----------|-------------- |
|
36 |
+
| 1024 | 2B | [Gemma-2B](https://huggingface.co/google/gemma-2b) | Rectified Flow | [hugging face](https://huggingface.co/Alpha-VLLM/Lumina-Next-SFT) |
|
37 |
+
|
38 |
+
## Installation
|
39 |
+
|
40 |
+
Before installation, ensure that you have a working ``nvcc``
|
41 |
+
|
42 |
+
```bash
|
43 |
+
# The command should work and show the same version number as in our case. (12.1 in our case).
|
44 |
+
nvcc --version
|
45 |
+
```
|
46 |
+
|
47 |
+
On some outdated distros (e.g., CentOS 7), you may also want to check that a late enough version of
|
48 |
+
``gcc`` is available
|
49 |
+
|
50 |
+
```bash
|
51 |
+
# The command should work and show a version of at least 6.0.
|
52 |
+
# If not, consult distro-specific tutorials to obtain a newer version or build manually.
|
53 |
+
gcc --version
|
54 |
+
```
|
55 |
+
|
56 |
+
Downloading Lumina-T2X repo from GitHub:
|
57 |
+
|
58 |
+
```bash
|
59 |
+
git clone https://github.com/Alpha-VLLM/Lumina-T2X
|
60 |
+
```
|
61 |
+
|
62 |
+
### 1. Create a conda environment and install PyTorch
|
63 |
+
|
64 |
+
Note: You may want to adjust the CUDA version [according to your driver version](https://docs.nvidia.com/deploy/cuda-compatibility/#default-to-minor-version).
|
65 |
+
|
66 |
+
```bash
|
67 |
+
conda create -n Lumina_T2X -y
|
68 |
+
conda activate Lumina_T2X
|
69 |
+
conda install python=3.11 pytorch==2.1.0 torchvision==0.16.0 torchaudio==2.1.0 pytorch-cuda=12.1 -c pytorch -c nvidia -y
|
70 |
+
```
|
71 |
+
|
72 |
+
### 2. Install dependencies
|
73 |
+
|
74 |
+
```bash
|
75 |
+
pip install diffusers fairscale accelerate tensorboard transformers gradio torchdiffeq click
|
76 |
+
```
|
77 |
+
|
78 |
+
or you can use
|
79 |
+
|
80 |
+
```bash
|
81 |
+
cd lumina_next_t2i
|
82 |
+
pip install -r requirements.txt
|
83 |
+
```
|
84 |
+
|
85 |
+
### 3. Install ``flash-attn``
|
86 |
+
|
87 |
+
```bash
|
88 |
+
pip install flash-attn --no-build-isolation
|
89 |
+
```
|
90 |
+
|
91 |
+
### 4. Install [nvidia apex](https://github.com/nvidia/apex) (optional)
|
92 |
+
|
93 |
+
>[!Warning]
|
94 |
+
> While Apex can improve efficiency, it is *not* a must to make Lumina-T2X work.
|
95 |
+
>
|
96 |
+
> Note that Lumina-T2X works smoothly with either:
|
97 |
+
> + Apex not installed at all; OR
|
98 |
+
> + Apex successfully installed with CUDA and C++ extensions.
|
99 |
+
>
|
100 |
+
> However, it will fail when:
|
101 |
+
> + A Python-only build of Apex is installed.
|
102 |
+
>
|
103 |
+
> If the error `No module named 'fused_layer_norm_cuda'` appears, it typically means you are using a Python-only build of Apex. To resolve this, please run `pip uninstall apex`, and Lumina-T2X should then function correctly.
|
104 |
+
|
105 |
+
You can clone the repo and install following the official guidelines (note that we expect a full
|
106 |
+
build, i.e., with CUDA and C++ extensions)
|
107 |
+
|
108 |
+
```bash
|
109 |
+
pip install ninja
|
110 |
+
git clone https://github.com/NVIDIA/apex
|
111 |
+
cd apex
|
112 |
+
# if pip >= 23.1 (ref: https://pip.pypa.io/en/stable/news/#v23-1) which supports multiple `--config-settings` with the same key...
|
113 |
+
pip install -v --disable-pip-version-check --no-cache-dir --no-build-isolation --config-settings "--build-option=--cpp_ext" --config-settings "--build-option=--cuda_ext" ./
|
114 |
+
# otherwise
|
115 |
+
pip install -v --disable-pip-version-check --no-cache-dir --no-build-isolation --global-option="--cpp_ext" --global-option="--cuda_ext" ./
|
116 |
+
```
|
117 |
+
|
118 |
+
## Inference
|
119 |
+
|
120 |
+
To ensure that our generative model is ready to use right out of the box, we provide a user-friendly CLI program and a locally deployable Web Demo site.
|
121 |
+
|
122 |
+
### CLI
|
123 |
+
|
124 |
+
1. Install Lumina-Next-T2I
|
125 |
+
|
126 |
+
```bash
|
127 |
+
pip install -e .
|
128 |
+
```
|
129 |
+
|
130 |
+
2. Prepare the pre-trained model
|
131 |
+
|
132 |
+
⭐⭐ (Recommended) you can use huggingface_cli to download our model:
|
133 |
+
|
134 |
+
```bash
|
135 |
+
huggingface-cli download --resume-download Alpha-VLLM/Lumina-Next-T2I --local-dir /path/to/ckpt
|
136 |
+
```
|
137 |
+
|
138 |
+
or using git for cloning the model you want to use:
|
139 |
+
|
140 |
+
```bash
|
141 |
+
git clone https://huggingface.co/Alpha-VLLM/Lumina-Next-T2I
|
142 |
+
```
|
143 |
+
|
144 |
+
1. Setting your personal inference configuration
|
145 |
+
|
146 |
+
Update your own personal inference settings to generate different styles of images, checking `config/infer/config.yaml` for detailed settings. Detailed config structure:
|
147 |
+
|
148 |
+
> `/path/to/ckpt` should be a directory containing `consolidated*.pth` and `model_args.pth`
|
149 |
+
|
150 |
+
```yaml
|
151 |
+
- settings:
|
152 |
+
|
153 |
+
model:
|
154 |
+
ckpt: "/path/to/ckpt" # if ckpt is "", you should use `--ckpt` for passing model path when using `lumina` cli.
|
155 |
+
ckpt_lm: "" # if ckpt is "", you should use `--ckpt_lm` for passing model path when using `lumina` cli.
|
156 |
+
token: "" # if LLM is a huggingface gated repo, you should input your access token from huggingface and when token is "", you should `--token` for accessing the model.
|
157 |
+
|
158 |
+
transport:
|
159 |
+
path_type: "Linear" # option: ["Linear", "GVP", "VP"]
|
160 |
+
prediction: "velocity" # option: ["velocity", "score", "noise"]
|
161 |
+
loss_weight: "velocity" # option: [None, "velocity", "likelihood"]
|
162 |
+
sample_eps: 0.1
|
163 |
+
train_eps: 0.2
|
164 |
+
|
165 |
+
ode:
|
166 |
+
atol: 1e-6 # Absolute tolerance
|
167 |
+
rtol: 1e-3 # Relative tolerance
|
168 |
+
reverse: false # option: true or false
|
169 |
+
likelihood: false # option: true or false
|
170 |
+
|
171 |
+
infer:
|
172 |
+
resolution: "1024x1024" # option: ["1024x1024", "512x2048", "2048x512", "(Extrapolation) 1664x1664", "(Extrapolation) 1024x2048", "(Extrapolation) 2048x1024"]
|
173 |
+
num_sampling_steps: 60 # range: 1-1000
|
174 |
+
cfg_scale: 4. # range: 1-20
|
175 |
+
solver: "euler" # option: ["euler", "dopri5", "dopri8"]
|
176 |
+
t_shift: 4 # range: 1-20 (int only)
|
177 |
+
ntk_scaling: true # option: true or false
|
178 |
+
proportional_attn: true # option: true or false
|
179 |
+
seed: 0 # rnage: any number
|
180 |
+
```
|
181 |
+
|
182 |
+
- model:
|
183 |
+
- `ckpt`: lumina-next-t2i checkpoint path from [huggingface repo](https://huggingface.co/Alpha-VLLM/Lumina-Next-T2I) containing `consolidated*.pth` and `model_args.pth`.
|
184 |
+
- `ckpt_lm`: LLM checkpoint.
|
185 |
+
- `token`: huggingface access token for accessing gated repo.
|
186 |
+
- transport:
|
187 |
+
- `path_type`: the type of path for transport: 'Linear', 'GVP' (Geodesic Vector Pursuit), or 'VP' (Vector Pursuit).
|
188 |
+
- `prediction`: the prediction model for the transport dynamics.
|
189 |
+
- `loss_weight`: the weighting of different components in the loss function, can be 'velocity' for dynamic modeling, 'likelihood' for statistical consistency, or None for no weighting
|
190 |
+
- `sample_eps`: sampling in the transport model.
|
191 |
+
- `train_eps`: training to stabilize the learning process.
|
192 |
+
- ode:
|
193 |
+
- `atol`: Absolute tolerance for the ODE solver. (options: ["Linear", "GVP", "VP"])
|
194 |
+
- `rtol`: Relative tolerance for the ODE solver. (option: ["velocity", "score", "noise"])
|
195 |
+
- `reverse`: run the ODE solver in reverse. (option: [None, "velocity", "likelihood"])
|
196 |
+
- `likelihood`: Enable calculation of likelihood during the ODE solving process.
|
197 |
+
- infer
|
198 |
+
- `resolution`: generated image resolution.
|
199 |
+
- `num_sampling_steps`: sampling step for generating image.
|
200 |
+
- `cfg_scale`: classifier-free guide scaling factor
|
201 |
+
- `solver`: solver for image generation.
|
202 |
+
- `t_shift`: time shift factor.
|
203 |
+
- `ntk_scaling`: ntk rope scaling factor.
|
204 |
+
- `proportional_attn`: Whether to use proportional attention.
|
205 |
+
- `seed`: random initialization seeds.
|
206 |
+
|
207 |
+
1. Run with CLI
|
208 |
+
|
209 |
+
inference command:
|
210 |
+
```bash
|
211 |
+
lumina_next infer -c <config_path> <caption_here> <output_dir>
|
212 |
+
```
|
213 |
+
|
214 |
+
e.g. Demo command:
|
215 |
+
|
216 |
+
```bash
|
217 |
+
cd lumina_next_t2i
|
218 |
+
lumina_next infer -c "config/infer/settings.yaml" "a snowman of ..." "./outputs"
|
219 |
+
```
|
220 |
+
|
221 |
+
### Web Demo
|
222 |
+
|
223 |
+
To host a local gradio demo for interactive inference, run the following command:
|
224 |
+
|
225 |
+
```bash
|
226 |
+
# `/path/to/ckpt` should be a directory containing `consolidated*.pth` and `model_args.pth`
|
227 |
+
|
228 |
+
# default
|
229 |
+
python -u demo.py --ckpt "/path/to/ckpt"
|
230 |
+
|
231 |
+
# the demo by default uses bf16 precision. to switch to fp32:
|
232 |
+
python -u demo.py --ckpt "/path/to/ckpt" --precision fp32
|
233 |
+
|
234 |
+
# use ema model
|
235 |
+
python -u demo.py --ckpt "/path/to/ckpt" --ema
|
236 |
+
```
|
consolidated.00-of-01.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3028903c4a16927594380420c16bf9414417f623e4f3ecd30d530af25ea21fc6
|
3 |
+
size 6509604840
|
consolidated_ema.00-of-01.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:e5f3a7b0d0d6a12b5051ccb5d319f6954e2fb514fef4e284a4a9d7b350b493af
|
3 |
+
size 6509604840
|
model_args.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:81224af670d1ff56139096c6ac782732a890a25b7e1c61db8940c810fd588110
|
3 |
+
size 1132
|