juanmackie commited on
Commit
4058b98
·
verified ·
1 Parent(s): 02b6fc3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -8
app.py CHANGED
@@ -4,7 +4,8 @@ import numpy as np
4
  import cv2
5
  from PIL import Image
6
  import tempfile # For creating temporary video files
7
- import os # <--- ADDED: Import the 'os' module
 
8
 
9
  # Marigold specific imports
10
  from diffusers import MarigoldDepthPipeline, DDIMScheduler
@@ -27,13 +28,16 @@ try:
27
  pipe.scheduler = DDIMScheduler.from_config(pipe.scheduler.config, timestep_spacing="trailing")
28
  pipe = pipe.to(device=device, dtype=dtype)
29
 
30
- # Enable xformers for memory-efficient attention if available (optional)
31
- try:
32
- import xformers
33
- pipe.enable_xformers_memory_efficient_attention()
34
- print("xFormers enabled for Marigold pipeline.")
35
- except ImportError:
36
- print("xFormers not found, running without memory-efficient attention.")
 
 
 
37
 
38
  print(f"MarigoldDepthPipeline loaded successfully from {CHECKPOINT} on {device}.")
39
  except Exception as e:
 
4
  import cv2
5
  from PIL import Image
6
  import tempfile # For creating temporary video files
7
+ import os # Import the 'os' module
8
+ import accelerate # Import accelerate for better memory management (recommended)
9
 
10
  # Marigold specific imports
11
  from diffusers import MarigoldDepthPipeline, DDIMScheduler
 
28
  pipe.scheduler = DDIMScheduler.from_config(pipe.scheduler.config, timestep_spacing="trailing")
29
  pipe = pipe.to(device=device, dtype=dtype)
30
 
31
+ # Enable xformers for memory-efficient attention ONLY IF CUDA is available
32
+ if torch.cuda.is_available():
33
+ try:
34
+ import xformers
35
+ pipe.enable_xformers_memory_efficient_attention()
36
+ print("xFormers enabled for Marigold pipeline.")
37
+ except ImportError:
38
+ print("xFormers not found, running without memory-efficient attention (on GPU).")
39
+ else:
40
+ print("Running on CPU or MPS. xFormers memory-efficient attention is not applicable.")
41
 
42
  print(f"MarigoldDepthPipeline loaded successfully from {CHECKPOINT} on {device}.")
43
  except Exception as e: