MCPcopy Create free account
hub / github.com/Niko1221/Strata / check

Function check

engine/src/split/tools/rope_test.cpp:43–71  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

41}
42
43void check(float base, int orig, double S, int nrot, float want_low, float want_high) {
44 char tag[128];
45 std::snprintf(tag, sizeof tag, "base %g orig %d x%g nrot %d", base, orig, S, nrot);
46 const fnx::Rope r = fnx::yarn_rope(base, orig, S, nrot);
47 float dims[2];
48 ggml_corr_dims(nrot, orig, base, 32.0f, 1.0f, dims);
49 if (r.c_low != dims[0] || r.c_high != dims[1])
50 fail(std::string(tag) + ": band " + std::to_string(r.c_low) + ".." + std::to_string(r.c_high) + ", ggml " + std::to_string(dims[0]) +
51 ".." + std::to_string(dims[1]));
52 if (r.c_low != want_low || r.c_high != want_high)
53 fail(std::string(tag) + ": band " + std::to_string(r.c_low) + ".." + std::to_string(r.c_high) + ", recorded " +
54 std::to_string(want_low) + ".." + std::to_string(want_high));
55 // llama-context.cpp: attn_factor = get_mscale(S, 1) / (1 + 0.1 ln S); rope_yarn: mscale = attn_factor * (1 + 0.1 ln S)
56 const float factor = (float) S, get_mscale = 0.1f * logf(factor) + 1.0f;
57 const float attn_factor = get_mscale * (1.0f / (1.0f + 0.1f * logf(factor)));
58 const float mscale = attn_factor * (1.0f + 0.1f * logf(1.0f / (float) (1.0 / S)));
59 if (std::fabs(r.mscale - mscale) > 1e-6f * mscale) fail(std::string(tag) + ": mscale " + std::to_string(r.mscale) + ", llama.cpp " + std::to_string(mscale));
60 const float theta_scale = powf(base, -2.0f / nrot);
61 for (int pos : {1, 1000, 262143, 900000})
62 for (int i = 0; i < nrot / 2; ++i) {
63 const float mine = (float) pos * fnx::rope_unit_freq(r, i, nrot);
64 const float theirs = ggml_theta((float) pos * powf(theta_scale, (float) i), (float) (1.0 / S), dims, 2 * i);
65 if (std::fabs(mine - theirs) > 2e-5f * std::fabs(theirs)) {
66 fail(std::string(tag) + ": pair " + std::to_string(i) + " at " + std::to_string(pos) + ": angle " + std::to_string(mine) +
67 ", ggml " + std::to_string(theirs));
68 return;
69 }
70 }
71}
72
73// choose_rope: the model's YaRN keys and the settings, each case (model factor, model orig, context_length, env scale
74// -1 unset / 0 off, env orig 0 unset) with the scale, trained length and limit it must give, or a refusal

Callers 1

mainFunction · 0.70

Calls 7

yarn_ropeFunction · 0.85
ggml_corr_dimsFunction · 0.85
rope_unit_freqFunction · 0.85
ggml_thetaFunction · 0.85
failFunction · 0.70
stringFunction · 0.50
to_stringFunction · 0.50

Tested by

no test coverage detected