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

Flightdeck centralize-grad

Subtract each filter row’s mean gradient and measure its remaining RMS magnitude.

Source repository · Package JSON

Use Flightdeck centralize-grad

use vendor::fd_centralize_grad::centralize_grad;

Run the example

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

Expected output

module {
  func.func @main(%grad: tensor<2x7xf32>) -> (tensor<2x7xf32>, tensor<2x7xf32>) {
    %v0 = stablehlo.constant dense<0.00000000000000000e+00> : tensor<2x7xf32>
    %v1 = stablehlo.constant dense<0.00000000000000000e+00> : tensor<f32>
    %v2 = stablehlo.reduce(%grad init: %v1) applies stablehlo.add across dimensions = [1] : (tensor<2x7xf32>, tensor<f32>) -> tensor<2xf32>
    %v3 = stablehlo.broadcast_in_dim %v2, dims = [0] : (tensor<2xf32>) -> tensor<2x7xf32>
    %v4 = stablehlo.constant dense<7.0> : tensor<2x7xf32>
    %v5 = stablehlo.divide %v3, %v4 : tensor<2x7xf32>
    %v6 = stablehlo.subtract %grad, %v5 : tensor<2x7xf32>
    %v7 = stablehlo.multiply %v6, %v6 : tensor<2x7xf32>
    %v8 = stablehlo.reduce(%v7 init: %v1) applies stablehlo.add across dimensions = [1] : (tensor<2x7xf32>, tensor<f32>) -> tensor<2xf32>
    %v9 = stablehlo.broadcast_in_dim %v8, dims = [0] : (tensor<2xf32>) -> tensor<2x7xf32>
    %v10 = stablehlo.divide %v9, %v4 : tensor<2x7xf32>
    %v11 = stablehlo.sqrt %v10 : tensor<2x7xf32>
    return %v6, %v11 : tensor<2x7xf32>, tensor<2x7xf32>
  }
}

Published versions

VersionPackageSource commitSHA-256
0.1.1Download ZIP · Browse filesbf9c3d5003f9537b29cc2ed36a380d91205f817ec3d2a1198e736b641cf00c98f0b1775a4c
0.1.0Download ZIP · Browse filesd5835c5109caff4e6bea22fd75bea2e5240418a48c83b9c6e1e1e7fbf36fd31f323d73961c