mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-05 15:58:53 +00:00
[Engine] Metal: --rope-scaling builds the window RoPE table with the scaling
On a Mac, --rope-scaling linear|yarn was resolved and logged as active but changed no rotation: every Metal RoPE rotation is in qsa_prep, which reads only the window table that Window::init built unscaled. The window now builds that table with build_rope_table(64, rope_scaling(), ...), the builder the PC session table uses. Without --rope-scaling the original loop runs, so the default path is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c775728069
commit
8a124e4312
2 files changed
+48
-5
No files matched your search
@@ -137,6 +137,14 @@ JSON +9.3%, agent turn +12.5%; the other sets are not measured),
|
||||
and the Q8_0 hyper-connection read. `STRATA_HC_Q8=0` in the config's `env` gives the exact BF16 read. The Mac engine is
|
||||
deterministic: two runs give identical numbers.
|
||||
|
||||
### Longer context (`--rope-scaling`)
|
||||
|
||||
`--rope-scaling linear|yarn` with `--rope-scale`, `--rope-freq-scale` and the `--yarn-*` options changes the RoPE table of the
|
||||
attention, as on a PC. Flash-Next is trained to 262,144 tokens: `--context 524288 --rope-scaling yarn --rope-scale 2` gives it
|
||||
512K. The table keeps the model file's frequency base, and the engine logs the table it built (`rope scaling yarn in the window
|
||||
table: ...`). Without `--rope-scaling` the table is the original one, bit for bit. The DFlash2 drafter keeps its own unscaled
|
||||
table: it only proposes tokens, so the scaling changes how many it gets accepted, not the output.
|
||||
|
||||
### Gyro-S and Gyro-M (agentionai's trellis experts)
|
||||
|
||||
The Mac engine runs [Gyro](GYRO.md). The routed experts are trellis-coded blocks (ggml types TQ2_T, TQK6, TQK7) in a
|
||||
|
||||
@@ -28,6 +28,8 @@
|
||||
#include "strata/core/conversation_cache.hpp"
|
||||
#include "strata/core/session.hpp"
|
||||
#include "strata/kernels/ngram.hpp"
|
||||
#include "strata/kernels/rope.hpp"
|
||||
#include "strata/kernels/rope_scaling.hpp"
|
||||
#include "strata/kernels/sampler.hpp"
|
||||
namespace strata::gpu { void* host_view(const void* device_pointer); }
|
||||
#include "strata/kernels/cpu/hadamard.hpp"
|
||||
@@ -828,12 +830,45 @@ bool Window::init(const strata::core::ModelGeometry& g, strata::core::SessionSta
|
||||
}
|
||||
// RoPE: cos/sin [pos][32] for the first 64 dims, NEOX pairs (i, i + 32), in double as build_rope_table
|
||||
const double base = f_.meta_num.count("qwen4exp.rope.freq_base") ? f_.meta_num["qwen4exp.rope.freq_base"] : 1e7;
|
||||
for (int p = 0; p < MAXC + 16; ++p)
|
||||
for (int i = 0; i < 32; ++i) {
|
||||
const double th = (double) p * std::pow(base, -2.0 * i / 64.0);
|
||||
cs_.as<float>()[(p * 32 + i) * 2] = (float) std::cos(th);
|
||||
cs_.as<float>()[(p * 32 + i) * 2 + 1] = (float) std::sin(th);
|
||||
// Rope scaling (--rope-scaling linear|yarn, rope_scaling.hpp): the process config generate.cpp resolved before the
|
||||
// window exists. None: the original loop, unchanged (bit-identical to the unscaled engine). Linear/YaRN: the shared
|
||||
// table builder (setup_host.cpp, rope.cu's) fills cos/sin with the interpolated angles and YaRN's magnitude correction
|
||||
// (mscale) folded in, as the CUDA table path does. Every qsa_prep dispatch (q, k, the indexer q and the pooled
|
||||
// indexer keys; decode, verify, prompt and the MTP draft layer) reads this one table, so mscale lands once per rotated
|
||||
// row. The window's frequency base (the model file's) stays the base.
|
||||
const strata::kernels::RopeScaling& rsc = strata::kernels::rope_scaling();
|
||||
if (rsc.type == strata::kernels::RopeScalingType::None) {
|
||||
for (int p = 0; p < MAXC + 16; ++p)
|
||||
for (int i = 0; i < 32; ++i) {
|
||||
const double th = (double) p * std::pow(base, -2.0 * i / 64.0);
|
||||
cs_.as<float>()[(p * 32 + i) * 2] = (float) std::cos(th);
|
||||
cs_.as<float>()[(p * 32 + i) * 2 + 1] = (float) std::sin(th);
|
||||
}
|
||||
} else {
|
||||
strata::kernels::RopeScaling sc = rsc;
|
||||
if (sc.freq_base != base)
|
||||
std::fprintf(stderr, "strata metal: rope scaling: the resolved frequency base %g differs from the model "
|
||||
"file's %g; the window keeps the model file's\n", sc.freq_base, base);
|
||||
sc.freq_base = base;
|
||||
if (const char* why = strata::kernels::rope_scaling_invalid(sc)) {
|
||||
err = std::string("metal window: invalid rope scaling: ") + why;
|
||||
return false;
|
||||
}
|
||||
const int rows = MAXC + 16;
|
||||
std::vector<float> ct((size_t) rows * 32), st((size_t) rows * 32);
|
||||
strata::kernels::build_rope_table(64, sc, rows, ct.data(), st.data());
|
||||
float* cs = cs_.as<float>();
|
||||
for (size_t k = 0; k < (size_t) rows * 32; ++k) {
|
||||
cs[k * 2] = ct[k];
|
||||
cs[k * 2 + 1] = st[k];
|
||||
}
|
||||
double cd[2];
|
||||
sc.corr_dims(64, cd);
|
||||
std::fprintf(stderr, "strata metal: rope scaling %s in the window table: factor %g, freq_scale %g, base %g, "
|
||||
"original context %g, ext_factor %g, mscale %.6f, correction pairs %g..%g, %d positions\n",
|
||||
sc.type == strata::kernels::RopeScalingType::YaRN ? "yarn" : "linear", sc.factor, sc.freq_scale(),
|
||||
sc.freq_base, sc.orig_ctx, sc.ext_factor, sc.mscale(), cd[0], cd[1], rows);
|
||||
}
|
||||
for (int t = 0; t < MAXT; ++t)
|
||||
for (int c = 0; c < G_BUD; ++c) qids_.as<int>()[t * G_BUD + c] = c;
|
||||
for (int l = 0; l < G_NL; ++l) {
|
||||
|
||||
Reference in new issue
Block a user