// Use a signed interpolated momentum update and decoupled weight decay. The persistent buffer uses beta2=0.99. use graph_io; pub fn fd_lion_step(rows: i64, width: i64) { println!("module {"); fd_line(" func.func @main(%weight: tensor, %grad: tensor, %moment: tensor, %lr: tensor, %decay: tensor) -> (tensor, tensor) {", rows, width); fd_line(" %v0 = stablehlo.constant dense<0.00000000000000000e+00> : tensor", rows, width); fd_line(" %v1 = stablehlo.constant dense<9.00000000000000022e-01> : tensor", rows, width); fd_line(" %v2 = stablehlo.multiply %v1, %moment : tensor", rows, width); fd_line(" %v3 = stablehlo.constant dense<1.00000000000000006e-01> : tensor", rows, width); fd_line(" %v4 = stablehlo.multiply %v3, %grad : tensor", rows, width); fd_line(" %v5 = stablehlo.add %v2, %v4 : tensor", rows, width); fd_line(" %v6 = stablehlo.sign %v5 : tensor", rows, width); // direction = sign(0.9*moment+0.1*grad) fd_line(" %v7 = stablehlo.constant dense<1.00000000000000000e+00> : tensor", rows, width); fd_line(" %v8 = stablehlo.multiply %lr, %decay : tensor", rows, width); fd_line(" %v9 = stablehlo.subtract %v7, %v8 : tensor", rows, width); fd_line(" %v10 = stablehlo.multiply %weight, %v9 : tensor", rows, width); fd_line(" %v11 = stablehlo.multiply %lr, %v6 : tensor", rows, width); fd_line(" %v12 = stablehlo.subtract %v10, %v11 : tensor", rows, width); // updated = weight*(1-lr*decay)-lr*direction fd_line(" %v13 = stablehlo.constant dense<9.89999999999999991e-01> : tensor", rows, width); fd_line(" %v14 = stablehlo.multiply %v13, %moment : tensor", rows, width); fd_line(" %v15 = stablehlo.constant dense<1.00000000000000002e-02> : tensor", rows, width); fd_line(" %v16 = stablehlo.multiply %v15, %grad : tensor", rows, width); fd_line(" %v17 = stablehlo.add %v14, %v16 : tensor", rows, width); // m = 0.99*moment+0.01*grad fd_line(" return %v12, %v17 : tensor, tensor", rows, width); println!(" }"); println!("}"); }