okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
fcb0c2d0e
main
1"""I7 (tools and images review, 2026-10-22): a picture reader without vision.max_tokens in its config was unclamped, and #3690 saw one 2picture become 93,700 image tokens. The server gives every reader a limit (GPU 1024, CPU 300) unless the config names one, and logs a 3picture that came back over 4 times the limit. 4 5python -m unittest serve.test_vision_token_limit 6""" 7import io 8import unittest 9from contextlib import redirect_stdout 10 11import serve .server as server 12 13BASE = {"exe" :"strata-vision" ,"mmproj" :"m.gguf" ,"model" :"t.gguf" } 14 15 16def limit_of (cfg ): 17args = server .Vision .reader_args (cfg ) 18return int (args [args .index ("--max-tokens" )+ 1 ])if "--max-tokens" in args else None 19 20 21class TokenLimit (unittest .TestCase ): 22def test_a_config_without_max_tokens_gets_the_default_of_its_kind (self ): 23self .assertEqual (limit_of ({** BASE ,"gpu" :True }),1024 ) 24self .assertEqual (limit_of ({** BASE ,"gpu" :False }),300 ) 25self .assertEqual (limit_of (dict (BASE )),300 ) 26 27def test_a_limit_the_person_set_is_kept_not_capped (self ): 28self .assertEqual (limit_of ({** BASE ,"gpu" :True ,"max_tokens" :4096 }),4096 ) 29self .assertEqual (limit_of ({** BASE ,"max_tokens" :"512" }),512 ) 30 31def test_zero_still_means_no_limit (self ): 32self .assertIsNone (limit_of ({** BASE ,"gpu" :True ,"max_tokens" :0 })) 33 34def test_an_unreadable_value_falls_back_to_the_default (self ): 35self .assertEqual (limit_of ({** BASE ,"gpu" :True ,"max_tokens" :"lots" }),1024 ) 36 37def test_min_tokens_is_unchanged (self ): 38args = server .Vision .reader_args ({** BASE ,"gpu" :True ,"min_tokens" :768 }) 39self .assertEqual (args [args .index ("--min-tokens" )+ 1 ],"768" ) 40 41 42class Warn (unittest .TestCase ): 43def reader (self ,limit ): 44v = server .Vision .__new__ (server .Vision ) 45v .max_tokens = limit 46return v 47 48def said (self ,limit ,tokens ): 49out = io .StringIO () 50with redirect_stdout (out ): 51self .reader (limit ).warn_if_over_limit (tokens ) 52return out .getvalue () 53 54def test_93700_tokens_under_a_1024_limit_is_logged_with_the_numbers (self ): 55text = self .said (1024 ,93700 ) 56self .assertIn ("93700 image tokens" ,text ) 57self .assertIn ("limit of 1024" ,text ) 58self .assertIn ("warmed up at N image tokens" ,text ) 59 60def test_a_picture_within_four_times_the_limit_is_quiet (self ): 61self .assertEqual (self .said (1024 ,1024 ),"" ) 62self .assertEqual (self .said (1024 ,4096 ),"" ) 63 64def test_no_limit_no_warning (self ): 65self .assertEqual (self .said (0 ,93700 ),"" ) 66v = server .Vision .__new__ (server .Vision )# a reader object made without the attribute (older tests) 67v .warn_if_over_limit (93700 ) 68 69 70if __name__ == "__main__" : 71unittest .main ()