// Apply a sigmoid gate and return both activation and gate gradients for a gated linear unit. use graph_io; pub fn fd_glu_backward(rows: i64, width: i64) { println!("module {"); fd_line(" func.func @main(%x: tensor, %gate: tensor, %upstream: tensor) -> (tensor, tensor, tensor) {", rows, width); fd_line(" %v0 = stablehlo.constant dense<0.00000000000000000e+00> : tensor", rows, width); fd_line(" %v1 = stablehlo.logistic %gate : tensor", rows, width); // p = sig(gate) fd_line(" %v2 = stablehlo.multiply %x, %v1 : tensor", rows, width); // y = x*p fd_line(" %v3 = stablehlo.multiply %upstream, %v1 : tensor", rows, width); // dx = upstream*p fd_line(" %v4 = stablehlo.multiply %upstream, %x : tensor", rows, width); fd_line(" %v5 = stablehlo.multiply %v4, %v1 : tensor", rows, width); fd_line(" %v6 = stablehlo.constant dense<1.00000000000000000e+00> : tensor", rows, width); fd_line(" %v7 = stablehlo.subtract %v6, %v1 : tensor", rows, width); fd_line(" %v8 = stablehlo.multiply %v5, %v7 : tensor", rows, width); // dg = upstream*x*p*(1-p) fd_line(" return %v2, %v3, %v8 : tensor, tensor, tensor", rows, width); println!(" }"); println!("}"); }