char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
47f686f53
char/aliceai-t5-moe
1// ref: https://github.com/ggml-org/llama.cpp/issues/25937 2// only works reliably when run with a large model that occupies 3GB+ of wired memory 3// thus, this test is not run by default 4// example model to run with: google/gemma-4-E4B-it-qat-q4_0-gguf 5 6#include "llama.h" 7#include "common.h" 8 9#include <cstdint> 10#include <mach/mach.h> 11#include <mach/mach_host.h> 12#include <unistd.h> 13 14static uint64_t wired_memory () { 15vm_statistics64_data_t vmstat ; 16mach_msg_type_number_t count = HOST_VM_INFO64_COUNT ; 17if (host_statistics64 (mach_host_self (),HOST_VM_INFO64 , (host_info64_t )& vmstat ,& count )!= KERN_SUCCESS ) { 18return UINT64_MAX ; 19 } 20return static_cast < uint64_t > (vmstat .wire_count )* vm_kernel_page_size ; 21} 22 23int main (int argc ,char ** argv ) { 24auto * model_path = common_get_model_or_exit (argc ,argv ); 25 26llama_backend_init (); 27 28const uint64_t wired_initial = wired_memory (); 29 30llama_model_params params = llama_model_default_params (); 31params .load_mode = LLAMA_LOAD_MODE_NONE ; 32struct llama_model * model = llama_model_load_from_file (model_path ,params ); 33 34const uint64_t wired_loaded = wired_memory (); 35const uint64_t wired_delta = wired_loaded - wired_initial ; 36// system memory fluctuates, so we need to allocate enough to reliably detect the release 37GGML_ASSERT (wired_delta > 2'000'000'000 );// 2GB 38 39llama_model_free (model ); 40 41const uint64_t t_start_ms = ggml_time_ms (); 42 43// expect most of the allocated memory to be released within 10 seconds 44// we allow for some tolerance due to system-wide memory fluctuations 45while (wired_memory ()> wired_loaded - 0.75 * wired_delta ) { 46GGML_ASSERT (ggml_time_ms ()- t_start_ms < 10'000 ); 47usleep (100'000 );// 100ms 48 } 49 50llama_backend_free (); 51 52return 0 ; 53}