33
33
34
34
#define ST_HEADER_SIZE_LEN 8
35
35
36
- static IMatrixCollector* imatrix_collector = NULL ;
36
+ static IMatrixCollector imatrix_collector;
37
37
38
38
uint64_t read_u64 (uint8_t * buffer) {
39
39
// little endian
@@ -1984,7 +1984,7 @@ bool ModelLoader::load_tensors(on_new_tensor_cb_t on_new_tensor_cb, ggml_backend
1984
1984
1985
1985
auto processed_name = convert_tensor_name (tensor_storage.name );
1986
1986
// 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);
1988
1988
1989
1989
convert_tensor ((void *)read_buffer.data (), tensor_storage.type , dst_tensor->data ,
1990
1990
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
2011
2011
// convert first, then copy to device memory
2012
2012
auto processed_name = convert_tensor_name (tensor_storage.name );
2013
2013
// 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);
2015
2015
2016
2016
convert_buffer.resize (ggml_nbytes (dst_tensor));
2017
2017
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)
2263
2263
return mem_size;
2264
2264
}
2265
2265
2266
- void setConvertImatrixCollector (void * collector) {
2267
- imatrix_collector = ((IMatrixCollector*)collector);
2268
- }
2269
-
2270
2266
bool 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) {
2271
2267
ModelLoader model_loader;
2272
2268
@@ -2314,3 +2310,19 @@ bool convert(const char* model_path, const char* clip_l_path, const char* clip_g
2314
2310
bool success = model_loader.save_to_gguf_file (output_path, (ggml_type)output_type, tensor_type_rules);
2315
2311
return success;
2316
2312
}
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