tight-inversion commited on
Commit
96fea2f
·
1 Parent(s): 41d4fc8

Ensure AE on GPU

Browse files
Files changed (1) hide show
  1. app.py +8 -14
app.py CHANGED
@@ -23,20 +23,17 @@ from pulid.utils import resize_numpy_image_long, seed_everything
23
  def get_models(name: str, device: torch.device, offload: bool, fp8: bool):
24
  t5 = load_t5(device, max_length=128)
25
  clip = load_clip(device)
26
- if fp8:
27
- model = load_flow_model_quintized(name, device="cpu" if offload else device)
28
- else:
29
- model = load_flow_model(name, device="cpu" if offload else device)
30
  model.eval()
31
- ae = load_ae(name, device="cpu" if offload else device)
32
- ae.to(dtype=torch.bfloat16)
33
  return model, ae, t5, clip
34
 
35
 
36
  class FluxGenerator:
37
  def __init__(self, model_name: str, device: str, offload: bool, aggressive_offload: bool, args):
38
  self.device = torch.device(device)
39
- self.offload = offload
40
  self.aggressive_offload = aggressive_offload
41
  self.model_name = model_name
42
  self.model, self.ae, self.t5, self.clip_model = get_models(
@@ -45,13 +42,7 @@ class FluxGenerator:
45
  offload=self.offload,
46
  fp8=args.fp8,
47
  )
48
- self.pulid_model = PuLIDPipeline(self.model, device="cpu" if offload else device, weight_dtype=torch.bfloat16,
49
- onnx_provider=args.onnx_provider)
50
- if offload:
51
- self.pulid_model.face_helper.face_det.mean_tensor = self.pulid_model.face_helper.face_det.mean_tensor.to(torch.device("cuda"))
52
- self.pulid_model.face_helper.face_det.device = torch.device("cuda")
53
- self.pulid_model.face_helper.device = torch.device("cuda")
54
- self.pulid_model.device = torch.device("cuda")
55
  self.pulid_model.load_pretrain(args.pretrained_model)
56
 
57
  # function to encode an image into latents
@@ -458,5 +449,8 @@ if __name__ == "__main__":
458
  if args.aggressive_offload:
459
  args.offload = True
460
 
 
 
 
461
  demo = create_demo(args, args.name, args.device, args.offload, args.aggressive_offload)
462
  demo.launch(ssr_mode=False)
 
23
  def get_models(name: str, device: torch.device, offload: bool, fp8: bool):
24
  t5 = load_t5(device, max_length=128)
25
  clip = load_clip(device)
26
+ model = load_flow_model(name, device="cpu" if offload else device)
 
 
 
27
  model.eval()
28
+ ae = load_ae(name, device=device)
29
+ ae.to(device=device, dtype=torch.bfloat16)
30
  return model, ae, t5, clip
31
 
32
 
33
  class FluxGenerator:
34
  def __init__(self, model_name: str, device: str, offload: bool, aggressive_offload: bool, args):
35
  self.device = torch.device(device)
36
+ self.offload = False
37
  self.aggressive_offload = aggressive_offload
38
  self.model_name = model_name
39
  self.model, self.ae, self.t5, self.clip_model = get_models(
 
42
  offload=self.offload,
43
  fp8=args.fp8,
44
  )
45
+ self.pulid_model = PuLIDPipeline(self.model, device='cuda', weight_dtype=torch.bfloat16)
 
 
 
 
 
 
46
  self.pulid_model.load_pretrain(args.pretrained_model)
47
 
48
  # function to encode an image into latents
 
449
  if args.aggressive_offload:
450
  args.offload = True
451
 
452
+ print(f"Using device: {args.device}")
453
+ print(f"Offload: {args.offload}")
454
+
455
  demo = create_demo(args, args.name, args.device, args.offload, args.aggressive_offload)
456
  demo.launch(ssr_mode=False)