3333
3434#define ST_HEADER_SIZE_LEN 8
3535
36- static IMatrixCollector* imatrix_collector = NULL ;
36+ static IMatrixCollector imatrix_collector;
3737
3838uint64_t read_u64 (uint8_t * buffer) {
3939 // little endian
@@ -1984,7 +1984,7 @@ bool ModelLoader::load_tensors(on_new_tensor_cb_t on_new_tensor_cb, ggml_backend
19841984
19851985 auto processed_name = convert_tensor_name (tensor_storage.name );
19861986 // LOG_DEBUG("%s",processed_name.c_str());
1987- std::vector<float > imatrix = imatrix_collector ? imatrix_collector-> get_values (processed_name) : std::vector< float >{} ;
1987+ std::vector<float > imatrix = imatrix_collector. get_values (processed_name);
19881988
19891989 convert_tensor ((void *)read_buffer.data (), tensor_storage.type , dst_tensor->data ,
19901990 dst_tensor->type , (int )tensor_storage.nelements () / (int )tensor_storage.ne [0 ], (int )tensor_storage.ne [0 ], imatrix);
@@ -2011,7 +2011,7 @@ bool ModelLoader::load_tensors(on_new_tensor_cb_t on_new_tensor_cb, ggml_backend
20112011 // convert first, then copy to device memory
20122012 auto processed_name = convert_tensor_name (tensor_storage.name );
20132013 // LOG_DEBUG("%s",processed_name.c_str());
2014- std::vector<float > imatrix = imatrix_collector ? imatrix_collector-> get_values (processed_name) : std::vector< float >{} ;
2014+ std::vector<float > imatrix = imatrix_collector. get_values (processed_name);
20152015
20162016 convert_buffer.resize (ggml_nbytes (dst_tensor));
20172017 convert_tensor ((void *)read_buffer.data (), tensor_storage.type ,
@@ -2263,10 +2263,6 @@ int64_t ModelLoader::get_params_mem_size(ggml_backend_t backend, ggml_type type)
22632263 return mem_size;
22642264}
22652265
2266- void setConvertImatrixCollector (void * collector) {
2267- imatrix_collector = ((IMatrixCollector*)collector);
2268- }
2269-
22702266bool 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, const char * tensor_type_rules) {
22712267 ModelLoader model_loader;
22722268
@@ -2314,3 +2310,19 @@ bool convert(const char* model_path, const char* clip_l_path, const char* clip_g
23142310 bool success = model_loader.save_to_gguf_file (output_path, (ggml_type)output_type, tensor_type_rules);
23152311 return success;
23162312}
2313+
2314+ bool loadImatrix (const char * imatrix_path) {
2315+ return imatrix_collector.load_imatrix (imatrix_path);
2316+ }
2317+ void saveImatrix (const char * imatrix_path) {
2318+ imatrix_collector.save_imatrix (imatrix_path);
2319+ }
2320+ static bool collect_imatrix (struct ggml_tensor * t, bool ask, void * user_data) {
2321+ return imatrix_collector.collect_imatrix (t, ask, user_data);
2322+ }
2323+ void enableImatrixCollection () {
2324+ sd_set_backend_eval_callback ((sd_graph_eval_callback_t )collect_imatrix, NULL );
2325+ }
2326+ void disableImatrixCollection () {
2327+ sd_set_backend_eval_callback (NULL , NULL );
2328+ }
0 commit comments