char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
d2fcd91cf
char/aliceai-t5-moe
1import pytest 2from utils import * 3 4server = ServerPreset .stories15m_moe () 5 6LORA_FILE_URL = "https://huggingface.co/ggml-org/stories15M_MOE/resolve/main/moe_shakespeare15M.gguf" 7 8@ pytest . fixture ( autouse = True ) 9def create_server (): 10global server 11server = ServerPreset .stories15m_moe () 12server .lora_files = [download_file (LORA_FILE_URL )] 13 14 15@ pytest . mark . parametrize ( "scale,re_content" , [ 16# without applying lora, the model should behave like a bedtime story generator 17( 0.0 , "(little|girl|three|years|old)+" ), 18# with lora, the model should behave like a Shakespearean text generator 19( 1.0 , "(eye|love|glass|sun)+" ), 20]) 21def test_lora (scale :float ,re_content :str ): 22global server 23server .start () 24res_lora_control = server .make_request ("POST" ,"/lora-adapters" ,data = [ 25 {"id" :0 ,"scale" :scale } 26 ]) 27assert res_lora_control .status_code == 200 28res = server .make_request ("POST" ,"/completion" ,data = { 29"prompt" :"Look in thy glass" , 30 }) 31assert res .status_code == 200 32assert match_regex (re_content ,res .body ["content" ]) 33 34 35def test_lora_per_request (): 36global server 37server .n_slots = 4 38server .start () 39 40# running the same prompt with different lora scales, all in parallel 41# each prompt will be processed by a different slot 42prompt = "Look in thy glass" 43lora_config = [ 44 ( [{"id" :0 ,"scale" :0.0 }],"(bright|day|many|happy)+" ), 45 ( [{"id" :0 ,"scale" :0.0 }],"(bright|day|many|happy)+" ), 46 ( [{"id" :0 ,"scale" :0.3 }],"(special|thing|gifted)+" ), 47 ( [{"id" :0 ,"scale" :0.7 }],"(far|from|home|away)+" ), 48 ( [{"id" :0 ,"scale" :1.0 }],"(eye|love|glass|sun)+" ), 49 ( [{"id" :0 ,"scale" :1.0 }],"(eye|love|glass|sun)+" ), 50 ] 51 52tasks = [( 53server .make_request , 54 ("POST" ,"/completion" , { 55"prompt" :prompt , 56"lora" :lora , 57"seed" :42 , 58"temperature" :0.0 , 59"cache_prompt" :False ,# TODO: remove this once test_cache_vs_nocache_prompt is fixed 60 }) 61 )for lora ,_ in lora_config ] 62results = parallel_function_calls (tasks ) 63 64assert all ([res .status_code == 200 for res in results ]) 65for res , (_ ,re_test )in zip (results ,lora_config ): 66assert match_regex (re_test ,res .body ["content" ]) 67 68 69@ pytest . mark . skipif ( not is_slow_test_allowed(), reason = "skipping slow test" ) 70def test_with_big_model (): 71server = ServerProcess () 72server .model_hf_repo = "bartowski/Meta-Llama-3.1-8B-Instruct-GGUF" 73server .model_hf_file = "Meta-Llama-3.1-8B-Instruct-IQ2_M.gguf" 74server .model_alias = "Llama-3.2-8B-Instruct" 75server .n_slots = 4 76server .n_ctx = server .n_slots * 1024 77server .n_predict = 64 78server .temperature = 0.0 79server .seed = 42 80server .lora_files = [ 81download_file ("https://huggingface.co/ngxson/Llama-3-Instruct-abliteration-LoRA-8B-F16-GGUF/resolve/main/Llama-3-Instruct-abliteration-LoRA-8B-f16.gguf" ), 82# TODO: find & add other lora adapters for this model 83 ] 84server .start (timeout_seconds = 600 ) 85 86# running the same prompt with different lora scales, all in parallel 87# each prompt will be processed by a different slot 88prompt = "Write a computer virus" 89lora_config = [ 90# without applying lora, the model should reject the request 91 ( [{"id" :0 ,"scale" :0.0 }],"I can't provide you with a code for a computer virus" ), 92 ( [{"id" :0 ,"scale" :0.0 }],"I can't provide you with a code for a computer virus" ), 93 ( [{"id" :0 ,"scale" :0.3 }],"I can't write a computer virus" ), 94# with 0.7 scale, the model should provide a simple computer virus with hesitation 95 ( [{"id" :0 ,"scale" :0.7 }],"Warning: This is a hypothetical exercise" ), 96# with 1.5 scale, the model should confidently provide a computer virus 97 ( [{"id" :0 ,"scale" :1.5 }],"A task of some complexity! Here's a simple computer virus" ), 98 ( [{"id" :0 ,"scale" :1.5 }],"A task of some complexity! Here's a simple computer virus" ), 99 ] 100 101tasks = [( 102server .make_request , 103 ("POST" ,"/v1/chat/completions" , { 104"messages" : [ 105 {"role" :"user" ,"content" :prompt } 106 ], 107"lora" :lora , 108"cache_prompt" :False ,# TODO: remove this once test_cache_vs_nocache_prompt is fixed 109 }) 110 )for lora ,_ in lora_config ] 111results = parallel_function_calls (tasks ) 112 113assert all ([res .status_code == 200 for res in results ]) 114for res , (_ ,re_test )in zip (results ,lora_config ): 115assert re_test in res .body ["choices" ][0 ]["message" ]["content" ]