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

Flightdeck affine-quantize

Simulate 8-bit asymmetric activation quantization with zero included in the range and integer zero point. Outputs use FP32 storage.

Source repository · Package JSON

Use Flightdeck affine-quantize

use vendor::fd_affine_quantize::affine_quantize;

Run the example

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

Expected output

module {
  func.func @main(%x: tensor<2x7xf32>) -> (tensor<2x7xf32>, tensor<2x7xf32>, tensor<2x7xf32>, tensor<2x7xf32>) {
    %v0 = stablehlo.constant dense<0.00000000000000000e+00> : tensor<2x7xf32>
    %v1 = stablehlo.constant dense<3.40282346000000007e+38> : tensor<f32>
    %v2 = stablehlo.reduce(%x init: %v1) applies stablehlo.minimum across dimensions = [1] : (tensor<2x7xf32>, tensor<f32>) -> tensor<2xf32>
    %v3 = stablehlo.broadcast_in_dim %v2, dims = [0] : (tensor<2xf32>) -> tensor<2x7xf32>
    %v4 = stablehlo.minimum %v3, %v0 : tensor<2x7xf32>
    %v5 = stablehlo.constant dense<-3.40282346000000007e+38> : tensor<f32>
    %v6 = stablehlo.reduce(%x init: %v5) applies stablehlo.maximum across dimensions = [1] : (tensor<2x7xf32>, tensor<f32>) -> tensor<2xf32>
    %v7 = stablehlo.broadcast_in_dim %v6, dims = [0] : (tensor<2xf32>) -> tensor<2x7xf32>
    %v8 = stablehlo.maximum %v7, %v0 : tensor<2x7xf32>
    %v9 = stablehlo.subtract %v8, %v4 : tensor<2x7xf32>
    %v10 = stablehlo.constant dense<2.55000000000000000e+02> : tensor<2x7xf32>
    %v11 = stablehlo.divide %v9, %v10 : tensor<2x7xf32>
    %v12 = stablehlo.constant dense<9.99999999999999945e-21> : tensor<2x7xf32>
    %v13 = stablehlo.maximum %v11, %v12 : tensor<2x7xf32>
    %v14 = stablehlo.negate %v4 : tensor<2x7xf32>
    %v15 = stablehlo.divide %v14, %v13 : tensor<2x7xf32>
    %v16 = stablehlo.round_nearest_even %v15 : tensor<2x7xf32>
    %v17 = stablehlo.maximum %v16, %v0 : tensor<2x7xf32>
    %v18 = stablehlo.minimum %v17, %v10 : tensor<2x7xf32>
    %v19 = stablehlo.divide %x, %v13 : tensor<2x7xf32>
    %v20 = stablehlo.round_nearest_even %v19 : tensor<2x7xf32>
    %v21 = stablehlo.add %v20, %v18 : tensor<2x7xf32>
    %v22 = stablehlo.maximum %v21, %v0 : tensor<2x7xf32>
    %v23 = stablehlo.minimum %v22, %v10 : tensor<2x7xf32>
    %v24 = stablehlo.subtract %v23, %v18 : tensor<2x7xf32>
    %v25 = stablehlo.multiply %v24, %v13 : tensor<2x7xf32>
    return %v23, %v25, %v18, %v13 : tensor<2x7xf32>, tensor<2x7xf32>, tensor<2x7xf32>, tensor<2x7xf32>
  }
}

Published versions

VersionPackageSource commitSHA-256
0.1.1Download ZIP · Browse filesbf9c3d50036b9449327f65544ff034d1595089750bbbbe4fc15de3e5793f10cf6288ba2cda
0.1.0Download ZIP · Browse filesd5835c51097ba0b726d53dd95f76cc4d57e77e5d9abc0643a2616ac975662ea0df4ee34bc7