Text-to-Image
Jonathan-Zhou commited on
Commit
b992d20
1 Parent(s): 7b21717

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +65 -3
README.md CHANGED
@@ -1,3 +1,65 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ ---
4
+ '''python3
5
+ from diffusers import FlowMatchEulerDiscreteScheduler, AutoencoderKL
6
+ from diffusers.models.transformers.transformer_flux import FluxTransformer2DModel
7
+ from diffusers.pipelines.flux.pipeline_flux import FluxPipeline
8
+ from transformers import CLIPTextModel, CLIPTokenizer,T5EncoderModel, T5TokenizerFast
9
+ import torch
10
+ from huggingface_hub import hf_hub_download
11
+ from torchao.quantization.quant_api import (
12
+ quantize_,
13
+ int8_weight_only
14
+ )
15
+ dtype = torch.bfloat16
16
+ flux_repo = "black-forest-labs/FLUX.1-schnell"
17
+ revision = "refs/pr/1"
18
+
19
+ tokenizer = CLIPTokenizer.from_pretrained("openai/clip-vit-large-patch14", torch_dtype=dtype)
20
+ tokenizer_2 = T5TokenizerFast.from_pretrained(flux_repo, subfolder="tokenizer_2", torch_dtype=dtype, revision=revision)
21
+ scheduler = FlowMatchEulerDiscreteScheduler.from_pretrained(flux_repo, subfolder="scheduler", revision=revision)
22
+ transformer = FluxTransformer2DModel.from_pretrained(flux_repo, subfolder="transformer", torch_dtype=dtype, revision=revision)
23
+ lora_file_path = hf_hub_download(repo_id = "Jonathan-Zhou/Flux-GameLabel-Lora", filename = "lora.safetensors")
24
+ text_encoder = CLIPTextModel.from_pretrained("openai/clip-vit-large-patch14", torch_dtype=dtype)
25
+ text_encoder_2 = T5EncoderModel.from_pretrained(flux_repo, subfolder="text_encoder_2", torch_dtype=dtype, revision=revision)
26
+ vae = AutoencoderKL.from_pretrained(flux_repo, subfolder="vae", torch_dtype=dtype, revision=revision)
27
+
28
+
29
+ pipe = FluxPipeline(
30
+ scheduler=scheduler,
31
+ text_encoder=text_encoder,
32
+ tokenizer=tokenizer,
33
+ text_encoder_2=text_encoder_2,
34
+ tokenizer_2=tokenizer_2,
35
+ vae=vae,
36
+ transformer=transformer,
37
+ )
38
+
39
+ # If you want to compare the lora with the bsae model, you can comment out these two lines
40
+ pipe.load_lora_weights(lora_file_path, adapter_name="lora1")
41
+ pipe.fuse_lora()
42
+
43
+ # Quantization needed if run on a GPU with 24 GB VRAM
44
+ quantize_(transformer, int8_weight_only())
45
+ quantize_(text_encoder, int8_weight_only())
46
+ quantize_(text_encoder_2, int8_weight_only())
47
+ quantize_(vae, int8_weight_only())
48
+
49
+
50
+ pipe.to("cuda")
51
+ torch.cuda.empty_cache()
52
+ generator = torch.Generator().manual_seed(12345)
53
+ output = pipe(
54
+ prompt="a man showing off his cool new t shirt at the beach, a shark is jumping out of the water in the background",
55
+ width=1024,
56
+ height=1024,
57
+ num_inference_steps=6,
58
+ num_images_per_prompt = 1,
59
+ generator=generator,
60
+ guidance_scale=3.5,
61
+ )
62
+ image = output.images[0]
63
+ image.show()
64
+
65
+ '''