InvokeAI icon indicating copy to clipboard operation
InvokeAI copied to clipboard

Init strength seemingly lacks precision, produces identical images for different values

Open n00mkrad opened this issue 4 years ago • 5 comments

The following commands all produce the exact same image:

blue-green sunset, beautiful photo --init_img "init.png" --strength 0.834 -n 1 -s 30 -C 11 -A k_euler_a -W 512 -H 512 -S 779812348
blue-green sunset, beautiful photo --init_img "init.png" --strength 0.835 -n 1 -s 30 -C 11 -A k_euler_a -W 512 -H 512 -S 779812348
blue-green sunset, beautiful photo --init_img "init.png" --strength 0.836 -n 1 -s 30 -C 11 -A k_euler_a -W 512 -H 512 -S 779812348
blue-green sunset, beautiful photo --init_img "init.png" --strength 0.837 -n 1 -s 30 -C 11 -A k_euler_a -W 512 -H 512 -S 779812348
blue-green sunset, beautiful photo --init_img "init.png" --strength 0.838 -n 1 -s 30 -C 11 -A k_euler_a -W 512 -H 512 -S 779812348
blue-green sunset, beautiful photo --init_img "init.png" --strength 0.839 -n 1 -s 30 -C 11 -A k_euler_a -W 512 -H 512 -S 779812348
blue-green sunset, beautiful photo --init_img "init.png" --strength 0.840 -n 1 -s 30 -C 11 -A k_euler_a -W 512 -H 512 -S 779812348
blue-green sunset, beautiful photo --init_img "init.png" --strength 0.841 -n 1 -s 30 -C 11 -A k_euler_a -W 512 -H 512 -S 779812348
blue-green sunset, beautiful photo --init_img "init.png" --strength 0.842 -n 1 -s 30 -C 11 -A k_euler_a -W 512 -H 512 -S 779812348
blue-green sunset, beautiful photo --init_img "init.png" --strength 0.843 -n 1 -s 30 -C 11 -A k_euler_a -W 512 -H 512 -S 779812348
blue-green sunset, beautiful photo --init_img "init.png" --strength 0.844 -n 1 -s 30 -C 11 -A k_euler_a -W 512 -H 512 -S 779812348
blue-green sunset, beautiful photo --init_img "init.png" --strength 0.845 -n 1 -s 30 -C 11 -A k_euler_a -W 512 -H 512 -S 779812348
blue-green sunset, beautiful photo --init_img "init.png" --strength 0.846 -n 1 -s 30 -C 11 -A k_euler_a -W 512 -H 512 -S 779812348
blue-green sunset, beautiful photo --init_img "init.png" --strength 0.847 -n 1 -s 30 -C 11 -A k_euler_a -W 512 -H 512 -S 779812348
blue-green sunset, beautiful photo --init_img "init.png" --strength 0.848 -n 1 -s 30 -C 11 -A k_euler_a -W 512 -H 512 -S 779812348
blue-green sunset, beautiful photo --init_img "init.png" --strength 0.849 -n 1 -s 30 -C 11 -A k_euler_a -W 512 -H 512 -S 779812348
blue-green sunset, beautiful photo --init_img "init.png" --strength 0.850 -n 1 -s 30 -C 11 -A k_euler_a -W 512 -H 512 -S 779812348
blue-green sunset, beautiful photo --init_img "init.png" --strength 0.851 -n 1 -s 30 -C 11 -A k_euler_a -W 512 -H 512 -S 779812348
blue-green sunset, beautiful photo --init_img "init.png" --strength 0.852 -n 1 -s 30 -C 11 -A k_euler_a -W 512 -H 512 -S 779812348
blue-green sunset, beautiful photo --init_img "init.png" --strength 0.853 -n 1 -s 30 -C 11 -A k_euler_a -W 512 -H 512 -S 779812348
blue-green sunset, beautiful photo --init_img "init.png" --strength 0.854 -n 1 -s 30 -C 11 -A k_euler_a -W 512 -H 512 -S 779812348
blue-green sunset, beautiful photo --init_img "init.png" --strength 0.855 -n 1 -s 30 -C 11 -A k_euler_a -W 512 -H 512 -S 779812348
blue-green sunset, beautiful photo --init_img "init.png" --strength 0.856 -n 1 -s 30 -C 11 -A k_euler_a -W 512 -H 512 -S 779812348
blue-green sunset, beautiful photo --init_img "init.png" --strength 0.857 -n 1 -s 30 -C 11 -A k_euler_a -W 512 -H 512 -S 779812348
blue-green sunset, beautiful photo --init_img "init.png" --strength 0.858 -n 1 -s 30 -C 11 -A k_euler_a -W 512 -H 512 -S 779812348
blue-green sunset, beautiful photo --init_img "init.png" --strength 0.859 -n 1 -s 30 -C 11 -A k_euler_a -W 512 -H 512 -S 779812348
blue-green sunset, beautiful photo --init_img "init.png" --strength 0.860 -n 1 -s 30 -C 11 -A k_euler_a -W 512 -H 512 -S 779812348
blue-green sunset, beautiful photo --init_img "init.png" --strength 0.861 -n 1 -s 30 -C 11 -A k_euler_a -W 512 -H 512 -S 779812348
blue-green sunset, beautiful photo --init_img "init.png" --strength 0.862 -n 1 -s 30 -C 11 -A k_euler_a -W 512 -H 512 -S 779812348
blue-green sunset, beautiful photo --init_img "init.png" --strength 0.863 -n 1 -s 30 -C 11 -A k_euler_a -W 512 -H 512 -S 779812348
blue-green sunset, beautiful photo --init_img "init.png" --strength 0.864 -n 1 -s 30 -C 11 -A k_euler_a -W 512 -H 512 -S 779812348
blue-green sunset, beautiful photo --init_img "init.png" --strength 0.865 -n 1 -s 30 -C 11 -A k_euler_a -W 512 -H 512 -S 779812348
blue-green sunset, beautiful photo --init_img "init.png" --strength 0.866 -n 1 -s 30 -C 11 -A k_euler_a -W 512 -H 512 -S 779812348

