fix benchmark data in sdnext
parent
83dd4d8f65
commit
b73ffdcc8d
15
benchmark.py
15
benchmark.py
|
|
@ -1,9 +1,5 @@
|
||||||
import time
|
import time
|
||||||
import logging
|
import logging
|
||||||
import socket
|
|
||||||
from hashlib import sha256
|
|
||||||
from logging.handlers import SysLogHandler
|
|
||||||
|
|
||||||
from modules import shared
|
from modules import shared
|
||||||
from modules.processing import StableDiffusionProcessingTxt2Img, Processed, process_images
|
from modules.processing import StableDiffusionProcessingTxt2Img, Processed, process_images
|
||||||
|
|
||||||
|
|
@ -38,7 +34,7 @@ def run_benchmark(batch: int, extra: bool):
|
||||||
try:
|
try:
|
||||||
_processed: Processed = process_images(p)
|
_processed: Processed = process_images(p)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f'benchmark error: {batch} {e}')
|
print(f'SD-System-Info: benchmark error: {batch} {e}')
|
||||||
return 'error'
|
return 'error'
|
||||||
t1 = time.time()
|
t1 = time.time()
|
||||||
shared.state.end()
|
shared.state.end()
|
||||||
|
|
@ -47,13 +43,17 @@ def run_benchmark(batch: int, extra: bool):
|
||||||
|
|
||||||
|
|
||||||
class LogFilter(logging.Filter):
|
class LogFilter(logging.Filter):
|
||||||
|
import socket
|
||||||
hostname = socket.gethostname()
|
hostname = socket.gethostname()
|
||||||
def filter(self, record):
|
def filter(self, record):
|
||||||
record.hostname = LogFilter.hostname
|
record.hostname = LogFilter.hostname
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def submit_benchmark(data, username, console_logging):
|
def submit_benchmark(data, username):
|
||||||
|
from logging.handlers import SysLogHandler
|
||||||
|
from hashlib import sha256
|
||||||
|
|
||||||
syslog = SysLogHandler(address=('logs3.papertrailapp.com', 32554))
|
syslog = SysLogHandler(address=('logs3.papertrailapp.com', 32554))
|
||||||
syslog.addFilter(LogFilter())
|
syslog.addFilter(LogFilter())
|
||||||
formatter = logging.Formatter(f'%(asctime)s %(hostname)s SDBENCHMARK: {username} %(message)s', datefmt='%b %d %H:%M:%S')
|
formatter = logging.Formatter(f'%(asctime)s %(hostname)s SDBENCHMARK: {username} %(message)s', datefmt='%b %d %H:%M:%S')
|
||||||
|
|
@ -67,7 +67,4 @@ def submit_benchmark(data, username, console_logging):
|
||||||
message = '|'.join(line).replace(' ', ' ').replace('"', '').strip()
|
message = '|'.join(line).replace(' ', ' ').replace('"', '').strip()
|
||||||
hash256 = sha256(message.encode('utf-8')).hexdigest()[:6]
|
hash256 = sha256(message.encode('utf-8')).hexdigest()[:6]
|
||||||
message = message + '|' + hash256
|
message = message + '|' + hash256
|
||||||
if console_logging:
|
|
||||||
print('benchmark submit record:', line)
|
|
||||||
remote.info(message)
|
remote.info(message)
|
||||||
print('Benchmark submitted records:', len(data))
|
|
||||||
|
|
|
||||||
|
|
@ -6,20 +6,16 @@ import platform
|
||||||
import subprocess
|
import subprocess
|
||||||
import datetime
|
import datetime
|
||||||
import logging
|
import logging
|
||||||
from hashlib import sha256
|
|
||||||
from html.parser import HTMLParser
|
from html.parser import HTMLParser
|
||||||
import torch
|
import torch
|
||||||
import gradio as gr
|
import gradio as gr
|
||||||
import psutil
|
|
||||||
from modules import paths, script_callbacks, sd_hijack, sd_models, sd_samplers, shared, extensions, devices
|
from modules import paths, script_callbacks, sd_hijack, sd_models, sd_samplers, shared, extensions, devices
|
||||||
from benchmark import run_benchmark, submit_benchmark # pylint: disable=E0401,E0611,C0411
|
from benchmark import run_benchmark, submit_benchmark # pylint: disable=E0401,E0611,C0411
|
||||||
|
|
||||||
|
|
||||||
### system info globals
|
### system info globals
|
||||||
|
|
||||||
log = logging.getLogger('steps-animation')
|
log = logging.getLogger('sd')
|
||||||
log.setLevel(logging.INFO)
|
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
'date': '',
|
'date': '',
|
||||||
'timestamp': '',
|
'timestamp': '',
|
||||||
|
|
@ -41,7 +37,6 @@ data = {
|
||||||
'pipeline': shared.opts.data.get('sd_backend', ''),
|
'pipeline': shared.opts.data.get('sd_backend', ''),
|
||||||
'model': {},
|
'model': {},
|
||||||
}
|
}
|
||||||
|
|
||||||
networks = {
|
networks = {
|
||||||
'models': [],
|
'models': [],
|
||||||
'hypernetworks': [],
|
'hypernetworks': [],
|
||||||
|
|
@ -57,8 +52,6 @@ bench_text = ''
|
||||||
bench_file = os.path.join(os.path.dirname(__file__), 'benchmark-data-local.json')
|
bench_file = os.path.join(os.path.dirname(__file__), 'benchmark-data-local.json')
|
||||||
bench_headers = ['timestamp', 'performance', 'version', 'system', 'libraries', 'gpu', 'pipeline', 'model', 'username', 'note', 'hash']
|
bench_headers = ['timestamp', 'performance', 'version', 'system', 'libraries', 'gpu', 'pipeline', 'model', 'username', 'note', 'hash']
|
||||||
bench_data = []
|
bench_data = []
|
||||||
console_logging = None
|
|
||||||
|
|
||||||
|
|
||||||
### system info module
|
### system info module
|
||||||
|
|
||||||
|
|
@ -158,6 +151,7 @@ def get_memory():
|
||||||
return round(val / 1024 / 1024 / 1024, 2)
|
return round(val / 1024 / 1024 / 1024, 2)
|
||||||
mem = {}
|
mem = {}
|
||||||
try:
|
try:
|
||||||
|
import psutil
|
||||||
process = psutil.Process(os.getpid())
|
process = psutil.Process(os.getpid())
|
||||||
res = process.memory_info()
|
res = process.memory_info()
|
||||||
ram_total = 100 * res.rss / process.memory_percent()
|
ram_total = 100 * res.rss / process.memory_percent()
|
||||||
|
|
@ -494,8 +488,6 @@ def create_ui(blocks: gr.Blocks = None):
|
||||||
note = gr.Textbox('', label = 'Note', placeholder='enter any additional notes', elem_id='system_info_tab_note')
|
note = gr.Textbox('', label = 'Note', placeholder='enter any additional notes', elem_id='system_info_tab_note')
|
||||||
with gr.Column(scale=1):
|
with gr.Column(scale=1):
|
||||||
with gr.Row():
|
with gr.Row():
|
||||||
global console_logging # pylint: disable=global-statement
|
|
||||||
console_logging = gr.Checkbox(label = 'Console logging', value = False, elem_id = 'system_info_tab_console', interactive = True)
|
|
||||||
warmup = gr.Checkbox(label = 'Perform warmup', value = True, elem_id = 'system_info_tab_warmup')
|
warmup = gr.Checkbox(label = 'Perform warmup', value = True, elem_id = 'system_info_tab_warmup')
|
||||||
extra = gr.Checkbox(label = 'Extra steps', value = False, elem_id = 'system_info_tab_extra')
|
extra = gr.Checkbox(label = 'Extra steps', value = False, elem_id = 'system_info_tab_extra')
|
||||||
level = gr.Radio(['quick', 'normal', 'extensive'], value = 'normal', label = 'Benchmark level', elem_id = 'system_info_tab_level')
|
level = gr.Radio(['quick', 'normal', 'extensive'], value = 'normal', label = 'Benchmark level', elem_id = 'system_info_tab_level')
|
||||||
|
|
@ -544,25 +536,28 @@ def create_ui(blocks: gr.Blocks = None):
|
||||||
|
|
||||||
def bench_submit(username: str):
|
def bench_submit(username: str):
|
||||||
if username is None or username == '':
|
if username is None or username == '':
|
||||||
log.debug('SD-System-Info: username is required to submit results')
|
log.error('SD-System-Info: username is required to submit results')
|
||||||
return
|
return
|
||||||
submit_benchmark(bench_data, username, console_logging.value)
|
submit_benchmark(bench_data, username)
|
||||||
log.debug(f'SD-System-Info: benchmark data submitted: {len(bench_data)} records')
|
log.info(f'SD-System-Info: benchmark data submitted: {len(bench_data)} records')
|
||||||
|
|
||||||
|
|
||||||
def bench_run(batches: list = [1], extra: bool = False):
|
def bench_run(batches: list = [1], extra: bool = False):
|
||||||
results = []
|
results = []
|
||||||
for batch in batches:
|
for batch in batches:
|
||||||
log.debug(f'SD-System-Info: benchmark running for batch size {batch}')
|
log.debug(f'SD-System-Info: benchmark starting: batch-size={batch}')
|
||||||
res = run_benchmark(batch, extra)
|
res = run_benchmark(batch, extra)
|
||||||
log.debug(f'SD-System-Info: benchmark results batch size {batch}: {res} it/s')
|
log.info(f'SD-System-Info: benchmark batch-size={batch} it/s={res}')
|
||||||
results.append(str(res))
|
results.append(str(res))
|
||||||
its = ' / '.join(results)
|
its = ' / '.join(results)
|
||||||
return its
|
return its
|
||||||
|
|
||||||
|
|
||||||
def bench_init(username: str, note: str, warmup: bool, level: str, extra: bool):
|
def bench_init(username: str, note: str, warmup: bool, level: str, extra: bool):
|
||||||
|
from hashlib import sha256
|
||||||
|
|
||||||
log.debug('SD-System-Info: benchmark starting')
|
log.debug('SD-System-Info: benchmark starting')
|
||||||
|
get_full_data()
|
||||||
hash256 = sha256((dict2str(data['platform']) + data['torch'] + dict2str(data['libs']) + dict2str(data['gpu']) + ','.join(data['optimizations']) + data['crossattention']).encode('utf-8')).hexdigest()[:6]
|
hash256 = sha256((dict2str(data['platform']) + data['torch'] + dict2str(data['libs']) + dict2str(data['gpu']) + ','.join(data['optimizations']) + data['crossattention']).encode('utf-8')).hexdigest()[:6]
|
||||||
existing = [x for x in bench_data if (x[-1] is not None and x[-1][:6] == hash256)]
|
existing = [x for x in bench_data if (x[-1] is not None and x[-1][:6] == hash256)]
|
||||||
if len(existing) > 0:
|
if len(existing) > 0:
|
||||||
|
|
@ -606,7 +601,7 @@ def bench_init(username: str, note: str, warmup: bool, level: str, extra: bool):
|
||||||
d[10] = hash256
|
d[10] = hash256
|
||||||
|
|
||||||
md = '| ' + ' | '.join(d) + ' |'
|
md = '| ' + ' | '.join(d) + ' |'
|
||||||
log.debug(f'SD-System-Info: benchmark result: {md}')
|
log.info(f'SD-System-Info: benchmark result: {md}')
|
||||||
|
|
||||||
bench_save()
|
bench_save()
|
||||||
return bench_data
|
return bench_data
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue