// Smooth squared gradients with decay 0.99 and update parameters with a scale-adjusted step. use graph_io; pub fn fd_rmsprop_step(rows: i64, width: i64) { println!("module {"); fd_line(" func.func @main(%weight: tensor, %grad: tensor, %variance: tensor, %lr: tensor) -> (tensor, tensor) {", rows, width); fd_line(" %v0 = stablehlo.constant dense<0.00000000000000000e+00> : tensor", rows, width); fd_line(" %v1 = stablehlo.constant dense<9.89999999999999991e-01> : tensor", rows, width); fd_line(" %v2 = stablehlo.multiply %v1, %variance : tensor", rows, width); fd_line(" %v3 = stablehlo.constant dense<1.00000000000000002e-02> : tensor", rows, width); fd_line(" %v4 = stablehlo.multiply %v3, %grad : tensor", rows, width); fd_line(" %v5 = stablehlo.multiply %v4, %grad : tensor", rows, width); fd_line(" %v6 = stablehlo.add %v2, %v5 : tensor", rows, width); // next_var = 0.99*variance+0.01*grad*grad fd_line(" %v7 = stablehlo.multiply %lr, %grad : tensor", rows, width); fd_line(" %v8 = stablehlo.sqrt %v6 : tensor", rows, width); fd_line(" %v9 = stablehlo.constant dense<1.00000000000000002e-08> : tensor", rows, width); fd_line(" %v10 = stablehlo.add %v8, %v9 : tensor", rows, width); fd_line(" %v11 = stablehlo.divide %v7, %v10 : tensor", rows, width); fd_line(" %v12 = stablehlo.subtract %weight, %v11 : tensor", rows, width); // updated = weight-lr*grad/(sqrt(next_var)+1e-8) fd_line(" return %v12, %v6 : tensor, tensor", rows, width); println!(" }"); println!("}"); }