How to Use Dynamic Prompts in Stable Diffusion (Easy Tutorial)

author - Rico Rodriguez
Rico Rodriguez

Updated on

What are some of the hardest parts when using Stable Diffusion to generate nice images? For me, one thing is the time consuming process of brainstorming various prompt ideas.

Now with the Dynamic Prompts extension, everything can be much easier, it saves time and allows you to explore variations and create consistent images to some degree.

1. Use Dynamic Prompts to Take Your AI Image to the Next Level

Instead of creating and running multiple prompts, you can create a single prompt, and let the extension replace tokens for you. In this way, it allows you to easily explore different variations of an image concept. This can be helpful for brainstorming ideas or finding the perfect image for your needs.

Since they are all based on the same core prompt, it is more likely to generate images sharing a common style and aesthetics.

Stable Diffusion Dynamic Prompt Dress Wildcard

Dynamic Prompts Main Features:

  • Use wildcard to replace tokens from the designated list, such as randomizing dress styles in the prompts.
  • Use the angled bracket syntax to test tokens in batch. For instance, {green|blue|white} hair for three prompts, varying only the hair color.
  • Use the magic prompt script to expand short prompts into more descriptive versions.

Batch Test Prompts for Better AI Images:

With this extension, you can automatically test hundreds of prompt combinations, dramatically increasing your chances of discovering exceptional seeds and prompt strings. Since you are experimenting with a large batch, you can set the base resolution at 512px for the ease of your hardware.

But isn't a 512px resolution woefully inadequate for a high quality display? Don't worry, before we get started into the Dynamic Prompts tutorials, meet another must-have tool: Aiarty Image Enhancer.

It can upscale your low resolution images into 4K/8K/16K high resolution in a faster speed, with AI inferred details!

Stable Diffusion AI Image Upscaler AIArty Compare SD Girl
Stable Diffusion AI Image Upscaler AIArty

Aiarty Image Enhancer - Upscale and Enhance AI Images with Details

  • Lightweight standalone software to upscale low resolution images up to 32K
  • Auto AI inference to add details, deblur, denoise, and enhance images
  • Upscale 3000 images/hour, low RAM, optimized for AMD/Nvidia/Intel
  • 3 AI models, trained with a 6.78 million dataset, deliver realistic details

2. How to Use Dynamic Prompts in Stable Diffusion A1111

2.1 Install Dynamic Prompts Extension

Dynamic Prompts is an extension for Stable Diffusion Automatic1111 WebUI. You can directly install it from A1111.

Step 1. Launch Stable Diffusion A1111 WebUI and go to Extensions > Install from URL.

Step 2. Install from https://github.com/adieyal/sd-dynamic-prompts.git

Step 3. Find the extension in the Installed tab, hit Apply and restart UI.

Install From URL SD A1111

You shall see the Dynamic Prompts section in Stable Diffusion A1111 WebUI.

Dynamic Prompts A1111 WebUI

Alternatively, you can visit https://github.com/adieyal/sd-dynamic-prompts and download the folder, then copy and paste it to your-automatic1111-folder\extensions\.

Please remember to relaunch the WebUI every time you install new extensions.

2.2 Use Wildcard in Stable Diffusion Prompts

After enabling the Dynamic Prompts extension, you can use wildcards in your prompt.

Prompt syntax: two underscores symbol with the file name and two underscores at the end.

For instance, if your file name is hair_style.txt then the wildcard will be like __hairstyle__ (without adding .txt in the prompts).

  • -File name: girl_dress.txt
  • -Wild card: __girl_dress__
  • -File name: woman_handbags.txt
  • -Wild card: __woman_handbags__

Stable Diffusion Dynamic Prompt with wildcard: 1 girl, light smile, __hairstyle__, wearing __girl_dress__, hands on hip.

When you run the prompt, it will pick tokens from the hair style file and girl dress file.

Note:

  1. Dynamic Prompt will ignore the whitespace in your prompt. Therefore, you can structure your prompt as freely as you want.
  2. You can add comment to the prompt using # symbol. Any word after # is treated as a comment.

2.3 Create Your Own Wildcard

Step 1. Use ChatGPT to Build a List of Words

ChatGPT prompt: Make a list of 30 female hairstyles.

Step 2. Save it as a txt file in: automatic1111 folder\extensions\sd-dynamic-prompts\wildcards

Note: 1. If the wildcard folder doesn't exist, you can just create a new folder and name it as wildcards. 2. Please remember to restart A1111 WebUI after putting text files into the wildcards folder.

Dynamic Prompts Wildcard Create TXT File

ChatGPT prompt: List out 15 hair styles for girls, one style per line, with no extra descriptions.

