Skip to content

Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.

C++
7.5 KB
Raw Blame
// GENERATED by tests/python/gen_ple_oracle.py - DO NOT EDIT BY HAND.
//
// Sources, none of them this project's own code:
//   hash   ref/ngram.py::ngram_rows (qwen4exp.cpp L1092-1124, validated bit-exact in round 101)
//   table  the ORIGINAL GGUF's bytes, read at the offset the validated gguf_reader reports,
//          dequantized with numpy
//   offsets pack/full/manifest.json

#pragma once
#include <cstdint>

namespace strata::kernels::ple_oracle {

struct HashCase { const char* name; int n_tokens; const int32_t* tokens;
                  const int32_t* prev; const uint32_t* rows; };

// window direction
inline const int32_t case0_tokens[4] = {11, 22, 33, 44};
inline const int32_t case0_prev[8] = {-1, -1, 11, -1, 22, 11, 33, 22};
inline const uint32_t case0_rows[64] = {
    13555483, 24877159, 54278900, 63631058, 98394898, 117447587, 136774765, 157274238, 173487882, 192109366, 213364329, 236577563, 258758149, 262164274, 283572184, 312653920,
    3278367, 29880471, 46922633, 62971672, 94904487, 113013549, 120925297, 159537733, 161636484, 186269036, 207870452, 237789268, 242975733, 269388091, 285131318, 305889870,
    2485282, 23858032, 54544880, 69506925, 82331991, 106607168, 133019998, 141570514, 173894108, 180423171, 211374553, 239810912, 253076960, 266343146, 290765399, 312876099,
    12721672, 27113445, 44309803, 60385209, 97021817, 115900810, 134219364, 151977589, 161183764, 181257609, 201344488, 221596875, 241635416, 261674107, 281687144, 301751935,
};
// EOS one back cuts both
inline const int32_t case1_tokens[3] = {7, 8, 9};
inline const int32_t case1_prev[6] = {-1, -1, 7, 248044, 248044, 7};
inline const uint32_t case1_rows[48] = {
    2927653, 34980843, 54748278, 66612378, 97814964, 109013870, 126560393, 151352333, 167888935, 182235580, 215170017, 237467519, 247510681, 278779700, 296141806, 304994522,
    7508793, 29969020, 54939975, 74089003, 91535754, 104816064, 125484693, 154439441, 164805529, 181662903, 214193203, 238193346, 259492009, 262016223, 296463606, 310742083,
    5471414, 32902469, 56618078, 65819961, 82278798, 107765152, 125994638, 156967341, 179716672, 187881262, 219224344, 222418510, 250276020, 278493068, 281311927, 316005603,
};
// NULL reads as EOS
inline const int32_t case2_tokens[2] = {100, 101};
inline const int32_t case2_prev[4] = {-1, -1, -1, -1};
inline const uint32_t case2_rows[32] = {
    5727835, 21884476, 43702108, 66434789, 84094509, 104112171, 134886528, 157314943, 162363667, 189466439, 200618315, 232121522, 258547276, 266199001, 289022207, 305180972,
    14526383, 36975477, 51939184, 65076202, 94510971, 111786935, 138448715, 155393638, 167579692, 181767276, 211184823, 226303266, 246271192, 267465224, 281469089, 313531602,
};
// token id 0 is NOT missing
inline const int32_t case3_tokens[2] = {100, 101};
inline const int32_t case3_prev[4] = {0, 0, 100, 0};
inline const uint32_t case3_rows[32] = {
    223356, 29869136, 44693816, 65450370, 83243562, 109175069, 138072664, 149936704, 175869089, 193667153, 214433731, 233779437, 242682975, 271587098, 294555343, 309396483,
    9825591, 35767834, 58740777, 62904867, 86476006, 107666813, 129453358, 151836075, 160726459, 190511348, 208596315, 234569026, 259467109, 264365567, 292665383, 314164387,
};
// own EOS does not cut itself
inline const int32_t case4_tokens[3] = {248044, 5, 248044};
inline const int32_t case4_prev[6] = {-1, -1, 248044, -1, 5, 248044};
inline const uint32_t case4_rows[48] = {
    9663979, 26558231, 56120240, 74755659, 80459717, 109265651, 132697467, 151022725, 170054832, 192967038, 200687722, 225763581, 259275737, 272983544, 297596484, 300986548,
    15389869, 39778609, 55713969, 62213332, 88817728, 118483999, 133731511, 155458159, 179763390, 197956758, 205378969, 220499474, 242466248, 265658744, 293662119, 315720898,
    9663979, 26558231, 56120240, 74755659, 80459717, 109265651, 132697467, 151022725, 170054832, 192967038, 200687722, 225763581, 259275737, 272983544, 297596484, 300986548,
};
// real vocabulary ids
inline const int32_t case5_tokens[5] = {248043, 12345, 248043, 7, 200000};
inline const int32_t case5_prev[10] = {-1, -1, 248043, -1, 12345, 248043, 248043, 12345, 7, 248043};
inline const uint32_t case5_rows[80] = {
    5224855, 30284709, 43929396, 72280505, 94883662, 109322550, 131203836, 140794991, 166459826, 181131035, 209237474, 226844350, 246236135, 265823742, 299063341, 305586418,
    11270970, 23825822, 53627731, 75297762, 86108900, 117131242, 124369521, 148669731, 173053968, 186938961, 219076364, 237563026, 246838602, 277288915, 294366759, 301712965,
    9040325, 23423119, 51729309, 72606490, 88803423, 101106903, 139785146, 145105493, 165075797, 186774126, 216848848, 228384799, 252197080, 276291559, 284385762, 305326936,
    4918924, 35785322, 51404601, 69479989, 96595301, 119006811, 132661231, 157603286, 167367331, 194295259, 207336314, 231383366, 248222822, 265383752, 291175661, 300670030,
    19540326, 36155593, 54730668, 61035256, 83860210, 111525643, 123077188, 158579165, 171421264, 181503411, 210257194, 220050508, 255765827, 271545193, 290152687, 303296503,
};

inline const HashCase kHashCases[] = {
    {"window direction", 4, case0_tokens, case0_prev, case0_rows},
    {"EOS one back cuts both", 3, case1_tokens, case1_prev, case1_rows},
    {"NULL reads as EOS", 2, case2_tokens, case2_prev, case2_rows},
    {"token id 0 is NOT missing", 2, case3_tokens, case3_prev, case3_rows},
    {"own EOS does not cut itself", 3, case4_tokens, case4_prev, case4_rows},
    {"real vocabulary ids", 5, case5_tokens, case5_prev, case5_rows},
};
inline constexpr int kHashCaseCount = 6;

// The table: sampled values of two rows, plus the whole-row L1 sums so a wrong codebook or a
// wrong scale cannot hide between the samples.  Row 0 and the LAST row.
inline constexpr uint64_t kTableRows = 320001536ull;
inline constexpr uint64_t kTableDataStart = 192ull;
inline constexpr uint64_t kTableFileSize = 28800138432ull;
inline const uint32_t kProbeRows[] = {0, 12345, 320001535};
inline constexpr int kProbeCount = 3;
inline const float kProbeHead[][8] = {
    {-1.001119614e-02f, 1.290917397e-02f, -1.817822456e-02f, 1.290917397e-02f, -6.586313248e-03f, 5.795955658e-03f, -6.586313248e-03f, 5.795955658e-03f},
    {5.563795567e-03f, -4.314780235e-03f, 3.974139690e-03f, -1.476109028e-03f, -1.135468483e-04f, 1.135468483e-03f, -1.010566950e-02f, -6.017982960e-03f},
    {0.000000000e+00f, 0.000000000e+00f, 0.000000000e+00f, 0.000000000e+00f, 0.000000000e+00f, 0.000000000e+00f, 0.000000000e+00f, 0.000000000e+00f},
};
inline const float kProbeTail[][8] = {
    {2.571296692e-02f, 1.607060432e-02f, 3.139948845e-02f, 5.439281464e-03f, -1.705956459e-02f, -3.214120865e-03f, -2.200436592e-02f, 2.472400665e-03f},
    {-1.942408085e-02f, 5.811929703e-03f, -9.941458702e-03f, 3.823637962e-03f, -5.353093147e-03f, -1.529455185e-03f, -1.529455185e-03f, -5.353093147e-03f},
    {0.000000000e+00f, 0.000000000e+00f, 0.000000000e+00f, 0.000000000e+00f, 0.000000000e+00f, 0.000000000e+00f, 0.000000000e+00f, 0.000000000e+00f},
};
inline const double kProbeSum[] = {2.011959553e+00, 9.968549609e-01, 0.000000000e+00};
inline constexpr float kInterleavedSeparation = 1.253766603e+00f;

// pack/full/dense.bin regions for the two quantized PLE weights
inline constexpr uint64_t kKeyCodesOffset = 1017723776ull;
inline constexpr uint64_t kKeyCodesBytes  = 6553600ull;
inline constexpr uint64_t kKeyScalesOffset = 1024277376ull;
inline constexpr uint64_t kKeyScalesBytes  = 819200ull;
inline constexpr uint64_t kValueOffset = 1025219456ull;
inline constexpr uint64_t kValueBytes  = 26214400ull;

}  // namespace strata::kernels::ple_oracle