| 26 | } |
| 27 | |
| 28 | std::vector<float> cfg_guidance( |
| 29 | const std::vector<float> & pred_cond, |
| 30 | const std::vector<float> & pred_uncond, |
| 31 | float guidance_scale) { |
| 32 | require_same_size(pred_cond.size(), pred_uncond.size(), "CFG branch size mismatch"); |
| 33 | std::vector<float> out(pred_cond.size(), 0.0F); |
| 34 | for (size_t i = 0; i < pred_cond.size(); ++i) { |
| 35 | out[i] = pred_uncond[i] + guidance_scale * (pred_cond[i] - pred_uncond[i]); |
| 36 | } |
| 37 | return out; |
| 38 | } |
| 39 | |
| 40 | std::vector<float> apg_guidance( |
| 41 | const std::vector<float> & pred_cond, |