Upload folder using huggingface_hub
Browse files
README.md
CHANGED
|
@@ -6,24 +6,25 @@ tags:
|
|
| 6 |
- flux
|
| 7 |
- text-to-image
|
| 8 |
- image-generation
|
|
|
|
| 9 |
---
|
| 10 |
|
| 11 |
-
<!-- README Version: v1.
|
| 12 |
|
| 13 |
-
# FLUX.1-dev FP8
|
| 14 |
|
| 15 |
-
|
| 16 |
|
| 17 |
## Model Description
|
| 18 |
|
| 19 |
-
FLUX.1-dev is a
|
| 20 |
|
| 21 |
-
**Key Features
|
| 22 |
-
- **
|
| 23 |
-
- **
|
| 24 |
-
- **
|
| 25 |
-
- **
|
| 26 |
-
- **
|
| 27 |
|
| 28 |
## Repository Contents
|
| 29 |
|
|
@@ -31,294 +32,306 @@ FLUX.1-dev is a state-of-the-art text-to-image diffusion model developed by Blac
|
|
| 31 |
flux-dev-fp8/
|
| 32 |
βββ checkpoints/
|
| 33 |
β βββ flux/
|
| 34 |
-
β βββ flux1-dev-fp8.safetensors
|
| 35 |
βββ diffusion_models/
|
| 36 |
-
β βββ flux1-dev-fp8.safetensors
|
| 37 |
βββ text_encoders/
|
| 38 |
-
β βββ
|
| 39 |
-
β βββ clip-g.safetensors
|
| 40 |
-
β βββ clip-
|
| 41 |
-
β βββ
|
| 42 |
βββ clip/
|
| 43 |
-
β βββ t5xxl-fp8.safetensors
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
| 46 |
```
|
| 47 |
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
## Hardware Requirements
|
| 51 |
|
| 52 |
-
### Minimum Requirements
|
| 53 |
-
- **VRAM**:
|
| 54 |
- **System RAM**: 32GB recommended
|
| 55 |
- **Disk Space**: 50GB free space
|
| 56 |
-
- **
|
| 57 |
|
| 58 |
-
### Recommended Requirements
|
| 59 |
-
- **VRAM**:
|
| 60 |
- **System RAM**: 64GB
|
| 61 |
-
- **
|
|
|
|
| 62 |
|
| 63 |
-
### Performance
|
| 64 |
-
-
|
| 65 |
-
-
|
| 66 |
-
-
|
| 67 |
|
| 68 |
## Usage Examples
|
| 69 |
|
| 70 |
-
###
|
| 71 |
|
| 72 |
```python
|
| 73 |
import torch
|
| 74 |
from diffusers import FluxPipeline
|
| 75 |
|
| 76 |
-
# Load the FP8
|
| 77 |
pipe = FluxPipeline.from_single_file(
|
| 78 |
"E:/huggingface/flux-dev-fp8/checkpoints/flux/flux1-dev-fp8.safetensors",
|
| 79 |
-
torch_dtype=torch.
|
| 80 |
-
use_safetensors=True
|
| 81 |
)
|
| 82 |
|
| 83 |
# Enable memory optimizations
|
| 84 |
pipe.enable_model_cpu_offload()
|
| 85 |
-
pipe.
|
| 86 |
-
|
| 87 |
-
# Generate image
|
| 88 |
-
prompt = "A serene Japanese garden with cherry blossoms, koi pond, and stone lanterns at sunset, photorealistic, highly detailed"
|
| 89 |
|
|
|
|
|
|
|
| 90 |
image = pipe(
|
| 91 |
prompt=prompt,
|
| 92 |
height=1024,
|
| 93 |
width=1024,
|
| 94 |
num_inference_steps=28,
|
| 95 |
-
guidance_scale=
|
| 96 |
).images[0]
|
| 97 |
|
| 98 |
image.save("output.png")
|
| 99 |
```
|
| 100 |
|
| 101 |
-
###
|
| 102 |
|
| 103 |
```python
|
| 104 |
import torch
|
| 105 |
from diffusers import FluxPipeline
|
| 106 |
from transformers import T5EncoderModel, CLIPTextModel
|
| 107 |
|
| 108 |
-
# Load
|
| 109 |
-
|
| 110 |
-
"E:/huggingface/flux-dev-fp8/text_encoders/
|
| 111 |
torch_dtype=torch.float8_e4m3fn
|
| 112 |
)
|
| 113 |
|
| 114 |
-
|
| 115 |
-
"E:/huggingface/flux-dev-fp8/text_encoders/
|
| 116 |
torch_dtype=torch.float16
|
| 117 |
)
|
| 118 |
|
| 119 |
-
# Load diffusion model
|
| 120 |
pipe = FluxPipeline.from_single_file(
|
| 121 |
"E:/huggingface/flux-dev-fp8/diffusion_models/flux1-dev-fp8.safetensors",
|
| 122 |
-
text_encoder=
|
| 123 |
-
text_encoder_2=
|
| 124 |
-
torch_dtype=torch.
|
| 125 |
)
|
|
|
|
|
|
|
| 126 |
```
|
| 127 |
|
| 128 |
-
###
|
| 129 |
|
| 130 |
-
```
|
| 131 |
-
|
| 132 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
|
| 134 |
-
|
| 135 |
-
"E:/huggingface/flux-dev-fp8/checkpoints/flux/flux1-dev-fp8.safetensors",
|
| 136 |
-
torch_dtype=torch.float8_e4m3fn,
|
| 137 |
-
low_cpu_mem_usage=True
|
| 138 |
-
)
|
| 139 |
|
| 140 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
pipe.enable_model_cpu_offload()
|
| 142 |
-
pipe.enable_sequential_cpu_offload()
|
| 143 |
-
pipe.enable_attention_slicing(slice_size=1)
|
| 144 |
-
pipe.enable_vae_tiling()
|
| 145 |
|
| 146 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
image = pipe(
|
| 148 |
-
prompt=
|
| 149 |
-
height=
|
| 150 |
-
width=
|
| 151 |
-
num_inference_steps=
|
| 152 |
-
guidance_scale=
|
|
|
|
| 153 |
).images[0]
|
| 154 |
```
|
| 155 |
|
| 156 |
-
|
|
|
|
|
|
|
|
|
|
| 157 |
|
| 158 |
-
###
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
-
|
| 176 |
-
-
|
| 177 |
-
-
|
| 178 |
-
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
2. **Adjust Generation Parameters**:
|
| 190 |
-
- Reduce `num_inference_steps` (20-28 recommended)
|
| 191 |
-
- Lower resolution (768x768 or 896x896) for faster generation
|
| 192 |
-
- Use guidance_scale 7-9 for balanced quality/performance
|
| 193 |
-
|
| 194 |
-
3. **Hardware Acceleration**:
|
| 195 |
-
- Install xformers for memory-efficient attention: `pip install xformers`
|
| 196 |
-
- Use torch.compile() on PyTorch 2.0+ for ~20% speedup
|
| 197 |
-
- Enable TensorFloat-32 on Ampere+ GPUs: `torch.backends.cuda.matmul.allow_tf32 = True`
|
| 198 |
-
|
| 199 |
-
4. **Batch Processing**:
|
| 200 |
-
- Generate multiple images with batch_size parameter (VRAM permitting)
|
| 201 |
-
- Use lower guidance_scale for batch generation to save memory
|
| 202 |
-
|
| 203 |
-
### Expected Performance
|
| 204 |
-
|
| 205 |
-
| GPU | Resolution | Steps | Time/Image | VRAM Usage |
|
| 206 |
-
|-----|-----------|-------|-----------|-----------|
|
| 207 |
-
| RTX 4090 | 1024x1024 | 28 | ~8-12s | 18GB |
|
| 208 |
-
| RTX 4080 | 1024x1024 | 28 | ~12-16s | 15GB |
|
| 209 |
-
| RTX 3090 | 1024x1024 | 28 | ~15-20s | 20GB |
|
| 210 |
-
| RTX 3090 | 768x768 | 20 | ~8-12s | 14GB |
|
| 211 |
-
|
| 212 |
-
*Times are approximate and depend on prompt complexity and optimizations enabled.*
|
| 213 |
-
|
| 214 |
-
## FP8 Quantization Details
|
| 215 |
-
|
| 216 |
-
### What is FP8?
|
| 217 |
-
FP8 (8-bit floating point) uses the E4M3 format (1 sign bit, 4 exponent bits, 3 mantissa bits) for reduced memory footprint while maintaining model quality. This quantization:
|
| 218 |
-
|
| 219 |
-
- Reduces model size by ~50% vs FP16
|
| 220 |
-
- Maintains >98% of FP16 generation quality
|
| 221 |
-
- Enables deployment on 16-24GB consumer GPUs
|
| 222 |
-
- Accelerates inference on GPUs with FP8 Tensor Cores
|
| 223 |
-
|
| 224 |
-
### Quality Comparison
|
| 225 |
-
- **Visual Quality**: Minimal perceptible difference from FP16
|
| 226 |
-
- **Prompt Adherence**: Equivalent to FP16 in most cases
|
| 227 |
-
- **Edge Cases**: Very complex prompts may show minor differences
|
| 228 |
-
- **Recommended Use**: Production inference, consumer hardware deployment
|
| 229 |
|
| 230 |
## License
|
| 231 |
|
| 232 |
-
|
| 233 |
|
| 234 |
-
|
| 235 |
-
- β
Commercial use permitted
|
| 236 |
-
- β
Modification and distribution allowed
|
| 237 |
-
- β
Private use permitted
|
| 238 |
-
- β οΈ Must include license and copyright notice
|
| 239 |
-
- β οΈ No trademark use without permission
|
| 240 |
|
| 241 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 242 |
|
| 243 |
## Citation
|
| 244 |
|
| 245 |
-
If you use FLUX.1-dev in your research or
|
| 246 |
|
| 247 |
```bibtex
|
| 248 |
-
@misc{
|
| 249 |
-
title={FLUX.1:
|
| 250 |
author={Black Forest Labs},
|
| 251 |
year={2024},
|
| 252 |
-
|
| 253 |
}
|
| 254 |
```
|
| 255 |
|
| 256 |
-
|
| 257 |
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
}
|
| 264 |
-
```
|
| 265 |
-
|
| 266 |
-
## Related Resources
|
| 267 |
-
|
| 268 |
-
### Official Links
|
| 269 |
-
- **FLUX.1 Homepage**: https://blackforestlabs.ai/
|
| 270 |
-
- **Original Model**: https://huggingface.co/black-forest-labs/FLUX.1-dev
|
| 271 |
-
- **Documentation**: https://github.com/black-forest-labs/flux
|
| 272 |
|
| 273 |
-
###
|
| 274 |
-
- **Diffusers
|
| 275 |
-
- **
|
| 276 |
-
- **
|
| 277 |
|
| 278 |
-
### Related Models
|
| 279 |
-
- **FLUX.1-
|
| 280 |
-
- **FLUX
|
|
|
|
| 281 |
|
| 282 |
## Troubleshooting
|
| 283 |
|
| 284 |
### Common Issues
|
| 285 |
|
| 286 |
-
**Out of Memory
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
|
|
|
|
|
|
| 291 |
|
| 292 |
**Slow Generation**:
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
**Quality Issues**:
|
| 299 |
-
- Increase guidance_scale to 8-10 for better prompt adherence
|
| 300 |
-
- Use more inference steps (28-35) for higher quality
|
| 301 |
-
- Ensure proper prompt formatting (detailed descriptions work best)
|
| 302 |
-
- Try different random seeds for variation
|
| 303 |
|
| 304 |
-
**
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
|
|
|
|
|
|
|
|
|
| 309 |
|
| 310 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 311 |
|
| 312 |
-
|
| 313 |
|
| 314 |
-
- **
|
| 315 |
-
- **
|
| 316 |
-
- **Repository Issues**: Verify file integrity and paths
|
| 317 |
|
| 318 |
---
|
| 319 |
|
| 320 |
-
**Model
|
| 321 |
-
**
|
| 322 |
-
**
|
| 323 |
-
**
|
| 324 |
-
**Format**: SafeTensors (.safetensors)
|
|
|
|
| 6 |
- flux
|
| 7 |
- text-to-image
|
| 8 |
- image-generation
|
| 9 |
+
- fp8
|
| 10 |
---
|
| 11 |
|
| 12 |
+
<!-- README Version: v1.5 -->
|
| 13 |
|
| 14 |
+
# FLUX.1-dev FP8 - High-Performance Text-to-Image Model
|
| 15 |
|
| 16 |
+
FLUX.1-dev is a state-of-the-art text-to-image generation model optimized in FP8 precision for maximum performance and reduced VRAM requirements. This repository contains the complete model weights in FP8 format, offering professional-grade image generation with significantly reduced memory footprint compared to FP16 variants.
|
| 17 |
|
| 18 |
## Model Description
|
| 19 |
|
| 20 |
+
FLUX.1-dev is a 12-billion parameter rectified flow transformer model for text-to-image generation. This FP8 quantized version maintains generation quality while reducing VRAM requirements by approximately 50% compared to FP16, making it accessible on consumer-grade GPUs while preserving the model's creative and prompt-following capabilities.
|
| 21 |
|
| 22 |
+
**Key Features:**
|
| 23 |
+
- **Advanced Architecture**: Flow-based diffusion transformer with superior composition and detail
|
| 24 |
+
- **Memory Efficient**: FP8 quantization reduces VRAM requirements from ~72GB to ~24GB
|
| 25 |
+
- **High Fidelity**: Maintains visual quality and prompt adherence despite quantization
|
| 26 |
+
- **Fast Generation**: Optimized inference speed with reduced precision arithmetic
|
| 27 |
+
- **Flexible Text Encoding**: Dual text encoder system (CLIP + T5-XXL) for nuanced understanding
|
| 28 |
|
| 29 |
## Repository Contents
|
| 30 |
|
|
|
|
| 32 |
flux-dev-fp8/
|
| 33 |
βββ checkpoints/
|
| 34 |
β βββ flux/
|
| 35 |
+
β βββ flux1-dev-fp8.safetensors # 17GB - Complete checkpoint
|
| 36 |
βββ diffusion_models/
|
| 37 |
+
β βββ flux1-dev-fp8.safetensors # 12GB - Core diffusion model
|
| 38 |
βββ text_encoders/
|
| 39 |
+
β βββ t5xxl-fp8.safetensors # 4.6GB - T5-XXL text encoder (FP8)
|
| 40 |
+
β βββ clip-g.safetensors # 1.3GB - CLIP-G text encoder
|
| 41 |
+
β βββ clip-vit-large.safetensors # 1.6GB - CLIP ViT-Large
|
| 42 |
+
β βββ clip-l.safetensors # 235MB - CLIP-L encoder
|
| 43 |
βββ clip/
|
| 44 |
+
β βββ t5xxl-fp8.safetensors # 4.6GB - T5 encoder (alternate path)
|
| 45 |
+
βββ clip_vision/
|
| 46 |
+
β βββ clip-vision-h.safetensors # 1.2GB - CLIP vision model
|
| 47 |
+
βββ README.md
|
| 48 |
+
|
| 49 |
+
Total Size: ~46GB
|
| 50 |
```
|
| 51 |
|
| 52 |
+
### File Descriptions
|
| 53 |
+
|
| 54 |
+
- **Complete Checkpoint** (`checkpoints/flux/`): Full model with all components for direct loading
|
| 55 |
+
- **Diffusion Model** (`diffusion_models/`): Core image generation transformer
|
| 56 |
+
- **Text Encoders** (`text_encoders/`): Dual encoding system for text understanding
|
| 57 |
+
- **T5-XXL-FP8**: Large language model for semantic understanding (FP8 quantized)
|
| 58 |
+
- **CLIP Encoders**: Visual-language alignment models for prompt conditioning
|
| 59 |
+
- **CLIP Vision**: Vision encoder for image-to-image and conditioning tasks
|
| 60 |
|
| 61 |
## Hardware Requirements
|
| 62 |
|
| 63 |
+
### Minimum Requirements (Text-to-Image Generation)
|
| 64 |
+
- **VRAM**: 24GB (RTX 3090/4090, A5000, A6000)
|
| 65 |
- **System RAM**: 32GB recommended
|
| 66 |
- **Disk Space**: 50GB free space
|
| 67 |
+
- **CUDA**: 11.8+ or 12.x with PyTorch 2.0+
|
| 68 |
|
| 69 |
+
### Recommended Requirements (Optimal Performance)
|
| 70 |
+
- **VRAM**: 32GB+ (RTX 4090, A6000, A40, A100)
|
| 71 |
- **System RAM**: 64GB
|
| 72 |
+
- **Disk Space**: 100GB (for model cache and outputs)
|
| 73 |
+
- **Storage**: NVMe SSD for faster loading
|
| 74 |
|
| 75 |
+
### Performance Expectations
|
| 76 |
+
- **512Γ512**: ~2-3 seconds per image (4090, 28 steps)
|
| 77 |
+
- **1024Γ1024**: ~6-8 seconds per image (4090, 28 steps)
|
| 78 |
+
- **2048Γ2048**: ~20-30 seconds per image (4090, 28 steps)
|
| 79 |
|
| 80 |
## Usage Examples
|
| 81 |
|
| 82 |
+
### Using with Diffusers Library
|
| 83 |
|
| 84 |
```python
|
| 85 |
import torch
|
| 86 |
from diffusers import FluxPipeline
|
| 87 |
|
| 88 |
+
# Load the FP8 model (adjust paths to your local installation)
|
| 89 |
pipe = FluxPipeline.from_single_file(
|
| 90 |
"E:/huggingface/flux-dev-fp8/checkpoints/flux/flux1-dev-fp8.safetensors",
|
| 91 |
+
torch_dtype=torch.float16 # Use FP16 for computation
|
|
|
|
| 92 |
)
|
| 93 |
|
| 94 |
# Enable memory optimizations
|
| 95 |
pipe.enable_model_cpu_offload()
|
| 96 |
+
pipe.enable_vae_slicing()
|
|
|
|
|
|
|
|
|
|
| 97 |
|
| 98 |
+
# Generate an image
|
| 99 |
+
prompt = "A serene mountain landscape at sunset, photorealistic, 8k quality"
|
| 100 |
image = pipe(
|
| 101 |
prompt=prompt,
|
| 102 |
height=1024,
|
| 103 |
width=1024,
|
| 104 |
num_inference_steps=28,
|
| 105 |
+
guidance_scale=3.5
|
| 106 |
).images[0]
|
| 107 |
|
| 108 |
image.save("output.png")
|
| 109 |
```
|
| 110 |
|
| 111 |
+
### Advanced Usage with Component Loading
|
| 112 |
|
| 113 |
```python
|
| 114 |
import torch
|
| 115 |
from diffusers import FluxPipeline
|
| 116 |
from transformers import T5EncoderModel, CLIPTextModel
|
| 117 |
|
| 118 |
+
# Load components separately for fine-grained control
|
| 119 |
+
text_encoder = T5EncoderModel.from_single_file(
|
| 120 |
+
"E:/huggingface/flux-dev-fp8/text_encoders/t5xxl-fp8.safetensors",
|
| 121 |
torch_dtype=torch.float8_e4m3fn
|
| 122 |
)
|
| 123 |
|
| 124 |
+
text_encoder_2 = CLIPTextModel.from_single_file(
|
| 125 |
+
"E:/huggingface/flux-dev-fp8/text_encoders/clip-g.safetensors",
|
| 126 |
torch_dtype=torch.float16
|
| 127 |
)
|
| 128 |
|
| 129 |
+
# Load the main diffusion model
|
| 130 |
pipe = FluxPipeline.from_single_file(
|
| 131 |
"E:/huggingface/flux-dev-fp8/diffusion_models/flux1-dev-fp8.safetensors",
|
| 132 |
+
text_encoder=text_encoder,
|
| 133 |
+
text_encoder_2=text_encoder_2,
|
| 134 |
+
torch_dtype=torch.float16
|
| 135 |
)
|
| 136 |
+
|
| 137 |
+
pipe.to("cuda")
|
| 138 |
```
|
| 139 |
|
| 140 |
+
### ComfyUI Integration
|
| 141 |
|
| 142 |
+
```
|
| 143 |
+
# Add model paths in ComfyUI:
|
| 144 |
+
# Settings > System Paths > Checkpoints:
|
| 145 |
+
# E:\huggingface\flux-dev-fp8\checkpoints\flux
|
| 146 |
+
#
|
| 147 |
+
# Settings > System Paths > CLIP:
|
| 148 |
+
# E:\huggingface\flux-dev-fp8\text_encoders
|
| 149 |
+
#
|
| 150 |
+
# Load workflow:
|
| 151 |
+
# - Add "Load Checkpoint" node
|
| 152 |
+
# - Select: flux1-dev-fp8.safetensors
|
| 153 |
+
# - Connect to KSampler with recommended settings:
|
| 154 |
+
# - Steps: 20-28
|
| 155 |
+
# - CFG: 3.5
|
| 156 |
+
# - Sampler: euler
|
| 157 |
+
# - Scheduler: simple
|
| 158 |
+
```
|
| 159 |
|
| 160 |
+
## Model Specifications
|
|
|
|
|
|
|
|
|
|
|
|
|
| 161 |
|
| 162 |
+
### Architecture
|
| 163 |
+
- **Model Type**: Rectified Flow Transformer (Diffusion Model)
|
| 164 |
+
- **Parameters**: 12 billion
|
| 165 |
+
- **Base Resolution**: 1024Γ1024 (trained), flexible generation
|
| 166 |
+
- **Precision**: FP8 (Float8 E4M3) quantized from FP16
|
| 167 |
+
- **Format**: SafeTensors (secure, efficient)
|
| 168 |
+
|
| 169 |
+
### Text Encoding System
|
| 170 |
+
- **Primary Encoder**: T5-XXL (FP8, 4.6GB) - Semantic understanding
|
| 171 |
+
- **Secondary Encoders**: CLIP-G, CLIP-L, CLIP-ViT - Visual-language alignment
|
| 172 |
+
- **Max Token Length**: 512 tokens (T5-XXL)
|
| 173 |
+
|
| 174 |
+
### Supported Tasks
|
| 175 |
+
- Text-to-image generation
|
| 176 |
+
- High-resolution synthesis (up to 2048Γ2048+)
|
| 177 |
+
- Complex prompt understanding and composition
|
| 178 |
+
- Style transfer and artistic control
|
| 179 |
+
- Photorealistic and artistic generation
|
| 180 |
+
|
| 181 |
+
## Performance Tips and Optimization
|
| 182 |
+
|
| 183 |
+
### Memory Optimization Strategies
|
| 184 |
+
|
| 185 |
+
```python
|
| 186 |
+
# 1. Enable CPU offloading (reduces VRAM to ~16GB)
|
| 187 |
pipe.enable_model_cpu_offload()
|
|
|
|
|
|
|
|
|
|
| 188 |
|
| 189 |
+
# 2. Enable VAE slicing (for high resolutions)
|
| 190 |
+
pipe.enable_vae_slicing()
|
| 191 |
+
pipe.enable_vae_tiling() # For resolutions > 2048px
|
| 192 |
+
|
| 193 |
+
# 3. Use attention slicing (reduces memory further)
|
| 194 |
+
pipe.enable_attention_slicing(slice_size="auto")
|
| 195 |
+
|
| 196 |
+
# 4. Use torch.compile for speed (PyTorch 2.0+)
|
| 197 |
+
pipe.unet = torch.compile(pipe.unet, mode="reduce-overhead", fullgraph=True)
|
| 198 |
+
```
|
| 199 |
+
|
| 200 |
+
### Quality Optimization
|
| 201 |
+
|
| 202 |
+
```python
|
| 203 |
+
# Recommended generation parameters
|
| 204 |
image = pipe(
|
| 205 |
+
prompt=your_prompt,
|
| 206 |
+
height=1024,
|
| 207 |
+
width=1024,
|
| 208 |
+
num_inference_steps=28, # 20-28 recommended for quality
|
| 209 |
+
guidance_scale=3.5, # 3.0-4.0 optimal range for FLUX
|
| 210 |
+
generator=torch.manual_seed(42) # For reproducibility
|
| 211 |
).images[0]
|
| 212 |
```
|
| 213 |
|
| 214 |
+
### Speed vs Quality Trade-offs
|
| 215 |
+
- **Fast**: 20 steps, guidance 3.0 (~4s for 1024px on 4090)
|
| 216 |
+
- **Balanced**: 28 steps, guidance 3.5 (~6s for 1024px on 4090)
|
| 217 |
+
- **Quality**: 40 steps, guidance 4.0 (~9s for 1024px on 4090)
|
| 218 |
|
| 219 |
+
### Batch Generation
|
| 220 |
+
|
| 221 |
+
```python
|
| 222 |
+
# Generate multiple images efficiently
|
| 223 |
+
prompts = ["prompt 1", "prompt 2", "prompt 3"]
|
| 224 |
+
images = pipe(
|
| 225 |
+
prompt=prompts,
|
| 226 |
+
height=1024,
|
| 227 |
+
width=1024,
|
| 228 |
+
num_inference_steps=28,
|
| 229 |
+
guidance_scale=3.5
|
| 230 |
+
).images # Returns list of images
|
| 231 |
+
```
|
| 232 |
+
|
| 233 |
+
## Quantization Details
|
| 234 |
+
|
| 235 |
+
This FP8 version uses Float8 E4M3 quantization:
|
| 236 |
+
- **Precision**: 8-bit floating point (1 sign, 4 exponent, 3 mantissa bits)
|
| 237 |
+
- **Range**: ~Β±448 with reduced precision
|
| 238 |
+
- **Memory Savings**: ~50% reduction vs FP16
|
| 239 |
+
- **Quality**: Minimal perceptual loss in most generation scenarios
|
| 240 |
+
- **Speed**: Potential 1.5-2x inference speedup on supported hardware (H100, Ada Lovelace)
|
| 241 |
+
|
| 242 |
+
### FP8 vs FP16 Comparison
|
| 243 |
+
| Metric | FP16 | FP8 (This Model) |
|
| 244 |
+
|--------|------|------------------|
|
| 245 |
+
| VRAM | ~72GB | ~24GB (active), ~16GB (offloaded) |
|
| 246 |
+
| Speed | Baseline | 1.5-2x faster (on supported GPUs) |
|
| 247 |
+
| Quality | Reference | 95-98% equivalent |
|
| 248 |
+
| Generation | Professional | Professional |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 249 |
|
| 250 |
## License
|
| 251 |
|
| 252 |
+
**Apache License 2.0**
|
| 253 |
|
| 254 |
+
This model is released under the Apache 2.0 license, allowing commercial and non-commercial use with attribution. See the [LICENSE](LICENSE) file for full terms.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 255 |
|
| 256 |
+
### Usage Guidelines
|
| 257 |
+
- β
Commercial use permitted
|
| 258 |
+
- β
Modification and derivative works allowed
|
| 259 |
+
- β
Distribution permitted (with license and attribution)
|
| 260 |
+
- β οΈ Must include copyright notice and license text
|
| 261 |
+
- β οΈ Changes must be documented
|
| 262 |
|
| 263 |
## Citation
|
| 264 |
|
| 265 |
+
If you use FLUX.1-dev in your research or projects, please cite:
|
| 266 |
|
| 267 |
```bibtex
|
| 268 |
+
@misc{flux1dev2024,
|
| 269 |
+
title={FLUX.1: State-of-the-Art Image Generation},
|
| 270 |
author={Black Forest Labs},
|
| 271 |
year={2024},
|
| 272 |
+
url={https://blackforestlabs.ai/flux-1-dev/}
|
| 273 |
}
|
| 274 |
```
|
| 275 |
|
| 276 |
+
## Resources and Links
|
| 277 |
|
| 278 |
+
### Official Resources
|
| 279 |
+
- **Official Website**: [Black Forest Labs](https://blackforestlabs.ai/)
|
| 280 |
+
- **Model Card**: [Hugging Face - FLUX.1-dev](https://huggingface.co/black-forest-labs/FLUX.1-dev)
|
| 281 |
+
- **Documentation**: [FLUX Documentation](https://github.com/black-forest-labs/flux)
|
| 282 |
+
- **Community**: [Hugging Face Discussions](https://huggingface.co/black-forest-labs/FLUX.1-dev/discussions)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 283 |
|
| 284 |
+
### Integration Libraries
|
| 285 |
+
- **Diffusers**: [Hugging Face Diffusers](https://github.com/huggingface/diffusers)
|
| 286 |
+
- **ComfyUI**: [ComfyUI GitHub](https://github.com/comfyanonymous/ComfyUI)
|
| 287 |
+
- **Stability AI SDK**: [Stability SDK](https://github.com/Stability-AI/stability-sdk)
|
| 288 |
|
| 289 |
+
### Related Models
|
| 290 |
+
- **FLUX.1-schnell**: Faster variant optimized for speed
|
| 291 |
+
- **FLUX.1-pro**: Professional variant with enhanced capabilities
|
| 292 |
+
- **FLUX.1-dev-FP16**: Full precision version (72GB)
|
| 293 |
|
| 294 |
## Troubleshooting
|
| 295 |
|
| 296 |
### Common Issues
|
| 297 |
|
| 298 |
+
**Out of Memory Errors**:
|
| 299 |
+
```python
|
| 300 |
+
# Solution: Enable all memory optimizations
|
| 301 |
+
pipe.enable_model_cpu_offload()
|
| 302 |
+
pipe.enable_vae_slicing()
|
| 303 |
+
pipe.enable_attention_slicing(slice_size="auto")
|
| 304 |
+
```
|
| 305 |
|
| 306 |
**Slow Generation**:
|
| 307 |
+
```python
|
| 308 |
+
# Solution: Use torch.compile (requires PyTorch 2.0+)
|
| 309 |
+
pipe.unet = torch.compile(pipe.unet, mode="reduce-overhead")
|
| 310 |
+
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 311 |
|
| 312 |
+
**Quality Issues with FP8**:
|
| 313 |
+
```python
|
| 314 |
+
# Solution: Use FP16 computation with FP8 weights
|
| 315 |
+
pipe = FluxPipeline.from_single_file(
|
| 316 |
+
model_path,
|
| 317 |
+
torch_dtype=torch.float16 # Compute in FP16, weights stay FP8
|
| 318 |
+
)
|
| 319 |
+
```
|
| 320 |
|
| 321 |
+
### System Compatibility
|
| 322 |
+
- **CUDA 11.8+** required for FP8 support
|
| 323 |
+
- **PyTorch 2.1+** recommended for best performance
|
| 324 |
+
- **transformers 4.36+** for T5-XXL FP8 support
|
| 325 |
+
- **diffusers 0.26+** for FLUX pipeline support
|
| 326 |
|
| 327 |
+
## Version History
|
| 328 |
|
| 329 |
+
- **v1.5** (2025-01): Updated documentation with performance benchmarks
|
| 330 |
+
- **v1.0** (2024-08): Initial FP8 quantized release
|
|
|
|
| 331 |
|
| 332 |
---
|
| 333 |
|
| 334 |
+
**Model developed by**: Black Forest Labs
|
| 335 |
+
**Quantization**: Community contribution
|
| 336 |
+
**Repository maintained by**: Local model collection
|
| 337 |
+
**Last updated**: 2025-01-28
|
|
|