00:00Welcome to episode two of our Comfy UI tutorial series
00:02In this video, I will show you the basics of nodes and workflows, helping you get started with building your own projects
00:08Even if you don't plan to create your own workflows, maybe you download workflows from others and need to make changes, so it can be useful to have an idea of how things work
00:20In episode one, I demonstrated how to install and generate your first image using Stable Diffusion
00:26If you haven't installed Comfy UI or downloaded the model yet, please check out that episode first
00:33This is a basic Stable Diffusion workflow that can generate an image from text, often referred to as text-to-image
00:38Uh, to help you understand how it works more easily, I'll provide a simple
00:46analogy that will give you an idea of why it requires numerous nodes and steps to function properly
00:50I added some notes around the nodes to make it easier
00:53Now, imagine you're designing a custom cake at a bakery
00:57First, you choose a skilled baker, the model, who specializes in the type of cake you want
01:03In this case, our baker is the Juggernaut model
01:06Then, you give the baker detailed instructions on what you want in the cake, such as vanilla flavor, strawberries, and whipped cream
01:16This is called the positive prompt, and what to avoid, like, uh, nuts, chocolate
01:20This is called the negative prompt
01:24The baker starts preparing the cake by mixing the ingredients and baking it
01:28This is what the K sampler node does
01:31Then, you decide on the size of the cake
01:35Perhaps an 8-inch round cake
01:39This is where we use the empty latent image node, where we specify the width and height using pixels
01:43Once the cake is baked, the baker decorates it and prepares it for serving
01:48In this workflow, we use the VAE decode node for that step
01:51Finally, you take the completed cake home and display it on your dining table
01:55We use the save image node for that step
01:58Did this analogy help you understand the workflow better? Let's review it quickly
02:02We select the baker
02:05You give the baker detailed instructions on what you want in the cake and what to avoid
02:08The baker starts preparing the cake by mixing the ingredients and baking it
02:12You decide on the size of the cake
02:15Um, once the cake is baked, the baker decorates it and prepares it
02:17for serving
02:19Finally, you take the completed cake home and display it on your dining table
02:24Let's talk a little bit about, um, the interface
02:27Uh, the Q prompt button adds the current workflow to the queue, which prepares your setup for image generation
02:34Um, it's like hitting start on a task list
02:37By checking extra options, it reveals more advanced settings for generating images, such as the number of images to create at once, the batch count, or automatic queuing when parameters change
02:50The save button saves the current workflow so you can load it later
02:53It's like saving a document on your computer
02:57The load button loads a previously saved workflow, restoring it to your current session
03:01This is useful for reusing workflows
03:04The refresh button updates or reloads the current view or settings, ensuring you see the most recent changes
03:12The clear button clears the current workflow, resetting it to a blank state
03:16The load default button loads the default settings, returning the interface to its original state
03:21The reset view button resets the layout or arrangement of the interface elements to their default positions
03:27The manager button opens the ComfyUI manager, which is a management interface for, um, detail control over your projects, settings, and custom nodes
03:38The share button allows you to share the current project or workflow with others on different websites
03:42So, save your current workflow by clicking save, give it a name, and store it somewhere on your
03:50drive, then click the clear button to remove everything from the screen and start fresh
03:54The area where you add nodes in ComfyUI is commonly referred to as the canvas or node canvas
04:01This is the main workspace where you can create, connect, and manage various nodes to build your workflows
04:10You can add a new node by either double-clicking
04:12For example, you can search for "load" and select "load checkpoint," which will add that node to the canvas
04:17Uh, you can left-click on it and move it around
04:22And the second option is to right-click on the canvas, then go to "add node," and from the list, select it from the loaders category
04:33I can select the same node, "load checkpoint." To select different nodes, simply click on them
04:38If you press the Alt button and then Left-click and drag, it will drag a copy of that node
04:45Alternatively, you can use Control+C for copy and Control+V for paste
04:50If you right-click on a node, you have access to more options and settings
04:55You can also remove the node using the remove option, or simply press the delete key while the node is selected
05:04Sometimes you need to resize a node to make it look better
05:06You can do this by dragging from the bottom right corner
05:11Resizing from other corners won't work, only that corner will allow you to resize
05:16Here you have the node name, and in front of it, there is a small circle
05:22When you click on it, it will make the node smaller
05:23This action is often referred to as collapsing the node
05:29Collapsing a node reduces it to a more compact form, which helps in managing and organizing the workspace more efficiently, especially when dealing with complex workflows
05:40Here are also some shortcuts you can use to select nodes
05:43Remember these three control keys: Alt, Control, and Shift
05:50Knowing these three keys is usually sufficient for most software out there
05:54If one key doesn't work, try another
05:56That is what I do since I cannot remember all the shortcuts
05:59Many programs have hidden features accessible through these keys
06:05To select a single node, simply click on it
06:07If you want to move the node to a different position, click on the node and drag it to the desired location
06:14To select multiple nodes, hold down the Shift key and click on each node you want to select individually
06:21You can also select multiple nodes by holding down the control key and then dragging to create a selection box that encompasses all the nodes you want to select
06:30Release the mouse button to select all nodes within the box
06:34Once multiple nodes are selected, hold down the shift key, then click and drag any of the selected nodes to move all selected nodes together
06:42Let's clear the canvas and, uh, let me show you a few more things about the nodes
06:47I will add a few different nodes so I can explain what several key elements are composed of
06:54Uh, we have the node name, um, that identifies the function or operation of the node
06:59Uh, for most nodes, you can guess what they do from their names
07:02For example, if "load" is in the name, um, it probably loads
07:07something like a checkpoint model
07:08In this case, K sampler may not be obvious from its name, but you can think of it as a family of samplers
07:14Um, to make it easier to remember, consider K sampler as a key component
07:18Save image does exactly what it says, it saves the image to your computer automatically
07:23Then you have the inputs, connection points where data or signals are received from other nodes
07:29For example, K sampler has many inputs
07:31Uh, load checkpoint doesn't have any inputs, and save image has one input called images
07:39Next, there are the outputs, connection points where data or signals are sent to other nodes
07:45K sampler has only one output named latent
07:48Load checkpoint has three outputs, and save image doesn't have any outputs, so you cannot add more nodes after the image is saved and then have parameters or settings
08:00These are configurable options within the node that control its behavior and processing
08:07For example, K sampler has settings like seed, steps, and CFG that you can adjust
08:13For save image, you can change the prefix value of the image name so that it starts with whatever value you add there
08:22By the way, you can move this menu from the top left corner where those tiny dots are located
08:30The connections between nodes and ComfyUI are called links, but you can call them whatever you like, cables, spaghetti
08:38These links enable data or signals to flow from the output of one node to the input of another, allowing for the creation of a functional
08:43workflow
08:49So, if I want to create a link between these two nodes, I look at the connection points that usually have the same name and color
08:55For example, here, uh, both nodes have, um, connection points named model, and the color is purple
09:02This allows me to drag from purple to purple
09:04However, if I try to drag to a different color, it doesn't let me create the connection
09:11So, uh, I will drag it to the, um, purple connection point, and when I release the mouse, uh, the connection is made
09:18Now you can see the link has the same color as the connection points
09:22Now, if you look at these two points, they may look similar, but in fact, one is yellow and the other is orange
09:29Additionally, their names are clip and positive
09:32Therefore, you cannot make a connection between them
09:35These two different types of points
09:37If you want an idea of what node you can place there, you can drag and release the mouse somewhere on the canvas
09:44A menu will appear where you can add or search for a node
09:48Uh, the menu also suggests nodes that you can select
09:51For example, if I select the, the clip text and code node, it creates that node and connects it in one move
09:59When you delete that node, um, the connection is also deleted
10:01So the easiest way is to drag and release to get one of the suggested nodes or search for a node
10:09With a little practice, you'll learn which nodes connect with each other
10:13For example, with latent, I can get a VAE decode node, then from the VAE decode node, I can connect the pink output with the VAE from load checkpoint, and so on
10:24As You can see, um, you cannot connect nodes of other colors
10:26To unlink or disconnect a link from a node, you simply click on the connection point and drag it away somewhere on the canvas
10:36When you release the mouse, the link will be disconnected
10:38You can also delete, uh, a link by left-clicking on the little circle that appears on the link, then choosing delete
10:44You can also right-click on a node and go to Colors, uh, where you can pick different colors to differentiate nodes that are more important
10:55Additionally, when you right-click, you can change the title of the node, for example, you can rename it, um, to exactly describe what it does
11:03You can also change, uh, the shape of the node to box, round, or card, um, a combination of both, or you can leave it
11:13at the default shape
11:16Additionally, you can use the resize option to, um, automatically adjust the node to a smaller form
11:21Let's clear the workflow and start our text-to-image workflow for Stable Diffusion from scratch
11:28First, let's start by loading our model
11:30We'll use the load checkpoint node for this task, and this node is straightforward
11:34It loads the pre-trained model, uh, the checkpoint that we'll be using
11:39In our case, we're using a model called Juggernaut X
11:41You'll notice that this node has three outputs: model, clip, and VAE
11:46These outputs will be useful shortly
11:48Next, I'll add the K sampler node
11:51This node begins with random noise and gradually turns it into, um, a clear image by following specific instructions and settings
11:59as the number of steps and how strongly the instructions guide the process
12:04This helps create a final, high-quality image
12:07I will create a link between these two nodes, connecting the output from the model, um, output of the low checkpoint node to the model input of the K sampler node
12:17You see here, we have a clip output
12:20Clip stands for Contrastive Language-Image Pre-training, uh, which is a machine learning model that can interpret both images and their descriptions in natural language
12:29It effectively bridges the gap between visual and textual data
12:34To make an analogy for what clip does, it's like having a bilingual person who can understand both English and images
12:41When they see an image, they form a mental summary
12:45When they read a Description, they also form a summary, they can then compare these summaries to see if they match
12:53So if I drag and release, you can see in the suggested nodes, the clip text encode option
12:58If I select that, I now get the clip text encode prompt where we can input our text prompt
13:03Now, we need both a positive prompt and a negative prompt
13:07I can either hold down Alt and drag a copy of the clip text encode node, or I can search for the node labeled prompt and add it
13:14So now that we have both nodes, I will connect them to the load checkpoint node as well
13:19You might wonder how the system distinguishes between, um, the positive and negative prompts when both nodes look the same
13:27In the case sampler node, we have two inputs, one for positive prompt and another for negative prompt by connecting each respective node to these inputs, the system understands which prompt is positive and which is negative
13:40Um, to quickly distinguish between nodes, many people assign colors to them
13:44For example, uh, we can color the, uh, positive prompt node in green and the negative prompt node in red
13:51I will quickly add a positive prompt and a negative prompt so we can test them later when the workflow is ready
13:58Now, each checkpoint has some recommended settings that we can use in the K sampler, as you saw in the first episode when we got our settings from Civit AI, where I downloaded this model
14:09I will add those settings here
14:13So we have another input here called latent image
14:16If we drag and release, we can see options like VAE encode or empty latent image
14:22It took me a while to understand this, but everything that happens in the K sampler node revolves around the latent space
14:30Latent space represents hidden features of data in a simplified, abstract form, making it easier for models to process
14:37Everything that enters this space must be latent
14:40If it's pixel data, we need to encode it first to convert it into this simplified form
14:44So, if I have a photo made from pixels, I cannot input it directly into the K sampler
14:51We need to use VAE encode first
14:54We'll explore this process in another episode to create an image-to-image workflow
14:59However, for text-to-image, we need an empty latent image, even when using text to generate an image, the system still requires a placeholder image to work with and add noise on top to perform its task effectively
15:11As you can see, we have width and height options here
15:16Since we are using an SDXL model, we can create a larger image, such as a 1024 pixel image
15:22So, basically, most of the workflow is complete
15:25We have the model, the prompts, and, um, everything entering the K sampler, uh, including the empty image that allows us to choose the size
15:37Um, theoretically, the image exists in the latent space
15:39Um, we just need to extract it to view it
15:43Remember I mentioned that everything going into and out from the latent space must be either latent or converted to get pixels? Since we want to visualize the pixels, we use the load VAE decode node to extract the image
15:57from the latent space
16:00A VAE (Variational Autoencoder) decode node is a component in machine learning models, especially in image processing, that transforms latent space representations back into their original visible form
16:16Think of it like compressing and decompressing a file
16:18The VAE encode node compresses the image into a compact form, the latent space, and the VAE decode node decompresses it back to the original image
16:32Now, I know from the model description that Juggernaut has VAE baked in, so I can simply connect the VAE from the decoder to the VAE from the load checkpoint node
16:44But if you're using another model that requires a separate VAE file, you'll need to search for a node called load VAE first, download the VAE and place it into your model folder, then into the VAE folder
17:00After refreshing, select the model from the list and connect it to the VAE decode
17:04In my case, I don't need this step, so I'll just connect it back to the model
17:10Now, the final pixel image is here
17:12We just need to save it
17:15We could use a preview node if we want to preview the image first, um, and then save it with a right-click
17:22However, what I prefer to do is use a save image node
17:24Now, that way, everything I generate is saved, and I can delete what I don't need later from the output folder
17:29And that's it
17:33Um, let's test it to see if it works by clicking on Q prompt
17:38Um, you'll notice each node gets a green outline when the flow is active in that area, which is a good sign
17:44Um, at the end, we'll have our Generated image all from a workflow created from scratch
17:50Now, you might ask, why does it need so many components to make a simple image? I might ask you back, why do you need so many Lego pieces to build a castle? Consider a, a real-life example, a desktop PC
18:04You have the unit itself, um, then you connect the power cable to the socket, connect the internet cable, um, to the router, which is connected to other cables, um, and you also connect the, the mouse, monitor, and maybe a printer
18:16All these components are, are necessary for everything to function properly
18:21It's the same concept here
18:22If you want control over the workflow, you need more components to build exactly what you want
18:28I was curious about what's inside this latent image node, so I tried Adding a preview image node
18:35However, as you can see, we cannot connect them directly because the latent image is not pixel-based
18:43Remember, we need to decode it first
18:46So, I will use the VAE decode node, and, uh, now I can connect the image to the preview image node
18:53As you can see, I intentionally left the VAE input disconnected so you could observe what happens when I run this workflow
19:03When I cue the prompt, you'll notice the other nodes turn green, but this one remains red with a little circle around the VAE input, indicating this branch, uh, was, uh, interrupted here
19:16And to fix it, we simply, uh, connect the VAE to VAE and try again
19:23This is how the latent image looks
19:29You know, if I right-click on it, I can, um, open the image in a new tab, and it appears as a gray with subtle purple hues, um, matching the size we defined in width and height
19:35You can do the same for the generated image
19:38With a right-click, you can open, save, or copy the image
19:40I'll, I'll delete this part since, you know, we've seen what's there and, um, it's not particularly exciting
19:49Let's change the width and height to generate a landscape ratio image
19:54I'll adjust the values accordingly and also create a portrait ratio image
20:00Remember to keep it around 1024 pixels
20:03Larger images can capture more details, but if they're too big, you might encounter issues like duplicate heads or slower processing speed
20:13When you're constructing a complex workflow, you might find it useful to visualize how all the nodes are connected
20:19In such cases, a node called reroot can be very handy
20:25Think of a reroot node like a cable organizer for your computer desk
20:29Instead of having all your cables tangled and messy, the cable organizer, reroot node, helps you manage and direct each cable neatly to its destination
20:38After completing the workflow, you can arrange it to fit better on your screen and make it more comfortable for you
20:42For example, if you're used to interfaces like Automatic 1111 or Forge, you can organize it similarly, um, if that's more convenient for you
20:53In Forge, um, we have the stable diffusion checkpoint, which is equivalent to the load checkpoint node in ComfyUI
21:01Similarly, we have the positive and negative prompt nodes, which we can also arrange under the checkpoint if we prefer and resize them accordingly
21:11Then we have, um, the sampling method, steps, CFG settings, as well as the width and height parameters, all of which are, uh, also present in ComfyUI within the case sampler node
21:23Uh, additionally, there's the empty latent image node for setting the width and height
21:28Let's remove these reroute nodes and concentrate on the VAE code
21:32We can collapse the nodes we don't adjust settings for
21:36I'll place it on top to mimic the layout in Forge and position the save image node on the right, similar to how the preview is arranged in Forge
21:48If you don't like how the cables look in the background, you can go to settings and choose a different link render mode, such as straight, uh, then close the settings
21:55Next, I'll go to the manager and click restart
21:59After the restart, the links are now straight
22:02I'll try moving a node to see if the link stays straight
22:04You can also group nodes together
22:06Right-click on the canvas and select "Add Group." I suggest resizing the group before moving it close to the nodes
22:13Any node that touches or is within the group area will stick to that group, like a super strong magnet that pulls in any node it gets close to, creating, uh, an organized bundle
22:28Then I can arrange the items within that group as I like
22:30Uh, I can also rename the group
22:33Now I can move all items at once just by selecting the group instead of individual nodes
22:38After playing around with it for a while, I managed to make it look like this
22:43Now it almost resembles A regular interface and doesn't look so intimidating anymore, right? To change the links back to the default style, go to settings, choose spline, then close from the manager
22:58Restart, start the interface, and voila, we have spaghetti links again
23:02Now, there are custom nodes that can combine multiple nodes into one to make the interface even clearer, but that's for another episode
23:11I hope you enjoyed this video
23:13Please leave a like and a comment to support my channel
23:17Thank you, and see you soon with a new episode
23:24[Music]