Somehow between 0.834 and 0.866 the image did not change at all.

Is there a hard limit to how small the strength steps can be?

n00mkrad avatar Aug 31 '22 14:08 n00mkrad

At a 0.001 step, I get 33 identical images.

Meaning --strength apparently only works at a precision of 0.033, or just 30 steps in total from 0.0 to 1.0.

n00mkrad avatar Aug 31 '22 14:08 n00mkrad

It is, for whatever reason, bound to the step count. 30 steps allow for an init weight step of 0.033, 50 steps allow for 0.02, 100 allow for 0.01, and so on.

Is this a fundamental limitation or a bug?

I see t_enc = int(strength * steps) in simplet2i.py, which seems to be the root of the problem. A float multiplication with the step count, rounded to int.

n00mkrad avatar Aug 31 '22 14:08 n00mkrad

You beat me to it, but I just tested and am seeing changes at increments of .01 at 100 steps.

How does this compare to the CompViz repo? I don't have the coding ability to check for myself but I think that would answer whether or not this is a bug.

namion avatar Aug 31 '22 14:08 namion

Is this a fundamental limitation or a bug?

If I'm reading the code correctly, it's a fundamental limitation. The way "partial strength" works for img2img is that it sets up diffusion as if it were going to run a specific number of steps (the --steps argument), and then it only runs some of those steps. E.g. if you ask for 10 steps and a strength of .6, it'll set up as if it were going to do 10 steps and then actually run 6 steps.

You can't do a fractional number of steps (or at least it's not obvious to me how you would - probably something like that is possible in principle but the code isn't set up for it).

bakkot avatar Aug 31 '22 14:08 bakkot

You folk have it 100% correct. Unless the strength * steps results in a change to the number of steps, there won't be a difference. The effect is exactly the same as changing strength to 1.0 and altering the number of steps manually.

lstein avatar Aug 31 '22 15:08 lstein