AbstractPhil commited on
Commit
bb1a324
·
verified ·
1 Parent(s): 675385d

Create inference_v42.py

Browse files
Files changed (1) hide show
  1. inference_v42.py +54 -0
inference_v42.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # TinyFlux Inference - Colab Cell
2
+ #
3
+ # Install and run:
4
+ # !pip install git+https://github.com/AbstractPhil/tinyflux.git
5
+ # # Then run this cell
6
+
7
+ #@title TinyFlux Inference
8
+ prompt = "a big lion sitting on a couch in a living room, walls, table, ceiling" #@param {type:"string"}
9
+ negative_prompt = "glass, cup" #@param {type:"string"}
10
+ seed = 42 #@param {type:"integer"}
11
+ steps = 50 #@param {type:"slider", min:4, max:50, step:1}
12
+ guidance = 3 #@param {type:"slider", min:1.0, max:15.0, step:0.5}
13
+
14
+ import torch
15
+ from tinyflux.model.zoo import ModelZoo
16
+ from tinyflux.trainer.sampling import Sampler
17
+ from PIL import Image
18
+ from IPython.display import display
19
+
20
+ device = "cuda" if torch.cuda.is_available() else "cpu"
21
+ dtype = torch.bfloat16 if device == "cuda" else torch.float32
22
+
23
+ # Load models
24
+ print("Loading models...")
25
+ zoo = ModelZoo(device=device, dtype=dtype)
26
+ zoo.load_vae()
27
+ zoo.load_clip()
28
+ zoo.load_t5()
29
+ model = zoo.load_tinyflux(
30
+ source="AbstractPhil/tiny-flux-deep",
31
+ load_ema=False,
32
+ ema_path="step_407682.safetensors",
33
+ )
34
+ print("✓ Models loaded")
35
+
36
+ # Create sampler
37
+ sampler = Sampler(
38
+ zoo=zoo,
39
+ model=model,
40
+ num_steps=steps,
41
+ guidance_scale=guidance,
42
+ shift=3.0,
43
+ device=device,
44
+ dtype=dtype,
45
+ )
46
+
47
+ # Generate
48
+ print(f"\nGenerating: {prompt}")
49
+ images = sampler.generate([prompt], seed=seed, negative_prompt=negative_prompt)
50
+
51
+ # Display
52
+ img = (images[0].permute(1, 2, 0).cpu().float().numpy() * 255).astype("uint8")
53
+ display(Image.fromarray(img))
54
+ print(f"Seed: {seed}, Steps: {steps}, CFG: {guidance}")