Image Generation Mechanics, Conditioning and Consistency
You can size a latent grid from pixel width and height, recompute one denoising step and one guidance mix by hand, price a batch from steps and denoiser calls, and allow or refuse a reference image with a three-line license check.
- Level
- Navigator
- Time
- 20 h

Jump to
After this course you can
The student can configure deterministic diffusion workflow graphs (ComfyUI JSON), calculate exact VRAM and per-image generation costs, and output image batches matching strict resolution, seed, and metadata constraints.
The latent grid and one denoising step
This lesson's encoder shrinks each side of the picture by 8 and stores 4 numbers at every latent cell. The denoiser then halves that grid three times, so each latent side has to be divisible by 8. Together that means each pixel side has to be divisible by 64, because 8 times 8 is 64. A 512 by 512 picture passes: 512 / 8 = 64, and 64 times 64 times 4 = 16384 latent numbers. A 768 by 512 picture passes too: 768 / 8 = 96, and 96 times 64 times 4 = 24576 numbers. A 1024 by 1024 picture holds 128 times 128 times 4 = 65536 numbers, four times the 512 grid, since each side doubled. A 500 by 500 request fails the rule, because 500 / 64 = 7.8125. The nearest sizes that pass are 448 and 512. The 448 grid has 56 times 56 times 4 = 12544 numbers.
One of those numbers is updated by a short formula you can run by hand. At a noise level where the stored bar-alpha is 0.64, the square root is 0.8 and the square root of 1 minus 0.64 is 0.6. A clean value 2.0 mixed with noise 1.0 becomes 0.8 times 2.0 plus 0.6 times 1.0, which is 1.6 + 0.6 = 2.2. That 2.2 is the noisy value. When the denoiser predicts the noise as 1.0, the reconstructed clean value is (2.2 minus 0.6 times 1.0) divided by 0.8, which is 1.6 / 0.8 = 2.0. This lesson's one-number move then closes a fraction 0.25 of the gap: 2.2 plus 0.25 times (2.0 minus 2.2) = 2.2 minus 0.05 = 2.15. A full sampler picks that fraction from a noise schedule and may add a fresh noise term. The hand check stays this reconstruction and this one move. The checkpoint on the memory sheet has 1.5 billion parameters at 2 bytes each. With 1 GB defined as 1,000,000,000 bytes, the weights occupy 3.00 GB. The sheet then charges 50,000 bytes of activation storage per latent number. The 512 grid costs 16384 times 50,000 = 819,200,000 bytes, or 0.8192 GB, so the working set is 3.00 + 0.8192 = 3.8192 GB. The 768 by 512 grid costs 24576 times 50,000 = 1,228,800,000 bytes, or 1.2288 GB, and the working set is 4.2288 GB. The 1024 grid costs four times 0.8192 GB of activations, 3.2768 GB, and the working set is 6.2768 GB.
Guidance scale and the call count
Classifier-free guidance mixes two noise predictions from the same denoiser. One prediction sees the prompt. The other sees an empty prompt. With unconditional score 0.20, conditional score 0.80, and guidance s, the guided score is 0.20 plus s times (0.80 minus 0.20). The gap is 0.60. At s = 7 the guided score is 0.20 + 7 times 0.60 = 0.20 + 4.20 = 4.40. At s = 5 it is 0.20 + 5 times 0.60 = 3.20. At s = 1 it is 0.20 + 0.60 = 0.80, the conditional score itself, because the unconditional score is multiplied by zero in the expanded form s times conditional plus (1 minus s) times unconditional.
This lesson's pipeline spends one denoiser call on a step when s is 1, and two calls when s is anything else: one empty-prompt call and one prompted call. The sampler still makes one move per step. Twenty steps at guidance 7 therefore spend 2 times 20 = 40 calls. Twenty steps at guidance 1 spend 20 calls. Thirty steps at guidance 5 spend 2 times 30 = 60 calls. The price sheet charges 0.0008 dollars per denoiser call, and the activation memory above stays the same whatever the step count is, because the weights and the latent size occupy the card for the whole run.
Inpainting and outpainting on the grid
Inpainting repaints the pixels inside a mask and leaves the other pixels in place. The mask edges in this lesson sit on multiples of 64, so every masked block covers whole latent cells after the divide-by-8. A 128 by 128 mask on a 512 by 512 canvas covers 16384 pixels of 262144, and 262144 / 16384 = 16, so the painted share is 1/16. The latent mask is 16 by 16 = 256 cells out of 64 by 64 = 4096 cells, and 4096 / 256 = 16, the same share. A mask width of 100 fails the grid: 100 / 8 = 12.5, so the edge would cut through latent cells.
Outpainting keeps the original picture and fills a new strip. Growing 512 by 512 on the right until the canvas is 768 by 512 adds a strip of 256 by 512 = 131072 pixels. The new canvas holds 768 times 512 = 393216 pixels, and 131072 times 3 = 393216, so the new strip is 1/3 of the canvas. On the latent grid the added strip is 32 by 64 = 2048 cells out of 96 by 64 = 6144, and 2048 times 3 = 6144, again 1/3. The record stores both widths, 512 and 768, so a later check can recompute that share. The working set follows the new grid, 4.2288 GB for 768 by 512, from the sheet in the first section.
Seed, price, reference weight, and license
The seed starts the noise field. Euler in this lesson draws no extra noise after a move. Euler ancestral draws one extra noise value per step from the generator that the seed started. On a deterministic build, either sampler repeats when the seed, the prompt, the step count, the guidance, the width, the height, and the sampler name stay unchanged. Changing the seed from 17 to 18 changes the noise field. Changing only the step count also changes the picture, because the schedule has a different length, and the call count changes with it. A shared seed repeats the noise when the prompt and the other settings match. A character stays in place when the same reference image and the same reference weight enter every frame. The mix is (1 minus r) times the text vector plus r times the image vector. With text [0.80, 0.20], image [0.00, 1.00], and r = 0.25, the mix is 0.75 times [0.80, 0.20] plus 0.25 times [0.00, 1.00] = [0.60, 0.15] plus [0.00, 0.25] = [0.60, 0.40].
Three license lines all have to pass before that reference file enters the run. You hold the copyright, or the license allows adaptations. The license allows this use, so a non-commercial license fails a commercial job. The record stores the source, the license name, and the file hash. A missing hash fails the third line. The words no derivatives fail the first line. A photo you took can be entered as license name own when the job is commercial and the hash is stored. Ten frames at the twenty-step price, guidance 7, cost 10 times 0.032 = 0.320 dollars. Each frame keeps seed 17, Euler, 512 by 512, and r = 0.25 on a photo you took, and only a short phrase at the end of the prompt changes, so the reference keeps its 0.25 share while the text part of the mix moves with the new phrase. Forty calls times 0.0008 = 0.032 dollars for one of those frames. Thirty steps at guidance 5 cost 60 times 0.0008 = 0.048 dollars per image, and a batch of 8 costs 8 times 0.048 = 0.384 dollars.
One commercial batch, from grid to provenance
The job asks for 8 images, 768 by 512, Euler, 30 steps, guidance 5, seed 42, on the checkpoint from the memory sheet. Both sides divide by 64. Latent width 96, latent height 64, and 96 times 64 times 4 = 24576 numbers. Activations are 1.2288 GB and the working set is 3.00 + 1.2288 = 4.2288 GB. Take one latent number at bar-alpha 0.64. Clean value 2.0 and noise 1.0 produce the noisy value 2.2. The denoiser predicts noise 1.0, the reconstruction is 2.0, and the one-number move with fraction 0.25 lands on 2.15. That check covers a single number. The other 24575 numbers follow the same schedule inside the software.
Unconditional score 0.20 and conditional score 0.80 at guidance 5 give 0.20 + 5 times 0.60 = 3.20. Guidance is above 1, so each step spends 2 calls. Thirty steps spend 60 calls. At 0.0008 dollars per call the image costs 0.048 dollars, and the batch of 8 costs 0.384 dollars. The sampler name on the record is euler, so this run adds no extra noise draw after the move. A second run with the same prompt, seed 42, 30 steps, guidance 5, and 768 by 512 repeats on a deterministic build. Seed 43 with every other field unchanged changes the noise field.
The offered reference carries a non-commercial license, and the job is commercial, so line 2 of the license check fails. The file stays out, the reference weight is stored as 0, and the license field reads refused. Swap in a photo you took, with source, license name own, and hash all stored. Line 1, line 2, and line 3 pass. At reference weight 0.25 the mix of [0.80, 0.20] and [0.00, 1.00] is [0.60, 0.40] on every image in the batch. If this 768-wide canvas is an outpaint of a 512-wide original, the added strip is 131072 pixels of 393216, which is 1/3.
The provenance line you write before launching is seed 42, steps 30, cfg 5, sampler euler, width 768, height 512, calls 60, cost 0.048, working_gb 4.2288, reference_license refused, deterministic true. For the own-photo variant, reference_license becomes own and reference_weight becomes 0.25, and the call count and the 0.384 dollar batch price stay put because the reference mix uses the conditioning vector inside calls you already counted.
Price a 16:9 batch on paper
A commercial batch of 4 uses 1024 by 576, Euler, 25 steps, guidance 4, and seed 7, on the same checkpoint and the same 0.0008 dollar call price. The unconditional score is 0.10 and the conditional score is 0.50. A 256 by 256 mask sits in the corner on multiples of 64. The reference is a public-domain dedication, and the record already holds source, license name, and file hash. The reference weight is 0.50, the text vector is [0.80, 0.20], and the image vector is [0.00, 1.00]. Compute the latent count, the working GB, the guided score, the calls per image, the batch cost, the painted share, and the mixed vector. Then say what the picture and the call count do if the step count becomes 26 while seed 7 stays. Last, mark a second file whose license text says no derivatives.
1024 / 8 = 128 and 576 / 8 = 72, so the latent count is 128 times 72 times 4 = 36864. Activations are 36864 times 50,000 = 1,843,200,000 bytes = 1.8432 GB, and the working set is 4.8432 GB. The score gap is 0.40, so the guided score is 0.10 + 4 times 0.40 = 1.70. Calls per image are 2 times 25 = 50, the image costs 0.040 dollars, and the batch costs 0.160 dollars. The mask covers 65536 pixels of 589824, and 65536 times 9 = 589824, so the share is 1/9. The latent mask is 32 by 32 = 1024 cells out of 128 times 72 = 9216, also 1/9. The mix is 0.50 times [0.80, 0.20] plus 0.50 times [0.00, 1.00] = [0.40, 0.60]. All three license lines pass for the public-domain file. At 26 steps the schedule length changes, so the picture changes, the calls become 2 times 26 = 52, and one image costs 0.0416 dollars. The file marked no derivatives fails line 1 and stays out of the run.
Check questions
How many latent numbers does 768 by 512 hold under this lesson's grid, and what working set in GB does the sheet give for that grid on the 1.5-billion-parameter checkpoint?
24576 latent numbers, and 4.2288 GB. Weights are 3.00 GB and activations are 1.2288 GB.
Unconditional score 0.20, conditional score 0.80, guidance 5. What guided score does the mix give, and how many denoiser calls do 30 steps spend?
The guided score is 3.20. Guidance above 1 spends two calls per step, so 30 steps spend 60 calls.
What share of a 512 by 512 canvas is a 128 by 128 mask aligned to the grid, and what share of the latent cells is the matching mask?
Both shares are 1/16. The mask is 16384 pixels of 262144, and 256 latent cells of 4096.
At 0.0008 dollars per call, what does a batch of 8 cost at 30 steps and guidance 5, and what does the license check do with a non-commercial reference on that commercial job?
The batch costs 0.384 dollars, from 60 calls and 0.048 dollars each. Line 2 refuses the reference, so the file stays out.
Fill the record before the first picture: pixel sides divisible by 64, latent count, working GB, guided score, call count, batch price, and a license mark of allowed or refused. The seed fixes the noise on a deterministic build, and a fixed reference weight is what keeps a character across frames.
Final task
Pass a 25-item keyed benchmark on diffusion parameters, VRAM math, and licensing rules, and submit a workflow JSON + batch post-processing script that passes automated checks on dimensions, color profiles, and provenance metadata. (Optional Portfolio item: 10-frame visual storyboard).
Terms in this course
This course has no terms of its own in the glossary yet. Terms from earlier courses are used here too.
The first lesson is open to read. The rest of the course is being written, and tests and diplomas come later. Join the waitlist