M6-078M6: Multimodal & Generative ModelsFlow Matching & Rectified FlowHard
⚡Flashcard Drill➔Mastery:

Classifier-Free Guidance Formulation and Implementation in Flow Matching

🎯 Active Recall Self-Check (Draft First, Verify After)
Login-free practice tracker: recall core answer, audit pitfalls, and log review status.
Step 1 · Draft your concise answer & assumptions
Step 2 · Check Pitfalls & Follow-up Inquiries
Next: M6-079 →
📐 Mathematical Definition
vCFG=vθ(xt,∅)+s(vθ(xt,c)−vθ(xt,∅))v_{\text{CFG}}=v_\theta(x_t,\varnothing)+s\left(v_\theta(x_t,c)-v_\theta(x_t,\varnothing)\right)
⚡ One-Sentence Core Answer
Classifier-Free Guidance in Flow Matching extrapolates between conditional and unconditional vector fields, steering probability transport velocity toward prompt conditions without modifying straight ODE integration.

📌 Key Takeaways

  • •
    Velocity extrapolation formula: calculates guided velocity field as  v^t=vθ(xt,t,∅)+s⋅(vθ(xt,t,c)−vθ(xt,t,∅)) \,\hat{v}_t = v_\theta(x_t, t, \emptyset) + s \cdot \big( v_\theta(x_t, t, c) - v_\theta(x_t, t, \emptyset) \big)\,, amplifying prompt adherence
  • •
    Integration compatibility: guided velocity  v^t \,\hat{v}_t\, integrates directly into standard numerical ODE solvers (Euler, Midpoint) without altering integration mechanics
  • •
    Guidance scale dynamics: Flow Matching operates effectively at lower guidance scales (s=3.0–4.5s=3.0\text{--}4.5) than traditional diffusion (s=7.5–9.0s=7.5\text{--}9.0) due to superior condition alignment

📐 Mathematical Derivations

Mathematical Mechanism: 1. Flow Matching Guidance Extrapolation: Let vθ(xt,t,c)v_\theta(x_t, t, c) be the velocity predicted conditioned on prompt cc, and vθ(xt,t,∅)v_\theta(x_t, t, \emptyset) be the unconditional velocity (conditioned on null prompt ∅\emptyset). The guided vector field with guidance scale s≥1.0s \ge 1.0 is: v^θ(xt,t,c)=vθ(xt,t,∅)+s⋅(vθ(xt,t,c)−vθ(xt,t,∅))=(1−s)vθ(xt,t,∅)+svθ(xt,t,c)\hat{v}_\theta(x_t, t, c) = v_\theta(x_t, t, \emptyset) + s \cdot \Big( v_\theta(x_t, t, c) - v_\theta(x_t, t, \emptyset) \Big) = (1 - s) v_\theta(x_t, t, \emptyset) + s v_\theta(x_t, t, c) When s=1.0s = 1.0, the update reduces to standard conditional transport. When s>1.0s > 1.0, the difference vector Δv=v(c)−v(∅)\Delta v = v(c) - v(\emptyset) amplifies velocity components that point toward conditional density modes while canceling out generic unconditional background drift. 2. Guided Probability Flow ODE Integration: The guided trajectory evolves according to the modified initial value problem: dxtdt=v^θ(xt,t,c),x0∼N(0,I)\frac{dx_t}{dt} = \hat{v}_\theta(x_t, t, c), \quad x_0 \sim \mathcal{N}(0, I) Under a 1st-order Euler discretization step from tnt_n to tn+1t_{n+1} with step size hh: xn+1=xn+h⋅[(1−s)vθ(xn,tn,∅)+svθ(xn,tn,c)]x_{n+1} = x_n + h \cdot \Big[ (1 - s) v_\theta(x_n, t_n, \emptyset) + s v_\theta(x_n, t_n, c) \Big] 3. Dual-Stream Batched Execution: Conditional and unconditional inputs are processed in a unified 2B2B batch through the Flow Matching Transformer: Xbatch=[xt;xt],Cbatch=[c;∅],Tbatch=[t;t]X_{\text{batch}} = [x_t ; x_t], \quad C_{\text{batch}} = [c ; \emptyset], \quad T_{\text{batch}} = [t ; t] Forward pass outputs Vbatch=[vcond;vuncond]V_{\text{batch}} = [v_{\text{cond}} ; v_{\text{uncond}}]. The guided vector v^=vuncond+s(vcond−vuncond)\hat{v} = v_{\text{uncond}} + s (v_{\text{cond}} - v_{\text{uncond}}) is passed directly to the ODE integrator.

🏭 Production Trade-offs

Deep Dive & Engineering Trade-offs: ① Lower Guidance Scale Requirements in Flow Matching: Traditional diffusion models (SD 1.5) required high guidance scales (s=7.5–9.0s=7.5\text{--}9.0) because curved Brownian paths easily drifted away from prompt conditions. Modern Flow Matching foundation models (SD3, Flux.1) enforce straight transport paths and leverage massive text encoders (T5-XXL, CLIP-G). Consequently, they achieve crisp prompt alignment at much lower guidance scales (s=3.0–4.5s=3.0\text{--}4.5). Operating at lower scale prevents the harsh color saturation and high-frequency edge burning that plagued early diffusion models. ② Negative Prompting in Flow Matching: Substituting negative text prompt cnegc_{\text{neg}} in place of the empty condition ∅\emptyset: v^=v(cneg)+s(v(c)−v(cneg))\hat{v} = v(c_{\text{neg}}) + s(v(c) - v(c_{\text{neg}})). The vector difference pushes velocity directly away from the negative semantic direction. ③ Guidance Distillation in Flux.1-Schnell: Guidance distillation trains a student model on paired inputs (xt,t,c,s)(x_t, t, c, s) to predict the guided velocity v^\hat{v} directly in a single forward pass, eliminating the unconditional branch entirely. This cuts serving latency by 50% while operating with 4-step Euler sampling. ⑤ Interview Strategy: Formulate the guided velocity equation v^=v(∅)+s(v(c)−v(∅))\hat{v} = v(\emptyset) + s(v(c) - v(\emptyset)), show how it integrates into the Euler ODE update, explain why Flow Matching models operate at lower guidance scales, and describe negative prompting and guidance distillation.
⚠️ Common Interview Pitfalls
  • ✕
    Using legacy diffusion guidance scales (s=8.0–12.0s=8.0\text{--}12.0) on Flow Matching models, causing severe over-saturation and visual blowouts
  • ✕
    Assuming CFG changes the mathematical ODE solver in Flow Matching; CFG modifies only the evaluated vector field v^t\hat{v}_t
  • ✕
    Running conditional and unconditional passes as separate sequential operations instead of batched 2B2B execution
🎯 Interviewer Follow-up Inquiries
  • ?
    Why do modern Flow Matching architectures achieve superior prompt adherence at lower guidance scales (s=3.5s=3.5) than traditional diffusion models (s=8.0s=8.0)?
  • ?
    How does Guidance Distillation eliminate the unconditional forward pass in real-time Flow Matching models like Flux.1-Schnell?
⚡
Test muscle memory on this topic via 3-Layer Flashcards
Active Recall: Mentally formulate Prompt ➔ Math Derivation ➔ Benchmark Implementation in 3 minutes.
🎯 Drill This Card Now➔
📚

Associated Knowledge Base Guides & Mindmaps

← PreviousM6-077: Architectural Variants of Diffusion Transformers: MMDiT Dual-Stream vs U-DiT Hierarchical📋 Back to BankNext →M6-079: ControlNet Architectural Mechanics: Zero Convolutions and Trainable Encoders