ChatGPT output:

  • Long straight hair
  • Twintails
  • Ponytail
  • Bob
  • Pixie cut
  • Ombre hair
  • Curly hair
  • Braids
  • Bangs
  • Fishtail braids
  • Waterfall braids
  • French braids
  • Messy bun
  • Layered hair
  • High ponytail

Save it in a text editor and name it as girl_hairstyle.txt for later usage.

Example 1. Randomize Dress and Hair Style

Prompts with wildcard:

score_9,score_8_up,score_7_up,
1girl,solo,__booru_dress__,necklace,__girl_hairstyle__,
pouty lips,tiny,(chibi:1.1),standing, looking at viewer,grey_background,wide_shot

Here is what I got:

Dynamic Prompt Stable Diffusion Hairstyle Dress

Output 1:

score_9,score_8_up,score_7_up,
1girl,solo,maiden dress,necklace,curly hair,pouty lips,tiny,(chibi:1.1),standing, looking at viewer,grey_background,wide_shot

Output 2:

score_9,score_8_up,score_7_up,
1girl,solo,dark lolita dress,necklace,messy bun, pouty lips,tiny,(chibi:1.1),standing, looking at viewer,grey_background,wide_shot

Output 3:

score_9,score_8_up,score_7_up,
1girl,solo, harem_outfit ,necklace,ombre hair, pouty lips,tiny,(chibi:1.1),standing, looking at viewer,grey_background,wide_shot

Output 4:

score_9,score_8_up,score_7_up,
1girl,solo,strapless dress,necklace,fishtail braids, pouty lips,tiny,(chibi:1.1),standing, looking at viewer,grey_background,wide_shot

Likewise, if you want to get inspired with various kinds of outfit combinations, you can use wildcards as follows. I separated topwear from skirt and pants. Or you can go more general about bottomwear, without discriminating skirt from pants. It all depends on your project aims.

1girl,__booru_topwear__, __booru_skirt__,necklace,solo
1girl,__booru_topwear__, __booru_pants__,necklace,solo
1girl,__booru_topwear__, __booru_bottomwear__,necklace,solo

Bonus Info:

For the above Stable Diffusion images, I use the Pony based AutismmixSDXL checkpoints.

Model: AutismmixSDXL (Base Model Pony)

Size: 512x768

Sampler: Euler A

Example 2: Randomize Hat and Outfit

Dynamic Prompt Stable Diffusion Pony Hat

Prompts with wildcard:

score_9,score_8_up,score_7_up,
1 cute pony,solo, __booru_topwear__,__booru_skirt__,necklace,__booru_hat__,
pouty lips,tiny,tiny,standing,looking at viewer,grey_background,wide_shot

*Output:

…bustier,pleated_skirt,necklace,pony tail,hat_ornament…
…hooded_sweater,hakama_skirt,necklace,pony tail,hat_flower…
…winter_coat,lace_skirt,necklace,pony tail,flat_cap…

*Note: I omitted the start and ending parts of the prompt as they stay the same.

Example 3: Randomize Hat and Topwear

Dynamic Prompt Stable Diffusion Chibi Hat

Output:

…sweater_vest, necklace, sailer_hat…
…gym-shirt, necklace,mini_witch_hat…
..winter_coat,necklace,party_hat…

Batch Size vs Batch Count

For batch size, the seed of the generated image is not fixed. It increases by 1 per time. For instance, if I set the batch size to 3 with a random seed, here is the example output:

Image 1, seed: 2781182592
Image 2, seed: 2781182593
Image 3, seed: 2781182594

When you set batch size to 2, and batch count to 3, as you can see from the screenshot below: SD will generate 2 images per batch, and go for 3 times. If you don't fix the seed, it will iterate.

Stable Diffusion A1111 WebUI Batch Size vs Batch Count

2.4 Use Existing Wildcard

The Dynamic Prompt extension already has many collections to use as the wildcard. You can check them in sd-dynamic-prompts/collections or using the Wildcards Manager tab directly.

You can combine tokens for merged effects. For instance, combining two artists can produce images that share the features of both artists. Here is an example:

1 woman in living room, holding coffee, oil painting, in style of __british_baroque_painters__ and __dutch_goldenage_painters__

Here are the possible results:

1 woman in living room, holding coffee, oil painting, in style of John Hayls and Abraham van Dijck

1 woman in living room, holding coffee, oil painting, in style of Richard Gibson and Abraham Diepraam

That's because the dynamic prompt parser find names from british_baroque_painters.txt and dutch_goldenage_painters.txt files.

3. Angled Bracket Syntax

Sometimes, instead of letting the dynamic prompts extension to randomly pick from the txt file, you may want to specify tokens to be used. The solution is to use the angled bracket syntax in the prompt.

