Registry / Framework

framework · v0.1.1
Flightdeck policy-ratio
Compute the clipped PPO surrogate and clipping fraction using sampled-token log probabilities. Supply a fixed positive clip radius in each row.
Use Flightdeck policy-ratio
use vendor::fd_policy_ratio::policy_ratio;
Run the example
nest demo fd_policy_ratio@0.1.1
blyxc native-run fd_policy_ratio-demo/main.blyx
Example source and expected output
use vendor::fd_policy_ratio::policy_ratio;
fn main() { fd_policy_ratio(2, 7); }
Expected output
module {
func.func @main(%new_logp: tensor<2x7xf32>, %old_logp: tensor<2x7xf32>, %advantage: tensor<2x7xf32>, %radius: tensor<2x7xf32>) -> (tensor<2x7xf32>, tensor<2x7xf32>) {
%v0 = stablehlo.constant dense<0.00000000000000000e+00> : tensor<2x7xf32>
%v1 = stablehlo.subtract %new_logp, %old_logp : tensor<2x7xf32>
%v2 = stablehlo.exponential %v1 : tensor<2x7xf32>
%v3 = stablehlo.constant dense<1.00000000000000000e+00> : tensor<2x7xf32>
%v4 = stablehlo.subtract %v3, %radius : tensor<2x7xf32>
%v5 = stablehlo.add %v3, %radius : tensor<2x7xf32>
%v6 = stablehlo.maximum %v2, %v4 : tensor<2x7xf32>
%v7 = stablehlo.minimum %v6, %v5 : tensor<2x7xf32>
%v8 = stablehlo.multiply %v2, %advantage : tensor<2x7xf32>
%v9 = stablehlo.multiply %v7, %advantage : tensor<2x7xf32>
%v10 = stablehlo.minimum %v8, %v9 : tensor<2x7xf32>
%v11 = stablehlo.constant dense<0.00000000000000000e+00> : tensor<f32>
%v12 = stablehlo.reduce(%v10 init: %v11) applies stablehlo.add across dimensions = [1] : (tensor<2x7xf32>, tensor<f32>) -> tensor<2xf32>
%v13 = stablehlo.broadcast_in_dim %v12, dims = [0] : (tensor<2xf32>) -> tensor<2x7xf32>
%v14 = stablehlo.constant dense<7.0> : tensor<2x7xf32>
%v15 = stablehlo.divide %v13, %v14 : tensor<2x7xf32>
%v16 = stablehlo.negate %v15 : tensor<2x7xf32>
%v17 = stablehlo.subtract %v2, %v3 : tensor<2x7xf32>
%v18 = stablehlo.abs %v17 : tensor<2x7xf32>
%v19 = stablehlo.compare GT, %v18, %radius, FLOAT : (tensor<2x7xf32>, tensor<2x7xf32>) -> tensor<2x7xi1>
%v20 = stablehlo.select %v19, %v3, %v0 : tensor<2x7xi1>, tensor<2x7xf32>
%v21 = stablehlo.reduce(%v20 init: %v11) applies stablehlo.add across dimensions = [1] : (tensor<2x7xf32>, tensor<f32>) -> tensor<2xf32>
%v22 = stablehlo.broadcast_in_dim %v21, dims = [0] : (tensor<2xf32>) -> tensor<2x7xf32>
%v23 = stablehlo.divide %v22, %v14 : tensor<2x7xf32>
return %v16, %v23 : tensor<2x7xf32>, tensor<2x7xf32>
}
}
Published versions
| Version | Package | Source commit | SHA-256 |
|---|---|---|---|
| 0.1.1 | Download ZIP · Browse files | bf9c3d5003 | 98ca633668ad41ef9c4564b9aca90aa1d8fa3d09ab0416371fc6934c690b3958 |
| 0.1.0 | Download ZIP · Browse files | d5835c5109 | bc1f1f753a431c8a75b29996a835f811d31e85b55342c093c7ac4bbd6e76be16 |