2929
3030#define ST_HEADER_SIZE_LEN 8
3131
32- static IMatrixCollector* imatrix_collector = NULL ;
32+ static IMatrixCollector imatrix_collector;
3333
3434uint64_t read_u64 (uint8_t * buffer) {
3535 // little endian
@@ -1842,7 +1842,7 @@ bool ModelLoader::load_tensors(on_new_tensor_cb_t on_new_tensor_cb, ggml_backend
18421842
18431843 auto processed_name = convert_tensor_name (tensor_storage.name );
18441844 // LOG_DEBUG("%s",processed_name.c_str());
1845- std::vector<float > imatrix = imatrix_collector ? imatrix_collector-> get_values (processed_name) : std::vector< float >{} ;
1845+ std::vector<float > imatrix = imatrix_collector. get_values (processed_name);
18461846
18471847 convert_tensor ((void *)read_buffer.data (), tensor_storage.type , dst_tensor->data ,
18481848 dst_tensor->type , (int )tensor_storage.nelements () / (int )tensor_storage.ne [0 ], (int )tensor_storage.ne [0 ], imatrix);
@@ -1869,7 +1869,7 @@ bool ModelLoader::load_tensors(on_new_tensor_cb_t on_new_tensor_cb, ggml_backend
18691869 // convert first, then copy to device memory
18701870 auto processed_name = convert_tensor_name (tensor_storage.name );
18711871 // LOG_DEBUG("%s",processed_name.c_str());
1872- std::vector<float > imatrix = imatrix_collector ? imatrix_collector-> get_values (processed_name) : std::vector< float >{} ;
1872+ std::vector<float > imatrix = imatrix_collector. get_values (processed_name);
18731873
18741874 convert_buffer.resize (ggml_nbytes (dst_tensor));
18751875 convert_tensor ((void *)read_buffer.data (), tensor_storage.type ,
@@ -2069,10 +2069,6 @@ int64_t ModelLoader::get_params_mem_size(ggml_backend_t backend, ggml_type type)
20692069 return mem_size;
20702070}
20712071
2072- void setConvertImatrixCollector (void * collector) {
2073- imatrix_collector = ((IMatrixCollector*)collector);
2074- }
2075-
20762072bool convert (const char * model_path, const char * clip_l_path, const char * clip_g_path, const char * t5xxl_path, const char * diffusion_model_path, const char * vae_path, const char * output_path, sd_type_t output_type) {
20772073 ModelLoader model_loader;
20782074
@@ -2120,3 +2116,19 @@ bool convert(const char* model_path, const char* clip_l_path, const char* clip_g
21202116 bool success = model_loader.save_to_gguf_file (output_path, (ggml_type)output_type);
21212117 return success;
21222118}
2119+
2120+ bool loadImatrix (const char * imatrix_path) {
2121+ return imatrix_collector.load_imatrix (imatrix_path);
2122+ }
2123+ void saveImatrix (const char * imatrix_path) {
2124+ imatrix_collector.save_imatrix (imatrix_path);
2125+ }
2126+ static bool collect_imatrix (struct ggml_tensor * t, bool ask, void * user_data) {
2127+ return imatrix_collector.collect_imatrix (t, ask, user_data);
2128+ }
2129+ void enableImatrixCollection () {
2130+ sd_set_backend_eval_callback ((sd_graph_eval_callback_t )collect_imatrix, NULL );
2131+ }
2132+ void disableImatrixCollection () {
2133+ sd_set_backend_eval_callback (NULL , NULL );
2134+ }
0 commit comments