okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

waveringanamtp: the request's hard bans (logit_bias -100) are masked out of the draft head, so a banned token is never drafted (STRATA_MTP_BAN_MASK=0: off)9a985cb12

main
1.9 KiB37 linesraw
1// The draft-head ban columns (core/draft_ban.hpp): token ids to subset columns, and the cases that must stay no-ops.
2#include "strata/core/draft_ban.hpp"
3#include "strata/core/logit_bias.hpp"
4
5#include <cstdio>
6#include <cstdlib>
7#include <string>
8
9int main() {
10    using strata::core::draft_ban_columns;
11    auto check = [](bool ok, const char* what) {
12        if (!ok) { std::fprintf(stderr, "draft_ban_test: %s\n", what); std::exit(1); }
13    };
14    const int32_t dvocab[] = {3, 7, 1, 9, 5};   // column i drafts token dvocab[i]
15    std::vector<float> bias;
16    std::string err;
17
18    check(draft_ban_columns(bias, dvocab, 5).empty(), "no bias must mask nothing");
19    check(draft_ban_columns(bias, nullptr, 0).empty(), "no bias must mask nothing (full head)");
20
21    check(strata::core::parse_logit_bias("2:1.5,7:-99.5,9:100", 10, bias, err), "parse finite");
22    check(draft_ban_columns(bias, dvocab, 5).empty(), "a finite bias must leave the drafter unchanged");
23    check(draft_ban_columns(bias, nullptr, 0).empty(), "a finite bias must leave the full head unchanged");
24
25    check(strata::core::parse_logit_bias("9:-100,0:-100,7:-100,5:2", 10, bias, err), "parse bans");
26    check(draft_ban_columns(bias, dvocab, 5) == std::vector<int32_t>{1, 3}, "bans map to their subset columns");
27    check(draft_ban_columns(bias, nullptr, 0) == std::vector<int32_t>{0, 7, 9}, "full head: columns are the ids");
28
29    check(strata::core::parse_logit_bias("0:-100,2:-100", 10, bias, err), "parse bans outside the subset");
30    check(draft_ban_columns(bias, dvocab, 5).empty(), "a ban outside the draft vocabulary masks nothing");
31
32    const int32_t odd[] = {-1, 12, 0};   // ids the bias does not cover are never masked
33    check(strata::core::parse_logit_bias("0:-100", 10, bias, err), "parse");
34    check(draft_ban_columns(bias, odd, 3) == std::vector<int32_t>{2}, "out-of-range subset ids are skipped");
35
36    std::puts("draft_ban_test: passed");
37}