// Project one task gradient away from a conflicting task gradient. Output the projected gradient and original row dot product. use graph_io; pub fn fd_gradient_conflict(rows: i64, width: i64) { println!("module {"); fd_line(" func.func @main(%first: tensor, %second: tensor) -> (tensor, tensor) {", rows, width); fd_line(" %v0 = stablehlo.constant dense<0.00000000000000000e+00> : tensor", rows, width); fd_line(" %v1 = stablehlo.multiply %first, %second : tensor", rows, width); println!(" %v2 = stablehlo.constant dense<0.00000000000000000e+00> : tensor"); fd_line(" %v3 = stablehlo.reduce(%v1 init: %v2) applies stablehlo.add across dimensions = [1] : (tensor, tensor) -> tensor", rows, width); fd_line(" %v4 = stablehlo.broadcast_in_dim %v3, dims = [0] : (tensor) -> tensor", rows, width); // dot = rsum(first*second) fd_line(" %v5 = stablehlo.multiply %second, %second : tensor", rows, width); fd_line(" %v6 = stablehlo.reduce(%v5 init: %v2) 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); // sq = rsum(second*second) fd_line(" %v8 = stablehlo.minimum %v4, %v0 : tensor", rows, width); fd_line(" %v9 = stablehlo.multiply %v8, %second : tensor", rows, width); fd_line(" %v10 = stablehlo.constant dense<9.99999999999999945e-21> : tensor", rows, width); fd_line(" %v11 = stablehlo.maximum %v7, %v10 : tensor", rows, width); fd_line(" %v12 = stablehlo.divide %v9, %v11 : tensor", rows, width); fd_line(" %v13 = stablehlo.subtract %first, %v12 : tensor", rows, width); // projected = first-minimum(dot,0)*second/maximum(sq,1e-20) fd_line(" return %v13, %v4 : tensor, tensor", rows, width); println!(" }"); println!("}"); }