rippertnt commited on
Commit
58c2804
·
verified ·
1 Parent(s): 2287959

Upload 5 files

Browse files
Files changed (6) hide show
  1. .gitattributes +1 -0
  2. klein.py +8 -22
  3. klein2.py +62 -0
  4. klein3.py +35 -0
  5. ltx.py +91 -0
  6. suji.jpg +3 -0
.gitattributes CHANGED
@@ -34,3 +34,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
  tokenizer/tokenizer.json filter=lfs diff=lfs merge=lfs -text
 
 
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
  tokenizer/tokenizer.json filter=lfs diff=lfs merge=lfs -text
37
+ suji.jpg filter=lfs diff=lfs merge=lfs -text
klein.py CHANGED
@@ -1,36 +1,22 @@
1
  import torch
2
  from diffusers import Flux2KleinPipeline
3
- from transformers import BitsAndBytesConfig
4
 
5
- bnb_config = BitsAndBytesConfig(
6
- load_in_4bit=True,
7
- bnb_4bit_quant_type="nf4", # BEST quality/speed
8
- bnb_4bit_compute_dtype=torch.bfloat16, # fast on Ampere+
9
- bnb_4bit_use_double_quant=True, # lower VRAM
10
- )
11
-
12
- device = "cuda"
13
- dtype = torch.bfloat16
14
-
15
- pipe = Flux2KleinPipeline.from_pretrained("./FLUX.2-9B-bnb-4bit", torch_dtype=dtype)
16
-
17
- """
18
  pipe = Flux2KleinPipeline.from_pretrained(
19
- "black-forest-labs/FLUX.2-klein-4B",
20
  torch_dtype=torch.bfloat16,
21
- device_map="auto", # REQUIRED
22
- quantization_config=bnb_config, # APPLY 4-bit
23
  )
24
- """
25
- pipe.to("cuda")
26
  #pipe.enable_model_cpu_offload() # save some VRAM by offloading the model to CPU
27
 
28
  from PIL import Image
29
 
30
  init_image = Image.open("suji.jpg").convert("RGB")
 
31
  #prompt = "an very beautiful sexy korean kpop young woman with white bikini is smiling on the waikiki beach. hiqh quality realistic photo."# pixar 3d style"
32
  #prompt = "beautiful woman in the beach holding plate with Circulus "
