29
29
30
30
#define ST_HEADER_SIZE_LEN 8
31
31
32
- static IMatrixCollector* imatrix_collector = NULL ;
32
+ static IMatrixCollector imatrix_collector;
33
33
34
34
uint64_t read_u64 (uint8_t * buffer) {
35
35
// little endian
@@ -1842,7 +1842,7 @@ bool ModelLoader::load_tensors(on_new_tensor_cb_t on_new_tensor_cb, ggml_backend
1842
1842
1843
1843
auto processed_name = convert_tensor_name (tensor_storage.name );
1844
1844
// 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);
1846
1846
1847
1847
convert_tensor ((void *)read_buffer.data (), tensor_storage.type , dst_tensor->data ,
1848
1848
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
1869
1869
// convert first, then copy to device memory
1870
1870
auto processed_name = convert_tensor_name (tensor_storage.name );
1871
1871
// 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);
1873
1873
1874
1874
convert_buffer.resize (ggml_nbytes (dst_tensor));
1875
1875
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)
2069
2069
return mem_size;
2070
2070
}
2071
2071
2072
- void setConvertImatrixCollector (void * collector) {
2073
- imatrix_collector = ((IMatrixCollector*)collector);
2074
- }
2075
-
2076
2072
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) {
2077
2073
ModelLoader model_loader;
2078
2074
@@ -2120,3 +2116,19 @@ bool convert(const char* model_path, const char* clip_l_path, const char* clip_g
2120
2116
bool success = model_loader.save_to_gguf_file (output_path, (ggml_type)output_type);
2121
2117
return success;
2122
2118
}
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