aredden commited on
Commit
340f0a0
·
1 Parent(s): 1626546

Add fields to configs, fix issue with offload from bnb, remove extra random text code

Browse files
configs/config-dev-cuda0.json CHANGED
@@ -47,5 +47,10 @@
47
  "flow_dtype": "float16",
48
  "ae_dtype": "bfloat16",
49
  "text_enc_dtype": "bfloat16",
50
- "num_to_quant": 20
 
 
 
 
 
51
  }
 
47
  "flow_dtype": "float16",
48
  "ae_dtype": "bfloat16",
49
  "text_enc_dtype": "bfloat16",
50
+ "text_enc_quantization_dtype": "qfloat8",
51
+ "compile_extras": false,
52
+ "compile_blocks": false,
53
+ "offload_ae": false,
54
+ "offload_text_enc": false,
55
+ "offload_flow": false
56
  }
configs/config-dev-eval.json CHANGED
@@ -49,7 +49,9 @@
49
  "text_enc_dtype": "bfloat16",
50
  "flow_quantization_dtype": "qfloat8",
51
  "text_enc_quantization_dtype": "qfloat8",
52
- "num_to_quant": 22,
53
  "compile_extras": false,
54
- "compile_blocks": false
 
 
 
55
  }
 
49
  "text_enc_dtype": "bfloat16",
50
  "flow_quantization_dtype": "qfloat8",
51
  "text_enc_quantization_dtype": "qfloat8",
 
52
  "compile_extras": false,
53
+ "compile_blocks": false,
54
+ "offload_ae": false,
55
+ "offload_text_enc": false,
56
+ "offload_flow": false
57
  }
configs/config-dev-offload.json CHANGED
@@ -49,7 +49,7 @@
49
  "text_enc_dtype": "bfloat16",
50
  "flow_quantization_dtype": "qfloat8",
51
  "text_enc_quantization_dtype": "qint4",
52
- "num_to_quant": 22,
53
  "compile_extras": false,
54
  "compile_blocks": false,
55
  "offload_text_encoder": true,
 
49
  "text_enc_dtype": "bfloat16",
50
  "flow_quantization_dtype": "qfloat8",
51
  "text_enc_quantization_dtype": "qint4",
52
+ "ae_quantization_dtype": "qfloat8",
53
  "compile_extras": false,
54
  "compile_blocks": false,
55
  "offload_text_encoder": true,
configs/config-dev-prequant.json CHANGED
@@ -47,10 +47,11 @@
47
  "flow_dtype": "float16",
48
  "ae_dtype": "bfloat16",
49
  "text_enc_dtype": "bfloat16",
50
- "flow_quantization_dtype": "qfloat8",
51
  "text_enc_quantization_dtype": "qfloat8",
52
- "num_to_quant": 22,
53
- "compile_extras": true,
54
- "compile_blocks": true,
55
- "prequantized_flow": true
 
 
56
  }
 
47
  "flow_dtype": "float16",
48
  "ae_dtype": "bfloat16",
49
  "text_enc_dtype": "bfloat16",
 
50
  "text_enc_quantization_dtype": "qfloat8",
51
+ "compile_extras": false,
52
+ "compile_blocks": false,
53
+ "prequantized_flow": true,
54
+ "offload_ae": false,
55
+ "offload_text_enc": false,
56
+ "offload_flow": false
57
  }
configs/config-dev.json CHANGED
@@ -47,9 +47,11 @@
47
  "flow_dtype": "float16",
48
  "ae_dtype": "bfloat16",
49
  "text_enc_dtype": "bfloat16",
50
- "flow_quantization_dtype": "qfloat8",
51
  "text_enc_quantization_dtype": "qfloat8",
52
- "num_to_quant": 22,
53
  "compile_extras": true,
54
- "compile_blocks": true
 
 
 
55
  }
 
47
  "flow_dtype": "float16",
48
  "ae_dtype": "bfloat16",
49
  "text_enc_dtype": "bfloat16",
 
50
  "text_enc_quantization_dtype": "qfloat8",
