Predictably random


Ever wondered what seeds are? Looking for predictable yet truly unique outcomes for Stable Diffusion? This post contains a quick behind the scenes tour of randomness.

Computers are in most cases entirely predictable. If you have them do something in the same way, you’ll get the same result. Of course, this isn’t always desirable.

The solution lies in pseudo-random generators which spit out sequences of “random” numbers. The pseudo though means that they are still based on math and have a defined outcome.

When working with Stable Diffusion you can get millions of different pictures from the same prompt. In some cases people will provide the “seed” for something that provides a desirable outcome. In this way one can predictable get the same outcome when using the same prompt and parameters.

Generally these seeds are 32-bit numbers and give you roughly 4 billion starting points. The seed is used to initialise the generator which will then generate a sequence. Of course, it’s important that you not only have the seed but are also using the exact same generator, expect to see an entirely different result if not.

You’d think 4 billion is a lot but that’s actually a tiny fraction of the real potential. Stable diffusion’s latent space is a matrix of 64×64 for a 512×512 image. There’s definitely vastly more ways to fill this matrix than 4 billion!

Below you’ll find a simple example. For all 3 pictures the number generator started with the same seed. For the second picture I read one float from the generator before passing the generator on to Stable Diffusion. For the 3rd one I first read 100 floats from the generator.

The matrix for the second picture simply consists of the same numbers shifted and with 1 new number added. The resulting pictures are distinct but we can see some similarities. The balls definitely still look a bit related. The third picture though shows very little resemblance. Sure, it’s also a ball on the beach as per my prompt but the similarities are limited.

So just reading one float from the generator prior to passing it on already gives us another 4 billion outcomes.

The similarities between the first and the second ball might have piqued your interest. What if some similarity is desirable?

Certain elements in the picture are a bit baked into the starting point. So when you use the same seed with only slight changes to the prompt you’ll get similar pictures. Sometimes there’ll be a striking similarity, other times you’ll have to dig a bit deeper. Let’s ask Stable Diffusion to render 3 pictures starting from the same seed, the only prompt change we make is hair colour.

After a bit of cheating (I had to try multiple hair colours for the second one), we get something cool to work with. The first and the second picture have a significant overlap. It’s either the same girl or they are sisters. The third picture is distinct but when you look at the elements in an abstract way you can see how there are still links.

In the overlap we can see how for example the hairline on the left for girl one and three are aligned. Girl number two has an arm there while keeping a very similar abstract boundary.

The example above purposely had a fairly weak prompt (portrait of a girl with a striped dress, blonde/white/red hair, sharp, high resolution). Notice how I did not specify what kind of stripes I wanted? Yet, the dresses definitely have similarities. And where the first girl gets more dress, the second girl gets black hair mixed with the white. I didn’t ask for the black streak in the hair but Stable Diffusion works from a starting point and figured white was just not an option there.

In conclusion, some tips on getting the most out of seeds:

  • Make sure you always have the seed of a picture -> You don’t want to hit a particularly great result with no way to reproduce it
  • Create lots of pictures with different seeds for every prompt -> You may feel the urge to tweak a prompt endlessly but it won’t help if you’re on a seed that just doesn’t vibe with the prompt
  • Stick to the same generator -> Once you’ve a sizeable set of seed and prompt combinations you really don’t want to start over again.
  • Generate pictures from code -> Not everyone’s cup of tea but it allows you to create “signature” seeds by going beyond the 4 billion options you get by default.
, ,

Leave a comment