stable-diffusion-webui icon indicating copy to clipboard operation
stable-diffusion-webui copied to clipboard

[Bug]: Typo in re_attention in prompt_parser.py?

Open schumar opened this issue 2 years ago • 2 comments
trafficstars

Is there an existing issue for this?

  • [X] I have searched the existing issues and checked the recent builds/commits

What happened?

prompt_parser.py in line 261 has

re_attention = re.compile(r"""
\\\(|
\\\)|
\\\[|
\\]|
\\\\|
\\|
\(|
\[|
:([+-]?[.\d]+)\)|
\)|
]|
[^\\()\[\]:]+|
:
""", re.X)

The 5th line (\\]|) seems to be missing a backslash.

Steps to reproduce the problem

  1. Open file
  2. Stare at file
  3. ...
  4. Profit :)

What should have happened?

A correct regular expression should be in that file, with balanced brackets.

Commit where the problem happens

c1c27dad3ba371a5ae344b267c760aa51e77f193

What platforms do you use to access the UI ?

Linux

What browsers do you use to access the UI ?

Brave

Command Line Arguments

`--lowvram --always-batch-cond-uncond --theme dark --xformers`

List of extensions

No

Console logs

No

Additional information

(sorry for not filling out all the boxes, I guess this is not actually important)

schumar avatar Feb 14 '23 18:02 schumar

While that regex is definitely the stuff nightmares are made of, I'm not detecting any real impact from it. I tried editing the file, restarting the server, and generating an image with a static seed. I ran three passes with a prompt where a word had no brackets, square brackets, and escaped square brackets. Each change to the prompt changes the image, but between the version with two backslashes in the file, versus three, there is absolutely no difference in the result.

You can see on the 9th and 12th line there, there's another pair where the opening square bracket is escaped, but the closing is not. Google absolutely refuses to give up its secrets regarding this, but I hypothesize that you don't need to escape a close bracket if it's not after an open bracket.

DejitaruJin avatar Feb 15 '23 02:02 DejitaruJin

I added a print(res) to the code to see what falls out, and "fixing" this regexp does indeed not change the behavior -- at least not with the test cases I was able to come up with.

Even running this manually in ipython

for m in re_attention.finditer('(([(abc\[:2)(def\]:3)]))'):
    print(m.group(0), m.group(1))

showed no difference.

So yes, not a bug at all, it just makes the nigthmares worse ;)

schumar avatar Feb 20 '23 17:02 schumar