okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
9a985cb12
main
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 () { 10using strata::core::draft_ban_columns ; 11auto check = [](bool ok ,const char * what ) { 12if (!ok ) { std::fprintf (stderr ,"draft_ban_test: %s\n" ,what ); std::exit (1 ); } 13 }; 14const int32_t dvocab []= {3 ,7 ,1 ,9 ,5 };// column i drafts token dvocab[i] 15 std::vector < float > bias ; 16 std::string err ; 17 18check (draft_ban_columns (bias ,dvocab ,5 ).empty (),"no bias must mask nothing" ); 19check (draft_ban_columns (bias ,nullptr ,0 ).empty (),"no bias must mask nothing (full head)" ); 20 21check (strata::core::parse_logit_bias ("2:1.5,7:-99.5,9:100" ,10 ,bias ,err ),"parse finite" ); 22check (draft_ban_columns (bias ,dvocab ,5 ).empty (),"a finite bias must leave the drafter unchanged" ); 23check (draft_ban_columns (bias ,nullptr ,0 ).empty (),"a finite bias must leave the full head unchanged" ); 24 25check (strata::core::parse_logit_bias ("9:-100,0:-100,7:-100,5:2" ,10 ,bias ,err ),"parse bans" ); 26check (draft_ban_columns (bias ,dvocab ,5 )== std::vector < int32_t > {1 ,3 },"bans map to their subset columns" ); 27check (draft_ban_columns (bias ,nullptr ,0 )== std::vector < int32_t > {0 ,7 ,9 },"full head: columns are the ids" ); 28 29check (strata::core::parse_logit_bias ("0:-100,2:-100" ,10 ,bias ,err ),"parse bans outside the subset" ); 30check (draft_ban_columns (bias ,dvocab ,5 ).empty (),"a ban outside the draft vocabulary masks nothing" ); 31 32const int32_t odd []= {-1 ,12 ,0 };// ids the bias does not cover are never masked 33check (strata::core::parse_logit_bias ("0:-100" ,10 ,bias ,err ),"parse" ); 34check (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}