Retry failed ZeroGPU allocations
Browse files
app.py
CHANGED
|
@@ -4,6 +4,7 @@ import secrets
|
|
| 4 |
import shutil
|
| 5 |
import sys
|
| 6 |
import threading
|
|
|
|
| 7 |
import urllib.parse
|
| 8 |
import urllib.request
|
| 9 |
import uuid
|
|
@@ -125,7 +126,11 @@ DEFAULT_SECOND_SCHEDULER = "karras"
|
|
| 125 |
DEFAULT_SECOND_STEPS = 18
|
| 126 |
DEFAULT_SECOND_CFG = 5
|
| 127 |
DEFAULT_DENOISE = .5
|
| 128 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
|
| 130 |
jobs = {}
|
| 131 |
images = {}
|
|
@@ -394,6 +399,22 @@ def generate_core(body):
|
|
| 394 |
return image[0], first_seed, second_seed
|
| 395 |
|
| 396 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 397 |
def load_model(name):
|
| 398 |
if name not in state["models"]:
|
| 399 |
stage_model("checkpoints", name)
|
|
@@ -522,7 +543,7 @@ def generate_image(request, tag="ST"):
|
|
| 522 |
if request.upscale and request.second_model:
|
| 523 |
load_chain(request.second_model, request.second_loras)
|
| 524 |
|
| 525 |
-
image, first_seed, second_seed =
|
| 526 |
request.model_dump_json()
|
| 527 |
)
|
| 528 |
|
|
@@ -643,18 +664,12 @@ def api_generate(body, p=""):
|
|
| 643 |
|
| 644 |
def queued_generate(request):
|
| 645 |
client = Client(LOCAL_URL, verbose=False)
|
| 646 |
-
|
| 647 |
-
|
| 648 |
-
|
| 649 |
-
|
| 650 |
-
|
| 651 |
-
|
| 652 |
-
api_name="/generate",
|
| 653 |
-
)
|
| 654 |
-
return Image.open(result).copy()
|
| 655 |
-
except Exception as error:
|
| 656 |
-
if attempt or GPU_ABORT_ERROR not in str(error):
|
| 657 |
-
raise
|
| 658 |
|
| 659 |
|
| 660 |
def linked_value(workflow, value):
|
|
|
|
| 4 |
import shutil
|
| 5 |
import sys
|
| 6 |
import threading
|
| 7 |
+
import time
|
| 8 |
import urllib.parse
|
| 9 |
import urllib.request
|
| 10 |
import uuid
|
|
|
|
| 126 |
DEFAULT_SECOND_STEPS = 18
|
| 127 |
DEFAULT_SECOND_CFG = 5
|
| 128 |
DEFAULT_DENOISE = .5
|
| 129 |
+
GPU_ATTEMPTS = 3
|
| 130 |
+
GPU_RETRY_ERRORS = (
|
| 131 |
+
"GPU task aborted",
|
| 132 |
+
"uncorrectable ECC error",
|
| 133 |
+
)
|
| 134 |
|
| 135 |
jobs = {}
|
| 136 |
images = {}
|
|
|
|
| 399 |
return image[0], first_seed, second_seed
|
| 400 |
|
| 401 |
|
| 402 |
+
def generate_gpu(body):
|
| 403 |
+
for attempt in range(GPU_ATTEMPTS):
|
| 404 |
+
try:
|
| 405 |
+
return generate_core(body)
|
| 406 |
+
except Exception as error:
|
| 407 |
+
if (
|
| 408 |
+
attempt == GPU_ATTEMPTS - 1
|
| 409 |
+
or not any(text in str(error) for text in GPU_RETRY_ERRORS)
|
| 410 |
+
):
|
| 411 |
+
raise
|
| 412 |
+
|
| 413 |
+
delay = 2**attempt
|
| 414 |
+
log(f"GPU allocation failed, retrying in {delay}s")
|
| 415 |
+
time.sleep(delay)
|
| 416 |
+
|
| 417 |
+
|
| 418 |
def load_model(name):
|
| 419 |
if name not in state["models"]:
|
| 420 |
stage_model("checkpoints", name)
|
|
|
|
| 543 |
if request.upscale and request.second_model:
|
| 544 |
load_chain(request.second_model, request.second_loras)
|
| 545 |
|
| 546 |
+
image, first_seed, second_seed = generate_gpu(
|
| 547 |
request.model_dump_json()
|
| 548 |
)
|
| 549 |
|
|
|
|
| 664 |
|
| 665 |
def queued_generate(request):
|
| 666 |
client = Client(LOCAL_URL, verbose=False)
|
| 667 |
+
result = client.predict(
|
| 668 |
+
request.model_dump_json(),
|
| 669 |
+
PASSWORD,
|
| 670 |
+
api_name="/generate",
|
| 671 |
+
)
|
| 672 |
+
return Image.open(result).copy()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 673 |
|
| 674 |
|
| 675 |
def linked_value(workflow, value):
|