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

Flightdeck preference-dpo

Score a preferred/rejected response pair against a reference policy. Return the DPO loss and gradient to the policy log-ratio.

Source repository · Package JSON

Use Flightdeck preference-dpo

use vendor::fd_preference_dpo::preference_dpo;

Run the example

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

Expected output

module {
  func.func @main(%policy_win: tensor<2x7xf32>, %policy_lose: tensor<2x7xf32>, %ref_win: tensor<2x7xf32>, %ref_lose: tensor<2x7xf32>, %beta: tensor<2x7xf32>) -> (tensor<2x7xf32>, tensor<2x7xf32>) {
    %v0 = stablehlo.constant dense<0.00000000000000000e+00> : tensor<2x7xf32>
    %v1 = stablehlo.subtract %policy_win, %policy_lose : tensor<2x7xf32>
    %v2 = stablehlo.subtract %ref_win, %ref_lose : tensor<2x7xf32>
    %v3 = stablehlo.subtract %v1, %v2 : tensor<2x7xf32>
    %v4 = stablehlo.multiply %beta, %v3 : tensor<2x7xf32>
    %v5 = stablehlo.negate %v4 : tensor<2x7xf32>
    %v6 = stablehlo.maximum %v5, %v0 : tensor<2x7xf32>
    %v7 = stablehlo.abs %v4 : tensor<2x7xf32>
    %v8 = stablehlo.negate %v7 : tensor<2x7xf32>
    %v9 = stablehlo.exponential %v8 : tensor<2x7xf32>
    %v10 = stablehlo.log_plus_one %v9 : tensor<2x7xf32>
    %v11 = stablehlo.add %v6, %v10 : tensor<2x7xf32>
    %v12 = stablehlo.negate %beta : tensor<2x7xf32>
    %v13 = stablehlo.logistic %v5 : tensor<2x7xf32>
    %v14 = stablehlo.multiply %v12, %v13 : tensor<2x7xf32>
    return %v11, %v14 : tensor<2x7xf32>, tensor<2x7xf32>
  }
}

Published versions

VersionPackageSource commitSHA-256
0.1.1Download ZIP · Browse filesbf9c3d50031b454a01b97efb407dbfb87795517b6467c7eefe2cff083a6128feeec9c63aa9
0.1.0Download ZIP · Browse filesd5835c5109776c61691c170e5c47a6c6766eb7092bc3a8cc94b968c65047297557237acc27