alfredplpl commited on
Commit
f59fd54
·
verified ·
1 Parent(s): 669af72

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +50 -0
README.md CHANGED
@@ -5,6 +5,56 @@ license_name: flux-1-dev-non-commercial-license
5
  license_link: https://huggingface.co/black-forest-labs/FLUX.1-dev/blob/main/LICENSE.md
6
  ---
7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  # How to cast fp8
9
  1. Install quanto-optinum.
10
  ```bash
 
5
  license_link: https://huggingface.co/black-forest-labs/FLUX.1-dev/blob/main/LICENSE.md
6
  ---
7
 
8
+ # FLUX.1 [dev] Modern Anime FP8 With Quanto (WIP)
9
+
10
+ ![eyecatch](eyecatch.jpg)
11
+
12
+ # Usage
13
+ - diffusers
14
+ ```python
15
+ # Reference 1: https://gist.github.com/AmericanPresidentJimmyCarter/873985638e1f3541ba8b00137e7dacd9
16
+ # Reference 2: https://huggingface.co/twodgirl/Flux-dev-optimum-quant-qfloat8
17
+ # Reference 2 by https://huggingface.co/twodgirl
18
+ # Reference 3: https://huggingface.co/p1atdev/FLUX.1-schnell-t5-xxl-quanto
19
+
20
+ import torch
21
+ from diffusers import FluxPipeline, FluxTransformer2DModel
22
+ from optimum.quanto import QuantizedDiffusersModel, QuantizedTransformersModel
23
+ from transformers import T5EncoderModel
24
+ from huggingface_hub import snapshot_download
25
+
26
+ snapshot_download(repo_id="alfredplpl/flux.1-dev-modern-anime-fp8",local_dir="./anime_fp8")
27
+
28
+ class QuantizedT5EncoderModel(QuantizedTransformersModel):
29
+ auto_class = T5EncoderModel
30
+ T5EncoderModel.from_config = lambda c: T5EncoderModel(c).to(dtype=torch.float16) # lol
31
+
32
+ class QuantizedFlux2DModel(QuantizedDiffusersModel):
33
+ base_class = FluxTransformer2DModel
34
+
35
+ pipe = FluxPipeline.from_pretrained("black-forest-labs/FLUX.1-dev",
36
+ transformer=None,
37
+ text_encoder_2=None,
38
+ torch_dtype=torch.bfloat16)
39
+
40
+ pipe.transformer=QuantizedFlux2DModel.from_pretrained("./anime_fp8/transformer")
41
+ pipe.text_encoder_2=QuantizedT5EncoderModel.from_pretrained("./anime_fp8/transformer")
42
+ pipe.vae=pipe.vae.to(torch.float32)
43
+ pipe.enable_model_cpu_offload()
44
+
45
+ prompt = "modern anime style, A close-up portrait of a young girl with green hair. Her hair is vibrant and shoulder-length, framing her face softly. She has large, expressive eyes that are slightly tilted upward, with a gentle and calm expression. Her facial features are delicate, with a small nose and soft lips. The background is simple, focusing attention on her face, with soft lighting that highlights her features. The overall style of the illustration is warm and inviting, with a soft color palette and a slightly dreamy atmosphere."
46
+ image = pipe(
47
+ prompt,
48
+ height=1024,
49
+ width=1024,
50
+ guidance_scale=3.5,
51
+ num_inference_steps=50,
52
+ max_sequence_length=512,
53
+ generator=torch.Generator(device="cuda").manual_seed(0)
54
+ ).images[0]
55
+ image.save("modern-anime-fp8.png")
56
+ ```
57
+
58
  # How to cast fp8
59
  1. Install quanto-optinum.
60
  ```bash