Blyx Nest Blyx language
Registry / Framework
framework · v0.1.1

Flightdeck rmsnorm-backward

Apply row RMS normalization with per-feature gain and return the input gradient and per-row gain contribution.

Source repository · Package JSON

Use Flightdeck rmsnorm-backward

use vendor::fd_rmsnorm_backward::rmsnorm_backward;

Run the example

nest demo fd_rmsnorm_backward@0.1.1
blyxc native-run fd_rmsnorm_backward-demo/main.blyx
Example source and expected output
use vendor::fd_rmsnorm_backward::rmsnorm_backward;
fn main() { fd_rmsnorm_backward(2, 7); }

Expected output

module {
  func.func @main(%x: tensor<2x7xf32>, %gain: tensor<2x7xf32>, %upstream: tensor<2x7xf32>) -> (tensor<2x7xf32>, tensor<2x7xf32>, tensor<2x7xf32>) {
    %v0 = stablehlo.constant dense<0.00000000000000000e+00> : tensor<2x7xf32>
    %v1 = stablehlo.constant dense<1.00000000000000000e+00> : tensor<2x7xf32>
    %v2 = stablehlo.multiply %x, %x : tensor<2x7xf32>
    %v3 = stablehlo.constant dense<0.00000000000000000e+00> : tensor<f32>
    %v4 = stablehlo.reduce(%v2 init: %v3) applies stablehlo.add across dimensions = [1] : (tensor<2x7xf32>, tensor<f32>) -> tensor<2xf32>
    %v5 = stablehlo.broadcast_in_dim %v4, dims = [0] : (tensor<2xf32>) -> tensor<2x7xf32>
    %v6 = stablehlo.constant dense<7.0> : tensor<2x7xf32>
    %v7 = stablehlo.divide %v5, %v6 : tensor<2x7xf32>
    %v8 = stablehlo.constant dense<1.00000000000000008e-05> : tensor<2x7xf32>
    %v9 = stablehlo.add %v7, %v8 : tensor<2x7xf32>
    %v10 = stablehlo.sqrt %v9 : tensor<2x7xf32>
    %v11 = stablehlo.divide %v1, %v10 : tensor<2x7xf32>
    %v12 = stablehlo.multiply %x, %v11 : tensor<2x7xf32>
    %v13 = stablehlo.multiply %gain, %v12 : tensor<2x7xf32>
    %v14 = stablehlo.multiply %upstream, %gain : tensor<2x7xf32>
    %v15 = stablehlo.multiply %v14, %v12 : tensor<2x7xf32>
    %v16 = stablehlo.reduce(%v15 init: %v3) applies stablehlo.add across dimensions = [1] : (tensor<2x7xf32>, tensor<f32>) -> tensor<2xf32>
    %v17 = stablehlo.broadcast_in_dim %v16, dims = [0] : (tensor<2xf32>) -> tensor<2x7xf32>
    %v18 = stablehlo.divide %v17, %v6 : tensor<2x7xf32>
    %v19 = stablehlo.multiply %v12, %v18 : tensor<2x7xf32>
    %v20 = stablehlo.subtract %v14, %v19 : tensor<2x7xf32>
    %v21 = stablehlo.multiply %v11, %v20 : tensor<2x7xf32>
    %v22 = stablehlo.multiply %upstream, %v12 : tensor<2x7xf32>
    return %v13, %v21, %v22 : tensor<2x7xf32>, tensor<2x7xf32>, tensor<2x7xf32>
  }
}

Published versions

VersionPackageSource commitSHA-256
0.1.1Download ZIP · Browse filesbf9c3d5003b34a7f6a605d1ddc573ec80150e5480ecc14b6304285d98de801327212e9a036
0.1.0Download ZIP · Browse filesd5835c5109813c4cc5e88adff18709cf1bc8b5533528a16aa068ff7bb7b2f5ebb505f6fb34