-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
REPL command returned after creating variation does not create the same image #641
Comments
This could either be a new bug I introduced during the RFC #266 work (i.e. the prompt string is wrong), or an older bug regarding reproducibility problems in random number generation on M1 systems. Could you compare the behavior against the main branch so that I can distinguish those possibilities? |
@mh-dm and @Any-Winter-4079 . Is this a manifestation of the non-reproducibility problem on MPS we were having earlier, or something separate? I'm pretty sure I've tested reproducibility of variation on Linux and it is OK, but I'll check later today before declaring this to be an M1 specific bug. |
@psychedelicious @lstein I did get the same image using Using this however It seems to me -S0 makes it not reproducible? I'm using Oh, another thing. I may not have the latest dev branch since I'm testing a bunch of things. But my version is at least consistent with the version from 1, max 2 days ago. Let me know if you are using 1.12.1 (so the problem is not nightly) and then I'll update and post my results again, to see if I can then reproduce the issue. |
Ccing: @bakkot @blessedcoolant @xraxa This turns out not to be an M1 specific problem, but a general issue for the variation-generating code on all platforms. If I run this identical command repeatedly I get different images even though I am setting the same seed each time:
The culprit is L104 of ldm/dream/generator/base.pm, indicated by the arrow here:
Commenting out this line of code doesn't interfere with variation generation and solves one problem. Now I do get the same series of variations when using -v0.1 along with a fixed seed. Unfortunately a fixed seed and the indicated -Vxxxxxx value still stubbornly produces a different image from the original variant. So there is more work needed to explore this. I will check the main branch to see if anything is different there and will update this comment if so. UPDATE: main does work as expected when I comment out the random seed generator, so it looks like I'll be able to track down the problem and fix it. |
- fixes no closing quote in pretty-printed dream_prompt string - removes unecessary -f switch when txt2img used In addition, this commit does an experimental commenting-out of the random.seed() call in the variation-generating part of ldm.dream.generator.base. This fixes the problem of two calls that use the same seed and -v0.1 generating different images (#641). However, it does not fix the issue of two images generated using the same seed and -VXXXXXX being different.
@lstein @psychedelicious Okay, just to comment what goes on in my machine:
It will generate the same image. The seed could be printed on screen, passed as an argument, added to the image metadata... Many possibilities. So for example, you generate 100 images that are variations. Each with a different (second) seed. Want to recreate some of those images? Just reuse the (second) seeds for those specific images. I'm not sure a code that is supposed to generate variations of images, generating every time a different image based on the original is really a bug. Update. Example: with a fixed (second) Then I can exit dream> q, re-enter |
There are two things happening here:
The first thing is intentional: if you ask for 5 variations, then another 5 variations, you presumably don't want the same things you got last time. (So @lstein your commenting-out of the The second thing is a bug caused (I expect) by this line - in python, |
@bakkot I agree with you. I think -S should indicate the seed for the original image. For example re-using If now I enter And if I enter that command again, I expect 3 new images, because If we somehow want the same variations (which is not the normal behavior, but e.g. say because we liked one a lot), we need to keep track of the second seed). |
Personally I would prefer |
@mh-dm You can go back to those results later even when variations are randomized: each variation prints the full command necessary to reproduce that variation. |
But that takes a lot of time. For example if I generate 20 images, then to generate a new one I have to specify -n21 because the first 20 images will be the same again... |
That seems to not work yet because there is a seed totally random. The simplest way to test it is printing that second seed.
And then simply use it.
What should happen is to add a new param here
|
That is a big downside, the question may be how often it happens in practice. If a few variations don't work, I'd personally try changing the variation strength or the sampler or the steps or the prompt or a combination. |
Exactly. I think the (or a) solution is my comment just above. About how often, I don't know, but I would expect to want to use the same strength often enough to be a bit of a pain otherwise (e.g. imagine needing to set new strength all the time, because with used strength values we get old images -and will we remember all those values used? :) |
I've fixed it insofar as the pretty-printed dream prompt now indicates the correct seed used to generate the variations, regardless of whether it was fixed in the original dream prompt or assigned automatically. I've been using seed values greater than zero, so the -S0 behavior is not an issue (should this be caught as an assertion error, or is it a feature?) I can revert the call to randomseed() so that -SXXXX -vY.Y never produce the same series of images. However, this behavior is different from what you get without -v, when -nXX produces the same series of images when given a fixed seed. My current issue is that when specifying the seed and variant produced by the pretty-printed prompt, I'm not getting the expected variant image back. This illustrates the problem:
Say I want to regenerate variant [2], so I cut and paste the corresponding output prompt line:
Nice try, but no match! I suspect that either:
I also thought that the variation_amount option (-v) should be set to zero, but this doesn't help. So at this point I'm going to stop trying to debug the problem and revert the random seed call in get_noise(). I did do some cleanup in dream.py regarding how the pretty-printed prompts are formatted, and I'm committing this to development. I leave it to later (or someone else) to implement @Any-Winter-4079 's proposed solution. |
That's definitely a problem. It used to be the original seed. (Variations have two seeds, which are interpolated between.) So you would never have the same value in That must have gotten broken at some point.
That is also a problem, independent of the previous thing. That also must have gotten broken at some point; when I initially introduced this feature |
I must have an older version because to me
with no |
@bakkot has described the expected behavior, my understanding of what should happen was accurate
Questions:
Finally - maybe I have missed a revelation while reading through the discussion here that explains this - I have the same issue as originally reported with REPL command 1: REPL command 2: Edit: to be clear, command |
Not exactly. So As a special case, if you specify It's probably possible to combine them into a single parameter in some fashion, but it's not really obvious to me that there is a clear way to do that.
Hopefully the above answered that question. You are pretty much always going to want to specify
Because the first seed really is special: are starting at that seed, not moving towards it. If you only have two seeds, yes, you could regard this as being just a weighted average of two seeds, and the order doesn't matter. But once you start getting into variations-of-variations - i.e., when you have more than one value in
Yeah, there's a separate bug introduced sometime in the last week or two caused by the initial seed getting lost on the way to getting printed. You can tell because the fist line printed in the output has the same seed value in |
Thank you for the very clear explanation. One point I am confused by:
If |
Not to get in the middle of the discussion (I'm reading intently) but what files are involved? |
Whoops, sorry, I had a typo in my example (now fixed). It does indeed mean "go all the way to 123". |
Yeah, I think this broke very recently (and probably only on the development branch), so I'm not surprised if you have an older version which still works correctly. Unfortunately I'm way behind on everything, so I can't tell you exactly which file the issue is in. |
At least some of this has resulted from my refactoring and simplifying how the dream command is reconstructed for display on the screen and in the PNG file. I did not understand the nuances of the variation syntax and so sorry to break your code. I'm just getting back to this conversation and will read through to the end before making any more comments. |
Ok, I've read through and understand what needs to be done to fix this. I just have to track and use the very original seed for the -S argument. Thanks for a great discussion, and I really appreciate @bakkot 's lucid explanation of the expected behavior and what -V really means. |
- fixes no closing quote in pretty-printed dream_prompt string - removes unecessary -f switch when txt2img used In addition, this commit does an experimental commenting-out of the random.seed() call in the variation-generating part of ldm.dream.generator.base. This fixes the problem of two calls that use the same seed and -v0.1 generating different images (invoke-ai#641). However, it does not fix the issue of two images generated using the same seed and -VXXXXXX being different.
- fixes no closing quote in pretty-printed dream_prompt string - removes unecessary -f switch when txt2img used In addition, this commit does an experimental commenting-out of the random.seed() call in the variation-generating part of ldm.dream.generator.base. This fixes the problem of two calls that use the same seed and -v0.1 generating different images (invoke-ai#641). However, it does not fix the issue of two images generated using the same seed and -VXXXXXX being different.
- fixes no closing quote in pretty-printed dream_prompt string - removes unecessary -f switch when txt2img used In addition, this commit does an experimental commenting-out of the random.seed() call in the variation-generating part of ldm.dream.generator.base. This fixes the problem of two calls that use the same seed and -v0.1 generating different images (invoke-ai#641). However, it does not fix the issue of two images generated using the same seed and -VXXXXXX being different.
- The seed printed needs to be the one generated prior to the initial noising operation. To do this, I added a new "first_seed" argument to the image callback in dream.py. - Closes #641
Should be working now. Fix committed to development. |
- fixes no closing quote in pretty-printed dream_prompt string - removes unecessary -f switch when txt2img used In addition, this commit does an experimental commenting-out of the random.seed() call in the variation-generating part of ldm.dream.generator.base. This fixes the problem of two calls that use the same seed and -v0.1 generating different images (invoke-ai#641). However, it does not fix the issue of two images generated using the same seed and -VXXXXXX being different.
- fixes no closing quote in pretty-printed dream_prompt string - removes unecessary -f switch when txt2img used In addition, this commit does an experimental commenting-out of the random.seed() call in the variation-generating part of ldm.dream.generator.base. This fixes the problem of two calls that use the same seed and -v0.1 generating different images (invoke-ai#641). However, it does not fix the issue of two images generated using the same seed and -VXXXXXX being different.
- The seed printed needs to be the one generated prior to the initial noising operation. To do this, I added a new "first_seed" argument to the image callback in dream.py. - Closes invoke-ai#641
Describe your environment
mamba env create -f environment-mac.yaml
Describe the bug
After generating an image, the REPL returns the command (parameters) which may be used to recreate that same image.
When variation amount is specified, the command returned does not recreate the same image.
To Reproduce
python scripts/dream.py
test -s 5 -S 0 -v 0.1
, call it "Image 1"outputs/img-samples/000070.810716037.png: "test -s 5 -W 512 -H 512 -C 7.5 -A k_lms -S 810716037 -n 1 -f 0.75 -V 810716037:0.1
Expected behavior
"Image 1" and "Image 2" are identical.
Additional context
Maybe I am misunderstanding how variations work
The text was updated successfully, but these errors were encountered: