Spaces:
Running on Zero
Running on Zero
HadiZayer Claude Sonnet 4.6 commited on
Commit ·
87c1aac
1
Parent(s): a697bd3
Fix ZeroGPU compatibility: load model on CPU at startup, move to CUDA inside @spaces.GPU
Browse files- app.py +3 -0
- run_magicfu.py +5 -6
app.py
CHANGED
|
@@ -19,6 +19,7 @@ import gradio as gr
|
|
| 19 |
import numpy as np
|
| 20 |
import shutil
|
| 21 |
import os
|
|
|
|
| 22 |
|
| 23 |
|
| 24 |
# Download checkpoint from HF Hub at startup
|
|
@@ -42,7 +43,9 @@ for og, edit in EXAMPLE_PAIRS:
|
|
| 42 |
magic_fixup = MagicFixup(model_path=checkpoint_path)
|
| 43 |
|
| 44 |
|
|
|
|
| 45 |
def sample(original_image, coarse_edit):
|
|
|
|
| 46 |
to_tensor = torchvision.transforms.ToTensor()
|
| 47 |
with autocast("cuda"):
|
| 48 |
w, h = coarse_edit.size
|
|
|
|
| 19 |
import numpy as np
|
| 20 |
import shutil
|
| 21 |
import os
|
| 22 |
+
import spaces
|
| 23 |
|
| 24 |
|
| 25 |
# Download checkpoint from HF Hub at startup
|
|
|
|
| 43 |
magic_fixup = MagicFixup(model_path=checkpoint_path)
|
| 44 |
|
| 45 |
|
| 46 |
+
@spaces.GPU
|
| 47 |
def sample(original_image, coarse_edit):
|
| 48 |
+
magic_fixup.model.cuda()
|
| 49 |
to_tensor = torchvision.transforms.ToTensor()
|
| 50 |
with autocast("cuda"):
|
| 51 |
w, h = coarse_edit.size
|
run_magicfu.py
CHANGED
|
@@ -105,7 +105,6 @@ def load_model_from_config(config, ckpt, verbose=False):
|
|
| 105 |
print("unexpected keys:")
|
| 106 |
print(u)
|
| 107 |
|
| 108 |
-
model.cuda()
|
| 109 |
model.eval()
|
| 110 |
return model
|
| 111 |
|
|
@@ -124,7 +123,7 @@ def get_model(config_path, ckpt_path):
|
|
| 124 |
print(u)
|
| 125 |
|
| 126 |
|
| 127 |
-
model = model.
|
| 128 |
return model
|
| 129 |
|
| 130 |
def get_grid(size):
|
|
@@ -193,10 +192,10 @@ class MagicFixup:
|
|
| 193 |
inpaint_image = image_tensor#*mask_tensor
|
| 194 |
|
| 195 |
test_model_kwargs={}
|
| 196 |
-
test_model_kwargs['inpaint_mask']=mask_tensor.to(device)
|
| 197 |
-
test_model_kwargs['inpaint_image']=inpaint_image.to(device)
|
| 198 |
-
clean_ref_tensor = clean_ref_tensor.to(device)
|
| 199 |
-
ref_tensor=ref_tensor.to(device)
|
| 200 |
uc = None
|
| 201 |
if scale != 1.0:
|
| 202 |
uc = self.model.learnable_vector
|
|
|
|
| 105 |
print("unexpected keys:")
|
| 106 |
print(u)
|
| 107 |
|
|
|
|
| 108 |
model.eval()
|
| 109 |
return model
|
| 110 |
|
|
|
|
| 123 |
print(u)
|
| 124 |
|
| 125 |
|
| 126 |
+
model = model.cpu()
|
| 127 |
return model
|
| 128 |
|
| 129 |
def get_grid(size):
|
|
|
|
| 192 |
inpaint_image = image_tensor#*mask_tensor
|
| 193 |
|
| 194 |
test_model_kwargs={}
|
| 195 |
+
test_model_kwargs['inpaint_mask']=mask_tensor.to(self.model.device)
|
| 196 |
+
test_model_kwargs['inpaint_image']=inpaint_image.to(self.model.device)
|
| 197 |
+
clean_ref_tensor = clean_ref_tensor.to(self.model.device)
|
| 198 |
+
ref_tensor=ref_tensor.to(self.model.device)
|
| 199 |
uc = None
|
| 200 |
if scale != 1.0:
|
| 201 |
uc = self.model.learnable_vector
|