stable-diffusion-webui

Форк
0
149 строк · 4.5 Кб
1
import sys
2
import textwrap
3
import traceback
4

5

6
exception_records = []
7

8

9
def format_traceback(tb):
10
    return [[f"{x.filename}, line {x.lineno}, {x.name}", x.line] for x in traceback.extract_tb(tb)]
11

12

13
def format_exception(e, tb):
14
    return {"exception": str(e), "traceback": format_traceback(tb)}
15

16

17
def get_exceptions():
18
    try:
19
        return list(reversed(exception_records))
20
    except Exception as e:
21
        return str(e)
22

23

24
def record_exception():
25
    _, e, tb = sys.exc_info()
26
    if e is None:
27
        return
28

29
    if exception_records and exception_records[-1] == e:
30
        return
31

32
    exception_records.append(format_exception(e, tb))
33

34
    if len(exception_records) > 5:
35
        exception_records.pop(0)
36

37

38
def report(message: str, *, exc_info: bool = False) -> None:
39
    """
40
    Print an error message to stderr, with optional traceback.
41
    """
42

43
    record_exception()
44

45
    for line in message.splitlines():
46
        print("***", line, file=sys.stderr)
47
    if exc_info:
48
        print(textwrap.indent(traceback.format_exc(), "    "), file=sys.stderr)
49
        print("---", file=sys.stderr)
50

51

52
def print_error_explanation(message):
53
    record_exception()
54

55
    lines = message.strip().split("\n")
56
    max_len = max([len(x) for x in lines])
57

58
    print('=' * max_len, file=sys.stderr)
59
    for line in lines:
60
        print(line, file=sys.stderr)
61
    print('=' * max_len, file=sys.stderr)
62

63

64
def display(e: Exception, task, *, full_traceback=False):
65
    record_exception()
66

67
    print(f"{task or 'error'}: {type(e).__name__}", file=sys.stderr)
68
    te = traceback.TracebackException.from_exception(e)
69
    if full_traceback:
70
        # include frames leading up to the try-catch block
71
        te.stack = traceback.StackSummary(traceback.extract_stack()[:-2] + te.stack)
72
    print(*te.format(), sep="", file=sys.stderr)
73

74
    message = str(e)
75
    if "copying a param with shape torch.Size([640, 1024]) from checkpoint, the shape in current model is torch.Size([640, 768])" in message:
76
        print_error_explanation("""
77
The most likely cause of this is you are trying to load Stable Diffusion 2.0 model without specifying its config file.
78
See https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Features#stable-diffusion-20 for how to solve this.
79
        """)
80

81

82
already_displayed = {}
83

84

85
def display_once(e: Exception, task):
86
    record_exception()
87

88
    if task in already_displayed:
89
        return
90

91
    display(e, task)
92

93
    already_displayed[task] = 1
94

95

96
def run(code, task):
97
    try:
98
        code()
99
    except Exception as e:
100
        display(task, e)
101

102

103
def check_versions():
104
    from packaging import version
105
    from modules import shared
106

107
    import torch
108
    import gradio
109

110
    expected_torch_version = "2.1.2"
111
    expected_xformers_version = "0.0.23.post1"
112
    expected_gradio_version = "3.41.2"
113

114
    if version.parse(torch.__version__) < version.parse(expected_torch_version):
115
        print_error_explanation(f"""
116
You are running torch {torch.__version__}.
117
The program is tested to work with torch {expected_torch_version}.
118
To reinstall the desired version, run with commandline flag --reinstall-torch.
119
Beware that this will cause a lot of large files to be downloaded, as well as
120
there are reports of issues with training tab on the latest version.
121

122
Use --skip-version-check commandline argument to disable this check.
123
        """.strip())
124

125
    if shared.xformers_available:
126
        import xformers
127

128
        if version.parse(xformers.__version__) < version.parse(expected_xformers_version):
129
            print_error_explanation(f"""
130
You are running xformers {xformers.__version__}.
131
The program is tested to work with xformers {expected_xformers_version}.
132
To reinstall the desired version, run with commandline flag --reinstall-xformers.
133

134
Use --skip-version-check commandline argument to disable this check.
135
            """.strip())
136

137
    if gradio.__version__ != expected_gradio_version:
138
        print_error_explanation(f"""
139
You are running gradio {gradio.__version__}.
140
The program is designed to work with gradio {expected_gradio_version}.
141
Using a different version of gradio is extremely likely to break the program.
142

143
Reasons why you have the mismatched gradio version can be:
144
  - you use --skip-install flag.
145
  - you use webui.py to start the program instead of launch.py.
146
  - an extension installs the incompatible gradio version.
147

148
Use --skip-version-check commandline argument to disable this check.
149
        """.strip())
150

151

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.