51
+ "ae_quantization_dtype": "qfloat8",
52
  "compile_extras": true,
53
+ "compile_blocks": true,
54
+ "offload_ae": false,
55
+ "offload_text_enc": false,
56
+ "offload_flow": false
57
  }
configs/config-schnell-cuda0.json CHANGED
@@ -16,7 +16,7 @@
16
  ],
17
  "theta": 10000,
18
  "qkv_bias": true,
19
- "guidance_embed": true
20
  },
21
  "ae_params": {
22
  "resolution": 256,
@@ -47,5 +47,11 @@
47
  "flow_dtype": "float16",
48
  "ae_dtype": "bfloat16",
49
  "text_enc_dtype": "bfloat16",
50
- "num_to_quant": 20
 
 
 
 
 
 
51
  }
 
16
  ],
17
  "theta": 10000,
18
  "qkv_bias": true,
19
+ "guidance_embed": false
20
  },
21
  "ae_params": {
22
  "resolution": 256,
 
47
  "flow_dtype": "float16",
48
  "ae_dtype": "bfloat16",
49
  "text_enc_dtype": "bfloat16",
50
+ "text_enc_quantization_dtype": "qfloat8",
51
+ "ae_quantization_dtype": "qfloat8",
52
+ "compile_extras": false,
53
+ "compile_blocks": false,
54
+ "offload_ae": false,
55
+ "offload_text_enc": false,
56
+ "offload_flow": false
57
  }
configs/config-schnell.json CHANGED
@@ -16,7 +16,7 @@
16
  ],
17
  "theta": 10000,
18
  "qkv_bias": true,
19
- "guidance_embed": true
20
  },
21
  "ae_params": {
22
  "resolution": 256,
@@ -47,5 +47,11 @@
47
  "flow_dtype": "float16",
48
  "ae_dtype": "bfloat16",
49
  "text_enc_dtype": "bfloat16",
50
- "num_to_quant": 20
 
 
 
 
 
 
51
  }
 
16
  ],
17
  "theta": 10000,
18
  "qkv_bias": true,
19
+ "guidance_embed": false
20
  },
21
  "ae_params": {
22
  "resolution": 256,
 
47
  "flow_dtype": "float16",
48
  "ae_dtype": "bfloat16",
49
  "text_enc_dtype": "bfloat16",
50
+ "text_enc_quantization_dtype": "qfloat8",
51
+ "ae_quantization_dtype": "qfloat8",
52
+ "compile_extras": true,
53
+ "compile_blocks": true,
54
+ "offload_ae": false,
55
+ "offload_text_enc": false,
56
+ "offload_flow": false
57
  }
float8_quantize.py CHANGED
@@ -12,7 +12,7 @@ from torch.compiler import is_compiling
12
  from torch import __version__
13
  from torch.version import cuda
14
 
15
- IS_TORCH_2_4 = __version__ >= (2, 4) and __version__ < (2, 4, 9)
16
  LT_TORCH_2_4 = __version__ < (2, 4)
17
  if LT_TORCH_2_4:
18
  if not hasattr(torch, "_scaled_mm"):
 
12
  from torch import __version__
13
  from torch.version import cuda
14
 
15
+ IS_TORCH_2_4 = __version__ < (2, 4, 9)
16
  LT_TORCH_2_4 = __version__ < (2, 4)
17
  if LT_TORCH_2_4:
18
  if not hasattr(torch, "_scaled_mm"):
flux_pipeline.py CHANGED
@@ -165,8 +165,8 @@ class FluxPipeline:
165
 
166
  img_ids = img_ids[None].repeat(bs, 1, 1, 1).flatten(1, 2)
167
  if self.offload_text_encoder:
168
- self.clip.to(self.device_clip)
169
- self.t5.to(self.device_t5)
170
  vec, txt, txt_ids = get_weighted_text_embeddings_flux(
171
  self,
172
  prompt,
@@ -498,28 +498,3 @@ class FluxPipeline:
498
  t5_device=t5_device,
499
  config=config,
500
  )
