How does text guide Stable Diffusion via U-Net cross-attention?
Tests whether you know text embeddings condition the U-Net through cross-attention. Good answers explain that image features query text keys and values at every layer. Red flag: claiming the prompt is concatenated to the image latent.
What's really being asked
This question probes whether you understand the architecture of latent diffusion models at a component level, specifically how a text modality conditions a generative image model. Interviewers care if you can distinguish the roles of the text encoder, the VAE, and the U-Net, and whether you grasp the attention mechanism that actually binds words to pixels. Senior candidates should explain cross-attention without hand-waving.
The full answer
First, the prompt is tokenized and passed through a frozen text encoder such as CLIP to produce a sequence of text embeddings, typically 77 tokens by 768 or 1024 dimensions. Second, these embeddings are injected into the U-Net denoiser via cross-attention layers that are interleaved with the standard convolutional and self-attention blocks. Third, in each cross-attention layer, the Query matrix is derived from the flattened intermediate image latent features, while the Key and Value matrices are derived from the text embeddings. Fourth, the attention scores map spatial image regions to semantic text tokens, allowing the denoising process to strengthen or suppress visual features based on the prompt. Fifth, this happens at multiple resolutions across the U-Net down-blocks, mid-block, and up-blocks, ensuring both global composition and local detail are guided.
The mistakes people make
Claiming the text vector is concatenated to the image latent or noise vector before entering the U-Net. Describing cross-attention but getting the Q and K/V sources backwards. Calling it self-attention instead of cross-attention. Forgetting that the process operates in latent space rather than pixel space. Saying the text encoder is fine-tuned with the U-Net when in many Stable Diffusion variants it is frozen.
What usually comes next
How does classifier-free guidance modify this cross-attention pathway? What happens if you manipulate the cross-attention maps during inference, such as in prompt-to-prompt editing? Why is the text encoder kept frozen rather than trained end-to-end? How does the model handle multiple prompts or negative prompts?
A concrete example
Consider the prompt a red cube on top of a blue sphere. In the U-Net cross-attention layers, the spatial region corresponding to the upper center of the image will show high attention scores to the tokens red and cube, while the lower region will attend strongly to blue and sphere. If you were to visualize these attention maps, you would see that the model disentangles the two objects by routing different spatial queries to different text keys, which is why it can respect both color and positional adjectives simultaneously.
Interview question
When denoising in Stable Diffusion, how do text embeddings primarily influence the U-Net's intermediate feature maps?
- a.Text and image tokens attend to each other through shared self-attention in the U-Net's bottleneck
- b.Image features act as Query while text embeddings provide Key and Value in cross-attention layers throughout the U-NetCorrect
- c.The text encoder is fine-tuned to output embeddings that replace the initial latent noise input
- d.Text vectors are concatenated to the latent noise before entering the first U-Net block
Why? this is the answer
Text embeddings condition the U-Net through cross-attention layers where image-derived Queries attend to text-derived Keys and Values at multiple resolutions, not just at the input or bottleneck. Option D reflects the common misconception that text is concatenated to the latent noise, while option A incorrectly describes the mechanism as self-attention.
Just read this? Test yourself on what you have been reading.
Read the original → huggingface.co
- #diffusion models
- #stable diffusion
- #cross-attention
- #generative ai
- #multimodal
You just looked this up. Could you explain it out loud?
That is the part interviews actually test. Tezvyn takes questions like this one and gives you what the interviewer is really checking, the answer that lands, and the mistake that ends the conversation, in the four minutes before your next meeting.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Every open role lists the topics its interview covers, so you can prepare for the real thing rather than guessing.
See open roles