// Route feed-forward activations through a ReLU gate. At a zero gate choose the zero subgradient. use graph_io; pub fn fd_reglu_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.maximum %gate, %v0 : tensor", rows, width); // a = maximum(gate,0) fd_line(" %v2 = stablehlo.multiply %x, %v1 : tensor", rows, width); // y = x*a fd_line(" %v3 = stablehlo.multiply %upstream, %v1 : tensor", rows, width); // dx = upstream*a fd_line(" %v4 = stablehlo.compare GT, %gate, %v0, FLOAT : (tensor, tensor) -> tensor", rows, width); fd_line(" %v5 = stablehlo.multiply %upstream, %x : tensor", rows, width); fd_line(" %v6 = stablehlo.select %v4, %v5, %v0 : tensor, tensor", rows, width); // dg = choose(gate>0,upstream*x,0) fd_line(" return %v2, %v3, %v6 : tensor, tensor, tensor", rows, width); println!(" }"); println!("}"); }