// Rotate even and odd feature pairs with supplied sine and cosine tables and backpropagate to the input pair. use graph_io; pub fn fd_rope_pairs(rows: i64, width: i64) { println!("module {"); fd_line(" func.func @main(%even: tensor, %odd: tensor, %cosine: tensor, %sine: tensor, %grad_even: tensor, %grad_odd: tensor) -> (tensor, tensor, tensor, tensor) {", rows, width); fd_line(" %v0 = stablehlo.constant dense<0.00000000000000000e+00> : tensor", rows, width); fd_line(" %v1 = stablehlo.multiply %even, %cosine : tensor", rows, width); fd_line(" %v2 = stablehlo.multiply %odd, %sine : tensor", rows, width); fd_line(" %v3 = stablehlo.subtract %v1, %v2 : tensor", rows, width); // out_even = even*cosine-odd*sine fd_line(" %v4 = stablehlo.multiply %even, %sine : tensor", rows, width); fd_line(" %v5 = stablehlo.multiply %odd, %cosine : tensor", rows, width); fd_line(" %v6 = stablehlo.add %v4, %v5 : tensor", rows, width); // out_odd = even*sine+odd*cosine fd_line(" %v7 = stablehlo.multiply %grad_even, %cosine : tensor", rows, width); fd_line(" %v8 = stablehlo.multiply %grad_odd, %sine : tensor", rows, width); fd_line(" %v9 = stablehlo.add %v7, %v8 : tensor", rows, width); // dx_even = grad_even*cosine+grad_odd*sine fd_line(" %v10 = stablehlo.multiply %grad_odd, %cosine : tensor", rows, width); fd_line(" %v11 = stablehlo.multiply %grad_even, %sine : tensor", rows, width); fd_line(" %v12 = stablehlo.subtract %v10, %v11 : tensor", rows, width); // dx_odd = grad_odd*cosine-grad_even*sine fd_line(" return %v3, %v6, %v9, %v12 : tensor, tensor, tensor, tensor", rows, width); println!(" }"); println!("}"); }