Spaces:
Runtime error
Runtime error
ImageStudio Maintainer commited on
Commit Β·
52379d0
1
Parent(s): 5c7571d
feat: log total GPU time consumed per generate_image call
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@ import io
|
|
| 2 |
import os
|
| 3 |
import random
|
| 4 |
import re
|
|
|
|
| 5 |
|
| 6 |
import numpy as np
|
| 7 |
import torch
|
|
@@ -325,6 +326,32 @@ def generate_image(
|
|
| 325 |
progress=gr.Progress(track_tqdm=True),
|
| 326 |
):
|
| 327 |
"""Generate an image from the given prompt using the selected model."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 328 |
if randomize_seed:
|
| 329 |
seed = random.randint(0, MAX_SEED)
|
| 330 |
seed = int(seed)
|
|
|
|
| 2 |
import os
|
| 3 |
import random
|
| 4 |
import re
|
| 5 |
+
import time
|
| 6 |
|
| 7 |
import numpy as np
|
| 8 |
import torch
|
|
|
|
| 326 |
progress=gr.Progress(track_tqdm=True),
|
| 327 |
):
|
| 328 |
"""Generate an image from the given prompt using the selected model."""
|
| 329 |
+
_gpu_start = time.time()
|
| 330 |
+
try:
|
| 331 |
+
return _generate_image_inner(
|
| 332 |
+
model_name, prompt, negative_prompt, use_negative_prompt,
|
| 333 |
+
height, width, num_inference_steps, guidance_scale, seed, randomize_seed,
|
| 334 |
+
)
|
| 335 |
+
finally:
|
| 336 |
+
print(
|
| 337 |
+
f"[ImageStudio] GPU time consumed: {time.time() - _gpu_start:.2f}s "
|
| 338 |
+
f"(model={model_name}, steps={num_inference_steps}, {int(width)}x{int(height)})",
|
| 339 |
+
flush=True,
|
| 340 |
+
)
|
| 341 |
+
|
| 342 |
+
|
| 343 |
+
def _generate_image_inner(
|
| 344 |
+
model_name,
|
| 345 |
+
prompt,
|
| 346 |
+
negative_prompt,
|
| 347 |
+
use_negative_prompt,
|
| 348 |
+
height,
|
| 349 |
+
width,
|
| 350 |
+
num_inference_steps,
|
| 351 |
+
guidance_scale,
|
| 352 |
+
seed,
|
| 353 |
+
randomize_seed,
|
| 354 |
+
):
|
| 355 |
if randomize_seed:
|
| 356 |
seed = random.randint(0, MAX_SEED)
|
| 357 |
seed = int(seed)
|