MCPcopy Create free account
hub / github.com/0xShug0/audio.cpp / test_guidance

Function test_guidance

tests/unittests/test_diffusion_math.cpp:32–59  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30}
31
32void test_guidance() {
33 const std::vector<float> pred_cond{0.4F, -0.2F, 0.8F, -0.5F, 0.1F, 0.6F};
34 const std::vector<float> pred_uncond{-0.1F, 0.3F, 0.2F, 0.4F, -0.6F, 0.0F};
35 require_vector_close(
36 engine::sampling::cfg_guidance(pred_cond, pred_uncond, 2.5F),
37 {1.15F, -0.95F, 1.7F, -1.85F, 1.15F, 1.5F},
38 2.0e-6F,
39 "cfg python reference");
40
41 std::vector<float> momentum(6, 0.0F);
42 require_vector_close(
43 engine::sampling::apg_guidance(pred_cond, pred_uncond, 2.0F, 2, 3, momentum),
44 {0.265853659F, -0.02F, 0.728F, -0.60731709F, 0.46F, 0.696F},
45 2.0e-6F,
46 "apg python reference");
47
48 const std::vector<float> latents{1.2F, -0.7F, 0.3F, 2.0F, -1.1F, 0.5F};
49 require_vector_close(
50 engine::sampling::adg_guidance(latents, pred_cond, pred_uncond, 0.6F, 2.25F, 2, 3),
51 {0.35072118F, -0.34340942F, 1.41628838F, -0.47153577F, 0.47726715F, 1.64375424F},
52 2.0e-6F,
53 "adg python reference");
54
55 const std::vector<float> zero_latents{0.0F, 0.0F};
56 const std::vector<float> zero_pred{0.0F, 0.0F};
57 const auto zero_adg = engine::sampling::adg_guidance(zero_latents, zero_pred, zero_pred, 1.0F, 2.0F, 1, 2);
58 require_vector_close(zero_adg, {0.0F, 0.0F}, 1.0e-6F, "adg zero norm finite");
59}
60
61void test_velocity_and_steps() {
62 std::vector<float> velocity{3.0F, 4.0F};

Callers 1

mainFunction · 0.85

Calls 4

cfg_guidanceFunction · 0.85
apg_guidanceFunction · 0.85
adg_guidanceFunction · 0.85
require_vector_closeFunction · 0.70

Tested by

no test coverage detected