okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
54d7f7d7c
main
1#include "strata/core/logit_bias.hpp" 2#include <cstdio> 3#include <cstdlib> 4 5int main () { 6 std::vector < float > b ; 7 std::string err ; 8auto check = [](bool ok ) {if (!ok ) { std::fprintf (stderr ,"logit_bias parser regression\n" ); std::exit (1 ); } }; 9check (strata::core::parse_logit_bias ("0:-100,2:1.25,3:-0.5" ,4 ,b ,err )); 10check (b .size ()== 4 && std::isinf (b [0 ])&& b [0 ]< 0 && b [1 ]== 0 && b [2 ]== 1.25f && b [3 ]== -0.5f ); 11for (const char * text : {"" ,"0:" ,"0:NaN" ,"0:inf" ,"0:-101" ,"0:101" ,"4:0" ,"-1:0" ,"x:1" , 12"0:1," ,"0:1,0:2" ,"0:1x" ,"0:-100,1:-100,2:-100,3:-100" ,"999999999999999999999:0" }) { 13check (!strata::core::parse_logit_bias (text ,4 ,b ,err )); 14check (b .empty ()); 15 } 16 std::string large ; 17for (int i = 0 ;i < 103215 ;++ i ) {if (i )large += ',' ;large += std::to_string (i )+ ":-100" ; } 18check (strata::core::parse_logit_bias (large ,248320 ,b ,err )); 19check (std::isinf (b [103214 ])&& b [103215 ]== 0 && b .size ()== 248320 ); 20 std::puts ("logit_bias_test: passed, including 103215 bans" ); 21}