Registry / Framework

framework · v0.1.1
Flightdeck layernorm-backward
Normalize each embedding row, add affine gain and bias, and propagate an upstream derivative. Sum gain contributions across rows externally.
Use Flightdeck layernorm-backward
use vendor::fd_layernorm_backward::layernorm_backward;
Run the example
nest demo fd_layernorm_backward@0.1.1
blyxc native-run fd_layernorm_backward-demo/main.blyx
Example source and expected output
use vendor::fd_layernorm_backward::layernorm_backward;
fn main() { fd_layernorm_backward(2, 7); }
Expected output
module {
func.func @main(%x: tensor<2x7xf32>, %gain: tensor<2x7xf32>, %bias: tensor<2x7xf32>, %upstream: tensor<2x7xf32>) -> (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(%x 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 %x, %v5 : tensor<2x7xf32>
%v7 = stablehlo.constant dense<1.00000000000000000e+00> : tensor<2x7xf32>
%v8 = stablehlo.multiply %v6, %v6 : tensor<2x7xf32>
%v9 = stablehlo.reduce(%v8 init: %v1) 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.divide %v10, %v4 : tensor<2x7xf32>
%v12 = stablehlo.constant dense<1.00000000000000008e-05> : tensor<2x7xf32>
%v13 = stablehlo.add %v11, %v12 : tensor<2x7xf32>
%v14 = stablehlo.sqrt %v13 : tensor<2x7xf32>
%v15 = stablehlo.divide %v7, %v14 : tensor<2x7xf32>
%v16 = stablehlo.multiply %v6, %v15 : tensor<2x7xf32>
%v17 = stablehlo.multiply %v16, %gain : tensor<2x7xf32>
%v18 = stablehlo.add %v17, %bias : tensor<2x7xf32>
%v19 = stablehlo.multiply %upstream, %gain : tensor<2x7xf32>
%v20 = stablehlo.reduce(%v19 init: %v1) applies stablehlo.add across dimensions = [1] : (tensor<2x7xf32>, tensor<f32>) -> tensor<2xf32>
%v21 = stablehlo.broadcast_in_dim %v20, dims = [0] : (tensor<2xf32>) -> tensor<2x7xf32>
%v22 = stablehlo.divide %v21, %v4 : tensor<2x7xf32>
%v23 = stablehlo.subtract %v19, %v22 : tensor<2x7xf32>
%v24 = stablehlo.multiply %v19, %v16 : tensor<2x7xf32>
%v25 = stablehlo.reduce(%v24 init: %v1) applies stablehlo.add across dimensions = [1] : (tensor<2x7xf32>, tensor<f32>) -> tensor<2xf32>
%v26 = stablehlo.broadcast_in_dim %v25, dims = [0] : (tensor<2xf32>) -> tensor<2x7xf32>
%v27 = stablehlo.divide %v26, %v4 : tensor<2x7xf32>
%v28 = stablehlo.multiply %v16, %v27 : tensor<2x7xf32>
%v29 = stablehlo.subtract %v23, %v28 : tensor<2x7xf32>
%v30 = stablehlo.multiply %v15, %v29 : tensor<2x7xf32>
%v31 = stablehlo.multiply %upstream, %v16 : tensor<2x7xf32>
return %v18, %v30, %v31 : tensor<2x7xf32>, tensor<2x7xf32>, tensor<2x7xf32>
}
}
Published versions
| Version | Package | Source commit | SHA-256 |
|---|---|---|---|
| 0.1.1 | Download ZIP · Browse files | bf9c3d5003 | 3bfe0753f0ecc8241211d39c47ded82309a4a845ef15e86843ac85793e4d18b4 |
| 0.1.0 | Download ZIP · Browse files | d5835c5109 | 22b51b758c6f2f9e81241cf9daf7d71dabf3c08e93ba2a4a54934f40bccc9587 |