Step 1. Make sure you have already installed the Dynamic Prompts extension.

Step 2. Put tokens you want to iterate inside the angled bracket.

Dynamic Prompt Stable Diffusion Hair Color Hug

If you want to test different hair colors, while keeping other things the same, use {red|blue|purple}.

Example:

score_9,score_8_up,score_7_up,1girl,solo,with animal ears,<lora:p3tl0v3XLP:1>,p3tl0v3,(hugging a cute white rabbit:1.2),{silver|ginger|green|pink} hair,long curly hair,floral print dress,necklace,wide shot,heart pendant,silver jewelry,animal tail,night sky,flower,<lora:detailed_notrigger:1>

Since you can visualize these images now, it is much easier for you to decide which color palettes are more aesthetically pleasing. Personally, I find silver hair and white rabbit goes well against the dark sky.

Note:

{2$$red|blue|purple}: this will choose 2 words per time without duplicated combinations.

{red|blue|purple}{red|blue|purple} can produce duplicated prompts such as red red.

Below is another example:

Dynamic Prompt Stable Diffusion Dress Foxgirl

score_9,score_8_up,score_7_up,1girl,solo,flower,animal ears,sitting,tail,long hair,blue eyes, {maid dress|print kimono|sailor_dress},hair flower,orange hair,cat tail,hair ornament,blue flower,long sleeves,cat girl,plant,bangs,looking at viewer, sleeves past wrists,outdoors,collarbone,blush,feet out of frame,animal ear fluff,lips,night sky,puffy long sleeves,<lora:gr33nXLP:1>.

About Combinatorial Generation

Combinatorial Generation Stable Diffusion Dynamic Prompts

Combinatorial generation will generate the image according to the multiples of the items.

For instance, if you have two wildcard txt file: hat.txt has 3 hats, dress.txt file has 5 dresses, then the total number of possible combinations will be 3x5=15.

Combinatorial Generation Dynamic Prompt SD

If you tick to enable Combinatorial generation, and set the value to 0, it will go through all the combinations. If you don't have a powerful computer, you can set a value larger than 0. For instance, 7 will give you 7 combinations.

Note:

  1. Seed -1 means it will use a random seed. You can also fix the seed in the advanced option.
  2. You can use a wildcard together with an angled bracket.
Dynamic Prompt Stable Diffusion Extension Advanced

4. Prompt Magic

Besides iterating prompts for you, Dynamic Prompts also has a Prompt Magic feature.

It uses LLM models to expand and enrich your prompts. Besides using the built-in LLM models, you can also download prompt models from Github and Huggingface.

Input: 1 girl, witch dress, magic hat, hold a wand, fantasy world, fruit on ground.

Magic Prompt: 1 girl, young, beautiful, ethereal witch with long, flowing hair, shimmering black dress adorned with silver stars, and a pointed velvet hat topped with a crescent moon. She holds a glowing, wooden wand, emanating magical particles. Surrounded by a lush, enchanted forest with bioluminescent flora, she stands on a mossy ground strewn with exotic, glowing fruits.

5. Bonus Tips

1. Using ControlNet for Precision

As you already noticed, even if you fixed the seed, for each generation, the image can change slightly or drastically.

If you only want dynamic prompts to change cloth styles, but keep the hairstyle and character poses consistent, you need to use ControlNet.

Before tweaking parameters in ControlNet, you need to delete the hairstyle wildcard, as you no longer need the variations. Now just keep the cloth style wildcard.

You can follow the detailed tutorial here to use ControlNet in Stable Diffusion.

Note: If you are using SDXL or Pony Diffusion XL models, you need to use corresponding ControlNet processors. SD 1.5 based ControlNet won't work for SDXL and PDXL.

2. Check Image Creation Information

Since we're generating a ton of AI images, it's easy to forget the exact parameters used to create them. That's where the PNG Info extension for Stable Diffusion comes in handy.

Simply drag and drop the AI image into the PNG Info tab, and it will display all the creation details. This includes the prompts, checkpoint models, LoRAs (if any), step count, CFG scale, sampling method, VAE, and ControlNet settings.

You can learn more about Dynamic Prompt extension from its official wiki: https://github.com/adieyal/sd-dynamic-prompts/blob/main/docs/tutorial.md.

Do you have better suggestions to create nice prompts and control the generation process precisely? Join our social media communities to discuss, learn, and grow skills together.

You May Also Like

Rico Rodriguez is an experienced content writer with a deep-rooted interest in AI. He has been at the forefront of exploring generative AI tools like Stable Diffusion. His articles offer valuable insights into the world of AI, providing readers with practical tips and informative explanations.

Home > Stable Diffusion Guide > How to Use Dynamic Prompts in Stable Diffusion