501
-
502
-
503
- if __name__ == "__main__":
504
- pipe = FluxPipeline.load_pipeline_from_config_path(
505
- "configs/config-dev-prequant.json",
506
- )
507
- o = pipe.generate(
508
- prompt="Street photography portrait of a beautiful asian woman in traditional clothing with golden hairpin and blue eyes, wearing a red kimono with dragon patterns",
509
- height=1024,
510
- width=576,
511
- num_steps=24,
512
- guidance=3.5,
513
- seed=10,
514
- )
515
- open("out.jpg", "wb").write(o.read())
516
- for x in range(2):
517
-
518
- o = pipe.generate(
519
- prompt="Street photography portrait of a beautiful asian woman in traditional clothing with golden hairpin and blue eyes, wearing a red kimono with dragon patterns",
520
- height=1024,
521
- width=576,
522
- num_steps=24,
523
- guidance=3.5,
524
- )
525
- open(f"out{x}.jpg", "wb").write(o.read())
 
165
 
166
  img_ids = img_ids[None].repeat(bs, 1, 1, 1).flatten(1, 2)
167
  if self.offload_text_encoder:
168
+ self.clip.cuda(self.device_clip)
169
+ self.t5.cuda(self.device_t5)
170
  vec, txt, txt_ids = get_weighted_text_embeddings_flux(
171
  self,
172
  prompt,
 
498
  t5_device=t5_device,
499
  config=config,
500
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
image_encoder.py CHANGED
@@ -42,29 +42,3 @@ class ImageEncoder:
42
  im.save(iob, format="JPEG", quality=95)
43
  iob.seek(0)
44
  return iob.getvalue()
45
-
46
-
47
- def test_real_img():
48
- from PIL import Image
49
- import numpy as np
50
-
51
- im = "out.jpg"
52
- im = Image.open(im)
53
- im = np.array(im)
54
- img_hwc = torch.from_numpy(im).cuda().type(torch.float32)
55
- img_chw = img_hwc.permute(2, 0, 1).contiguous()
56
- img_gray = img_hwc.mean(dim=2, keepdim=False).contiguous().clamp(0, 255)
57
- tj = ImageEncoder()
58
- o = tj.encode_torch(img_chw)
59
- o2 = tj.encode_torch(img_hwc)
60
- o3 = tj.encode_torch(img_gray)
61
- with open("out_chw.jpg", "wb") as f:
62
- f.write(o2)
63
- with open("out_hwc.jpg", "wb") as f:
64
- f.write(o)
65
- with open("out_gray.jpg", "wb") as f:
66
- f.write(o3)
67
-
68
-
69
- if __name__ == "__main__":
70
- test_real_img()
 
42
  im.save(iob, format="JPEG", quality=95)
43
  iob.seek(0)
44
  return iob.getvalue()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
util.py CHANGED
@@ -290,25 +290,3 @@ def load_models_from_config(config: ModelSpec) -> LoadedModels:
290
  t5=t5,
291
  config=config,
292
  )
293
-
294
-
295
- if __name__ == "__main__":
296
- p = "/big/generator-ui/flux-testing/flux/model-dir/flux1-dev.sft"
297
- ae_p = "/big/generator-ui/flux-testing/flux/model-dir/ae.sft"
298
-
299
- config = load_config(
300
- ModelVersion.flux_dev,
301
- flux_path=p,
302
- ae_path=ae_p,
303
- text_enc_path="city96/t5-v1_1-xxl-encoder-bf16",
304
- text_enc_device="cuda:0",
305
- ae_device="cuda:0",
306
- flux_device="cuda:0",
307
- flow_dtype="float16",
308
- ae_dtype="bfloat16",
309
- text_enc_dtype="bfloat16",
310
- num_to_quant=20,
311
- )
312
- with open("configs/config-dev-cuda0.json", "w") as f:
313
- json.dump(config.model_dump(), f, indent=2)
314
- print(config)
 
290
  t5=t5,
291
  config=config,
292
  )