// Apply classifier-free guidance and report the RMS size of the conditional correction relative to the unconditional prediction. use graph_io; pub fn fd_guidance_mix(rows: i64, width: i64) { println!("module {"); fd_line(" func.func @main(%conditional: tensor, %unconditional: tensor, %strength: tensor) -> (tensor, tensor) {", rows, width); fd_line(" %v0 = stablehlo.constant dense<0.00000000000000000e+00> : tensor", rows, width); fd_line(" %v1 = stablehlo.subtract %conditional, %unconditional : tensor", rows, width); // delta = conditional-unconditional fd_line(" %v2 = stablehlo.multiply %strength, %v1 : tensor", rows, width); fd_line(" %v3 = stablehlo.add %unconditional, %v2 : tensor", rows, width); // guided = unconditional+strength*delta fd_line(" %v4 = stablehlo.multiply %v1, %v1 : tensor", rows, width); println!(" %v5 = stablehlo.constant dense<0.00000000000000000e+00> : tensor"); fd_line(" %v6 = stablehlo.reduce(%v4 init: %v5) applies stablehlo.add across dimensions = [1] : (tensor, tensor) -> tensor", rows, width); fd_line(" %v7 = stablehlo.broadcast_in_dim %v6, dims = [0] : (tensor) -> tensor", rows, width); fd_line(" %v8 = stablehlo.constant dense : tensor", rows, width); fd_line(" %v9 = stablehlo.divide %v7, %v8 : tensor", rows, width); fd_line(" %v10 = stablehlo.sqrt %v9 : tensor", rows, width); // rms = sqrt(mean(delta*delta)) fd_line(" return %v3, %v10 : tensor, tensor", rows, width); println!(" }"); println!("}"); }