sbicy commited on
Commit
c0fb55e
·
verified ·
1 Parent(s): b3b7325

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -4,11 +4,10 @@ import torch
4
 
5
  def load_model():
6
  try:
7
- # Load the model with explicit variant for half-precision weights
8
  pipeline = StableDiffusionPipeline.from_pretrained(
9
  "stabilityai/stable-diffusion-2-1",
10
- torch_dtype=torch.float16,
11
- variant="fp16", # Updated from 'revision' to 'variant'
12
  safety_checker=None # Disable safety checker for faster inference
13
  )
14
  except Exception as e:
@@ -18,15 +17,16 @@ def load_model():
18
  # Configure the scheduler for faster generation
19
  pipeline.scheduler = DPMSolverMultistepScheduler.from_config(pipeline.scheduler.config)
20
 
21
- # Move to CPU if no GPU is available
22
  try:
23
- pipeline = pipeline.to("cuda" if torch.cuda.is_available() else "cpu")
24
  except Exception as e:
25
  print(f"Error moving the model to device: {e}")
26
  raise
27
 
28
  return pipeline
29
 
 
30
  # Initialize the model
31
  try:
32
  model = load_model()
 
4
 
5
  def load_model():
6
  try:
7
+ # Load the model without forcing half-precision
8
  pipeline = StableDiffusionPipeline.from_pretrained(
9
  "stabilityai/stable-diffusion-2-1",
10
+ torch_dtype=torch.float32, # Use float32 for CPU compatibility
 
11
  safety_checker=None # Disable safety checker for faster inference
12
  )
13
  except Exception as e:
 
17
  # Configure the scheduler for faster generation
18
  pipeline.scheduler = DPMSolverMultistepScheduler.from_config(pipeline.scheduler.config)
19
 
20
+ # Move to CPU
21
  try:
22
+ pipeline = pipeline.to("cpu")
23
  except Exception as e:
24
  print(f"Error moving the model to device: {e}")
25
  raise
26
 
27
  return pipeline
28
 
29
+
30
  # Initialize the model
31
  try:
32
  model = load_model()