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

Flightdeck adaptive-clip

Clip a gradient relative to the parameter-row norm. Supply a positive clipping factor fixed within the row.

Source repository · Package JSON

Use Flightdeck adaptive-clip

use vendor::fd_adaptive_clip::adaptive_clip;

Run the example

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

Expected output

module {
  func.func @main(%weight: tensor<2x7xf32>, %grad: tensor<2x7xf32>, %factor: tensor<2x7xf32>) -> (tensor<2x7xf32>, tensor<2x7xf32>) {
    %v0 = stablehlo.constant dense<0.00000000000000000e+00> : tensor<2x7xf32>
    %v1 = stablehlo.multiply %weight, %weight : tensor<2x7xf32>
    %v2 = stablehlo.constant dense<0.00000000000000000e+00> : tensor<f32>
    %v3 = stablehlo.reduce(%v1 init: %v2) applies stablehlo.add across dimensions = [1] : (tensor<2x7xf32>, tensor<f32>) -> tensor<2xf32>
    %v4 = stablehlo.broadcast_in_dim %v3, dims = [0] : (tensor<2xf32>) -> tensor<2x7xf32>
    %v5 = stablehlo.sqrt %v4 : tensor<2x7xf32>
    %v6 = stablehlo.constant dense<1.00000000000000002e-03> : tensor<2x7xf32>
    %v7 = stablehlo.maximum %v5, %v6 : tensor<2x7xf32>
    %v8 = stablehlo.multiply %grad, %grad : tensor<2x7xf32>
    %v9 = stablehlo.reduce(%v8 init: %v2) applies stablehlo.add across dimensions = [1] : (tensor<2x7xf32>, tensor<f32>) -> tensor<2xf32>
    %v10 = stablehlo.broadcast_in_dim %v9, dims = [0] : (tensor<2xf32>) -> tensor<2x7xf32>
    %v11 = stablehlo.sqrt %v10 : tensor<2x7xf32>
    %v12 = stablehlo.constant dense<1.00000000000000000e+00> : tensor<2x7xf32>
    %v13 = stablehlo.multiply %factor, %v7 : tensor<2x7xf32>
    %v14 = stablehlo.constant dense<9.99999999999999955e-07> : tensor<2x7xf32>
    %v15 = stablehlo.maximum %v11, %v14 : tensor<2x7xf32>
    %v16 = stablehlo.divide %v13, %v15 : tensor<2x7xf32>
    %v17 = stablehlo.minimum %v12, %v16 : tensor<2x7xf32>
    %v18 = stablehlo.multiply %grad, %v17 : tensor<2x7xf32>
    return %v18, %v17 : tensor<2x7xf32>, tensor<2x7xf32>
  }
}

Published versions

VersionPackageSource commitSHA-256
0.1.1Download ZIP · Browse filesbf9c3d5003b0ac031e3bf72c282bde371492bc8d5878e8d4a96f726c4536a7adf8629fe4f3
0.1.0Download ZIP · Browse filesd5835c51092278ec81e6752cb6e8626c087d49a914e976db3ca6f18495fa6365c63e1b8701