@@ -69,6 +69,7 @@ static const char * const LLM_KV_QUANTIZE_IMATRIX_FILE = "quantize.imatrix
6969static const char * const LLM_KV_QUANTIZE_IMATRIX_DATASET = " quantize.imatrix.dataset" ;
7070static const char * const LLM_KV_QUANTIZE_IMATRIX_N_ENTRIES = " quantize.imatrix.entries_count" ;
7171static const char * const LLM_KV_QUANTIZE_IMATRIX_N_CHUNKS = " quantize.imatrix.chunks_count" ;
72+ static const char * const LLM_KV_QUANTIZE_IMATRIX_PRIOR_W = " quantize.imatrix.prior_weight" ;
7273
7374// TODO: share with imatrix.cpp
7475static const char * const LLM_KV_IMATRIX_DATASETS = " imatrix.datasets" ;
@@ -214,7 +215,7 @@ static int load_legacy_imatrix(const std::string & imatrix_file, std::vector<std
214215 return m_last_call;
215216}
216217
217- static int load_imatrix (const std::string & imatrix_file, std::vector<std::string> & imatrix_datasets, std::unordered_map<std::string, std::vector<float >> & imatrix_data, float prior_weight) {
218+ static int load_imatrix (const std::string & imatrix_file, std::vector<std::string> & imatrix_datasets, std::unordered_map<std::string, std::vector<float >> & imatrix_data, float & prior_weight) {
218219
219220 struct ggml_context * ctx = nullptr ;
220221 struct gguf_init_params meta_gguf_params = {
@@ -224,6 +225,7 @@ static int load_imatrix(const std::string & imatrix_file, std::vector<std::strin
224225 struct gguf_context * ctx_gguf = gguf_init_from_file (imatrix_file.c_str (), meta_gguf_params);
225226 if (!ctx_gguf) {
226227 fprintf (stderr, " %s: imatrix file '%s' is using old format\n " , __func__, imatrix_file.c_str ());
228+ prior_weight = 0 .0f ; // can't use a prior weight without having proper activation counts
227229 return load_legacy_imatrix (imatrix_file, imatrix_datasets, imatrix_data);
228230 }
229231 const int32_t n_entries = gguf_get_n_tensors (ctx_gguf);
@@ -333,7 +335,7 @@ static int prepare_imatrix(const std::string & imatrix_file,
333335 const std::vector<std::string> & included_weights,
334336 const std::vector<std::string> & excluded_weights,
335337 std::unordered_map<std::string, std::vector<float >> & imatrix_data,
336- float prior_weight) {
338+ float & prior_weight) {
337339 int m_last_call = -1 ;
338340 if (!imatrix_file.empty ()) {
339341 m_last_call = load_imatrix (imatrix_file, imatrix_dataset, imatrix_data, prior_weight);
@@ -574,6 +576,14 @@ int main(int argc, char ** argv) {
574576 kvo.val_i64 = m_last_call;
575577 kv_overrides.emplace_back (std::move (kvo));
576578 }
579+
580+ {
581+ llama_model_kv_override kvo;
582+ std::strcpy (kvo.key , LLM_KV_QUANTIZE_IMATRIX_PRIOR_W);
583+ kvo.tag = LLAMA_KV_OVERRIDE_TYPE_FLOAT;
584+ kvo.val_f64 = prior_weight;
585+ kv_overrides.emplace_back (std::move (kvo));
586+ }
577587 }
578588 if (!kv_overrides.empty ()) {
579589 kv_overrides.emplace_back ();
0 commit comments