Merge branch 'main' of https://huggingface.co/spaces/not-lain/gpu-utils
Browse files
README.md
CHANGED
@@ -4,9 +4,9 @@ emoji: 🏃
|
|
4 |
colorFrom: red
|
5 |
colorTo: purple
|
6 |
sdk: gradio
|
7 |
-
sdk_version: 5.
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
---
|
11 |
|
12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
4 |
colorFrom: red
|
5 |
colorTo: purple
|
6 |
sdk: gradio
|
7 |
+
sdk_version: 5.14.0
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
---
|
11 |
|
12 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
CHANGED
@@ -20,6 +20,12 @@ def float32_high_matmul_precision():
|
|
20 |
finally:
|
21 |
torch.set_float32_matmul_precision("highest")
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
pipe = FluxFillPipeline.from_pretrained(
|
25 |
"black-forest-labs/FLUX.1-Fill-dev", torch_dtype=torch.bfloat16
|
@@ -135,15 +141,16 @@ def rmbg(image=None, url=None):
|
|
135 |
|
136 |
def mask_generation(image=None, d=None):
|
137 |
d = eval(d) # convert this to dictionary
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
|
|
147 |
sorted_ind = np.argsort(scores)[::-1]
|
148 |
masks = masks[sorted_ind]
|
149 |
scores = scores[sorted_ind]
|
@@ -165,7 +172,7 @@ def erase(image=None, mask=None):
|
|
165 |
return simple_lama(image, mask)
|
166 |
|
167 |
|
168 |
-
@spaces.GPU
|
169 |
def main(*args):
|
170 |
api_num = args[0]
|
171 |
args = args[1:]
|
|
|
20 |
finally:
|
21 |
torch.set_float32_matmul_precision("highest")
|
22 |
|
23 |
+
# use bfloat16 for the entire notebook
|
24 |
+
torch.autocast("cuda", dtype=torch.bfloat16).__enter__()
|
25 |
+
# turn on tfloat32 for Ampere GPUs (https://pytorch.org/docs/stable/notes/cuda.html#tensorfloat-32-tf32-on-ampere-devices)
|
26 |
+
if torch.cuda.get_device_properties(0).major >= 8:
|
27 |
+
torch.backends.cuda.matmul.allow_tf32 = True
|
28 |
+
torch.backends.cudnn.allow_tf32 = True
|
29 |
|
30 |
pipe = FluxFillPipeline.from_pretrained(
|
31 |
"black-forest-labs/FLUX.1-Fill-dev", torch_dtype=torch.bfloat16
|
|
|
141 |
|
142 |
def mask_generation(image=None, d=None):
|
143 |
d = eval(d) # convert this to dictionary
|
144 |
+
with torch.inference_mode(), torch.autocast("cuda", dtype=torch.bfloat16):
|
145 |
+
predictor = SAM2ImagePredictor.from_pretrained("facebook/sam2.1-hiera-large")
|
146 |
+
predictor.set_image(image)
|
147 |
+
input_point = np.array(d["input_points"])
|
148 |
+
input_label = np.array(d["input_labels"])
|
149 |
+
masks, scores, logits = predictor.predict(
|
150 |
+
point_coords=input_point,
|
151 |
+
point_labels=input_label,
|
152 |
+
multimask_output=True,
|
153 |
+
)
|
154 |
sorted_ind = np.argsort(scores)[::-1]
|
155 |
masks = masks[sorted_ind]
|
156 |
scores = scores[sorted_ind]
|
|
|
172 |
return simple_lama(image, mask)
|
173 |
|
174 |
|
175 |
+
@spaces.GPU(duration=120)
|
176 |
def main(*args):
|
177 |
api_num = args[0]
|
178 |
args = args[1:]
|