Spaces:
Running on Zero
Running on Zero
File size: 1,632 Bytes
b701455 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | import os
import sys
import time
import cProfile
import pstats
import io
from pathlib import Path
# Add project root to path
project_root = Path(__file__).resolve().parent.parent
sys.path.append(str(project_root))
from src.user.pipeline import pipeline
def run_benchmarked_pipeline():
print("π Starting benchmarked generation...")
# Warm-up run
print("π₯ Warm-up run...")
pipeline(
prompt="a high quality photo of a futuristic city",
w=512,
h=512,
number=1,
batch=1,
steps=10,
)
print("π Profiling generation...")
pr = cProfile.Profile()
pr.enable()
start_time = time.perf_counter()
pipeline(
prompt="a high quality photo of a futuristic city",
w=512,
h=512,
number=1,
batch=1,
steps=20,
)
end_time = time.perf_counter()
pr.disable()
print(f"β
Generation finished in {end_time - start_time:.2f}s")
# Analyze profile
s = io.StringIO()
sortby = pstats.SortKey.CUMULATIVE
ps = pstats.Stats(pr, stream=s).sort_stats(sortby)
ps.print_stats(30)
print("\n=== TOP 30 FUNCTIONS BY CUMULATIVE TIME ===")
print(s.getvalue())
# Also show by internal time
s = io.StringIO()
sortby = pstats.SortKey.TIME
ps = pstats.Stats(pr, stream=s).sort_stats(sortby)
ps.print_stats(30)
print("\n=== TOP 30 FUNCTIONS BY INTERNAL TIME ===")
print(s.getvalue())
if __name__ == "__main__":
# Ensure output dir exists
os.makedirs("./output", exist_ok=True)
run_benchmarked_pipeline()
|