33
- prompt = "A beautiful korean kpop young woman with white red sexy dress"
34
  image = pipe(
35
  prompt=prompt,
36
  image=init_image,
@@ -38,6 +24,6 @@ image = pipe(
38
  width=1024,
39
  guidance_scale=1.0,
40
  num_inference_steps=4,
41
- generator=torch.Generator(device=device).manual_seed(0)
42
  ).images[0]
43
- image.save("./output/flux_suji6.png")
 
1
  import torch
2
  from diffusers import Flux2KleinPipeline
 
3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  pipe = Flux2KleinPipeline.from_pretrained(
5
+ "./FLUX.2-9B-bnb-4bit",
6
  torch_dtype=torch.bfloat16,
7
+ device_map="cuda", # REQUIRED
 
8
  )
9
+
10
+ #pipe.to("cuda")
11
  #pipe.enable_model_cpu_offload() # save some VRAM by offloading the model to CPU
12
 
13
  from PIL import Image
14
 
15
  init_image = Image.open("suji.jpg").convert("RGB")
16
+
17
  #prompt = "an very beautiful sexy korean kpop young woman with white bikini is smiling on the waikiki beach. hiqh quality realistic photo."# pixar 3d style"
18
  #prompt = "beautiful woman in the beach holding plate with Circulus "
19
+ prompt = "피부가 드러나는 흰색 드레스를 입었다." #하얀색의 섹시한 드레스를 입은 아름다운 한국 여성"
20
  image = pipe(
21
  prompt=prompt,
22
  image=init_image,
 
24
  width=1024,
25
  guidance_scale=1.0,
26
  num_inference_steps=4,
27
+ generator=torch.Generator(device="cuda").manual_seed(0)
28
  ).images[0]
29
+ image.save("./output/flux_suji10.png")
klein2.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import torch
3
+ from diffusers import Flux2KleinPipeline, Flux2Transformer2DModel
4
+ from transformers import Qwen3ForCausalLM, BitsAndBytesConfig, AutoTokenizer
5
+ import math
6
+
7
+ torch.backends.cuda.matmul.allow_tf32 = True
8
+ torch.backends.cudnn.allow_tf32 = True
9
+ torch.backends.cudnn.benchmark = True
10
+
11
+ BNB_CONFIG = BitsAndBytesConfig(
12
+ load_in_4bit=True,
13
+ bnb_4bit_quant_type="nf4",
14
+ bnb_4bit_compute_dtype=torch.bfloat16 ,
15
+ bnb_4bit_use_double_quant=True,
16
+ )
17
+
18
+ model_path = f"./FLUX.2-klein-9B"
19
+ prompt = "A beautiful korean kpop young woman holding a sign that says hello world"
20
+ height, width, guidance_scale, steps, seed = 1024, 1024, 4.0, 4, 0
21
+ dtype = torch.bfloat16
22
+
23
+ transformer = Flux2Transformer2DModel.from_pretrained(
24
+ "./FLUX.2-9B-bnb-4bit/transformer",
25
+ #sudfolder="transformer",
26
+ quantization_config=BNB_CONFIG,
27
+ torch_dtype=dtype,
28
+ #use_safetensors=False,
29
+ )
30
+
31
+ text_encoder = Qwen3ForCausalLM.from_pretrained(
32
+ "./FLUX.2-9B-bnb-4bit/text_encoder",
33
+ #sudfolder="text_encoder",
34
+ quantization_config=BNB_CONFIG,
35
+ torch_dtype=dtype
36
+ )
37
+
38
+ pipe = Flux2KleinPipeline.from_pretrained(
39
+ "FLUX.2-9B-bnb-4bit",
40
+ torch_dtype=dtype,
41
+ transformer=transformer,
42
+ text_encoder=text_encoder,
43
+ )
44
+
45
+ #pipe.enable_vae_slicing()
46
+
47
+ pipe.to("cuda")
48
+
49
+ img = pipe(
50
+ prompt=prompt,
51
+ height=height,
52
+ width=width,
53
+ guidance_scale=guidance_scale,
54
+ num_inference_steps=steps,
55
+ generator=torch.Generator(device="cuda").manual_seed(seed),
56
+ ).images[0]
57
+
58
+ output = "output/flux2_beauty2.png"
59
+ os.makedirs(os.path.dirname(output) or ".", exist_ok=True)
60
+ img.save(output)
61
+
62
+ #pipe.save_pretrained('./FLUX.2-lightning')
klein3.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import diffusers
3
+ from sdnq import SDNQConfig # import sdnq to register it into diffusers and transformers
4
+ from sdnq.common import use_torch_compile as triton_is_available
5
+ from sdnq.loader import apply_sdnq_options_to_model
6
+
7
+ pipe = diffusers.Flux2KleinPipeline.from_pretrained("Disty0/FLUX.2-klein-9B-SDNQ-4bit-dynamic-svd-r32", torch_dtype=torch.bfloat16)
8
+
9
+ # Enable INT8 MatMul for AMD, Intel ARC and Nvidia GPUs:
10
+ if triton_is_available and (torch.cuda.is_available() or torch.xpu.is_available()):
11
+ pipe.transformer = apply_sdnq_options_to_model(pipe.transformer, use_quantized_matmul=True)
12
+ pipe.text_encoder = apply_sdnq_options_to_model(pipe.text_encoder, use_quantized_matmul=True)
13
+ # pipe.transformer = torch.compile(pipe.transformer) # optional for faster speeds
14
+
15
+
16
+ pipe.to("cuda")
17
+ #pipe.enable_model_cpu_offload()
18
+
19
+ from PIL import Image
20
+
21
+ init_image = Image.open("suji.jpg").convert("RGB")
22
+
23
+
24
+ prompt = "A beautiful korean woman holding a sign that says Circulus Inc. comics style."
25
+ image = pipe(
26
+ image=init_image,
27
+ prompt=prompt,
28
+ height=1024,
29
+ width=1024,
30
+ guidance_scale=1.0,
31
+ num_inference_steps=4,
32
+ generator=torch.manual_seed(0)
33
+ ).images[0]
34
+
35
+ image.save("flux-klein-sdnq-4bit-dynamic-svd-r32_d.png")
ltx.py ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from diffusers import LTX2Pipeline, LTX2ImageToVideoPipeline, LTX2VideoTransformer3DModel
3
+ from diffusers.pipelines.ltx2.export_utils import encode_video
4
+ from diffusers.utils import load_image
5
+ from transformers import Qwen3ForCausalLM, BitsAndBytesConfig, AutoTokenizer
6
+ import math
7
+ import numpy as np
8
+
9
+ torch.backends.cuda.matmul.allow_tf32 = True
10
+ torch.backends.cudnn.allow_tf32 = True
11
+ torch.backends.cudnn.benchmark = True
12
+
13
+ BNB_CONFIG = BitsAndBytesConfig(
14
+ load_in_4bit=True,
15
+ bnb_4bit_quant_type="nf4",
16
+ bnb_4bit_compute_dtype=torch.bfloat16 ,
17
+ bnb_4bit_use_double_quant=True,
18
+ )
19
+
20
+
21
+ from diffusers import LTX2Pipeline
22
+ from diffusers.pipelines.ltx2.export_utils import encode_video
23
+ from transformers import Gemma3ForConditionalGeneration
24
+ repo= "Lightricks/LTX-2"
25
+
26
+ text_encoder = Gemma3ForConditionalGeneration.from_pretrained(
27
+ repo,
28
+ subfolder="text_encoder",
29
+ quantization_config=BNB_CONFIG
30
+ )
31
+
32
+ ### transformer
33
+ transformer_4bit = LTX2VideoTransformer3DModel.from_pretrained(
34
+ repo,
35
+ subfolder="transformer",
36
+ quantization_config=BNB_CONFIG
37
+ )
38
+
39
+
40
+
41
+ pipe = LTX2Pipeline.from_pretrained(
42
+ repo,
43
+ torch_dtype=torch.bfloat16,
44
+ transformer=transformer_4bit,
45
+ text_encoder=text_encoder,
46
+ )
47
+
48
+ pipe.vae.to(dtype=torch.bfloat16)
49
+ pipe.connectors.to(dtype=torch.bfloat16)
50
+ pipe.audio_vae.to(dtype=torch.bfloat16)
51
+ pipe.vocoder.to(dtype=torch.bfloat16)
52
+ pipe.to("cuda", dtype=torch.bfloat16)
53
+
54
+ image = load_image(
55
+ "./suji.jpg"
56
+ )
57
+
58
+
59
+ prompt = "A very beautiful korean kpop young woman is walking waikiki beach"
60
+ negative_prompt = "worst quality, inconsistent motion, blurry, jittery, distorted"
61
+
62
+ frame_rate = 24.0
63
+
64
+ with torch.autocast("cuda", dtype=torch.bfloat16):
65
+ video, audio = pipe(
66
+ #image=image,
67
+ prompt=prompt,
68
+ negative_prompt=negative_prompt,
69
+ width=768,
70
+ height=512,
71
+ num_frames=121,
72
+ frame_rate=frame_rate,
73
+ num_inference_steps=40,
74
+ guidance_scale=4.0,
75
+ output_type="np",
76
+ return_dict=False,
77
+ )
78
+ video = np.nan_to_num(video, nan=0.0)
79
+ video = np.clip(video, 0, 1)
80
+ video = (video * 255).round().astype("uint8")
81
+ video = torch.from_numpy(video)
82
+
83
+ encode_video(
84
+ video[0],
85
+ fps=frame_rate,
86
+ audio=audio[0].float().cpu(),
87
+ audio_sample_rate=pipe.vocoder.config.output_sampling_rate, # should be 24000
88
+ output_path="video2.mp4",
89
+ )
90
+
91
+ pipe.save_pretrained("./LTX-2-bnb-4bit")
suji.jpg ADDED

Git LFS Details

  • SHA256: 052cd84a4a6a6baf58eb9bf7318b7428358f0b1a587768144aa16f67d34fdd1e
  • Pointer size: 131 Bytes
  • Size of remote file: 235 kB