2022-09-12 07:34:13 -06:00
|
|
|
import sys
|
2023-05-28 23:54:13 -06:00
|
|
|
import textwrap
|
2022-09-12 07:34:13 -06:00
|
|
|
import traceback
|
|
|
|
|
|
|
|
|
2023-05-31 10:56:37 -06:00
|
|
|
def report(message: str, *, exc_info: bool = False) -> None:
|
2023-05-28 23:54:13 -06:00
|
|
|
"""
|
|
|
|
Print an error message to stderr, with optional traceback.
|
|
|
|
"""
|
|
|
|
for line in message.splitlines():
|
|
|
|
print("***", line, file=sys.stderr)
|
|
|
|
if exc_info:
|
|
|
|
print(textwrap.indent(traceback.format_exc(), " "), file=sys.stderr)
|
2023-05-31 10:56:37 -06:00
|
|
|
print("---", file=sys.stderr)
|
2023-05-28 23:54:13 -06:00
|
|
|
|
|
|
|
|
2023-01-04 02:35:07 -07:00
|
|
|
def print_error_explanation(message):
|
|
|
|
lines = message.strip().split("\n")
|
|
|
|
max_len = max([len(x) for x in lines])
|
|
|
|
|
|
|
|
print('=' * max_len, file=sys.stderr)
|
|
|
|
for line in lines:
|
|
|
|
print(line, file=sys.stderr)
|
|
|
|
print('=' * max_len, file=sys.stderr)
|
|
|
|
|
|
|
|
|
2023-05-26 13:15:59 -06:00
|
|
|
def display(e: Exception, task, *, full_traceback=False):
|
2023-01-04 02:35:07 -07:00
|
|
|
print(f"{task or 'error'}: {type(e).__name__}", file=sys.stderr)
|
2023-05-26 13:15:59 -06:00
|
|
|
te = traceback.TracebackException.from_exception(e)
|
|
|
|
if full_traceback:
|
|
|
|
# include frames leading up to the try-catch block
|
|
|
|
te.stack = traceback.StackSummary(traceback.extract_stack()[:-2] + te.stack)
|
|
|
|
print(*te.format(), sep="", file=sys.stderr)
|
2023-01-04 02:35:07 -07:00
|
|
|
|
|
|
|
message = str(e)
|
|
|
|
if "copying a param with shape torch.Size([640, 1024]) from checkpoint, the shape in current model is torch.Size([640, 768])" in message:
|
|
|
|
print_error_explanation("""
|
2023-01-16 20:50:30 -07:00
|
|
|
The most likely cause of this is you are trying to load Stable Diffusion 2.0 model without specifying its config file.
|
2023-01-04 02:35:07 -07:00
|
|
|
See https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Features#stable-diffusion-20 for how to solve this.
|
|
|
|
""")
|
|
|
|
|
|
|
|
|
2023-01-23 06:40:20 -07:00
|
|
|
already_displayed = {}
|
|
|
|
|
|
|
|
|
|
|
|
def display_once(e: Exception, task):
|
|
|
|
if task in already_displayed:
|
|
|
|
return
|
|
|
|
|
|
|
|
display(e, task)
|
|
|
|
|
|
|
|
already_displayed[task] = 1
|
|
|
|
|
|
|
|
|
2022-09-12 07:34:13 -06:00
|
|
|
def run(code, task):
|
|
|
|
try:
|
|
|
|
code()
|
|
|
|
except Exception as e:
|
2023-01-04 02:35:07 -07:00
|
|
|
display(task, e)
|