@@ -163,13 +163,38 @@ static void llama_adapter_lora_init_impl(llama_model & model, const char * path_
163163
164164 // check metadata
165165 {
166+ const gguf_context * gguf_ctx = ctx_gguf.get ();
167+
168+ LLAMA_LOG_INFO (" %s: Dumping metadata keys/values.\n " , __func__);
169+
170+ // get metadata as string
171+ for (int i = 0 ; i < gguf_get_n_kv (gguf_ctx); i++) {
172+ gguf_type type = gguf_get_kv_type (gguf_ctx, i);
173+ const std::string type_name =
174+ type == GGUF_TYPE_ARRAY
175+ ? format (" %s[%s,%zu]" , gguf_type_name (type), gguf_type_name (gguf_get_arr_type (gguf_ctx, i)), gguf_get_arr_n (gguf_ctx, i))
176+ : gguf_type_name (type);
177+ const char * name = gguf_get_key (gguf_ctx, i);
178+ const std::string value = gguf_kv_to_str (gguf_ctx, i);
179+
180+ if (type != GGUF_TYPE_ARRAY) {
181+ adapter.gguf_kv .emplace (name, value);
182+ }
183+
184+ const size_t MAX_VALUE_LEN = 40 ;
185+ std::string print_value = value.size () > MAX_VALUE_LEN ? format (" %s..." , value.substr (0 , MAX_VALUE_LEN - 3 ).c_str ()) : value;
186+ replace_all (print_value, " \n " , " \\ n" );
187+
188+ LLAMA_LOG_INFO (" %s: - kv %3d: %42s %-16s = %s\n " , __func__, i, name, type_name.c_str (), print_value.c_str ());
189+ }
190+
166191 auto get_kv_str = [&](const std::string & key) -> std::string {
167- int id = gguf_find_key (ctx_gguf. get () , key.c_str ());
168- return id < 0 ? " " : std::string (gguf_get_val_str (ctx_gguf. get () , id));
192+ int id = gguf_find_key (gguf_ctx , key.c_str ());
193+ return id < 0 ? " " : std::string (gguf_get_val_str (gguf_ctx , id));
169194 };
170195 auto get_kv_f32 = [&](const std::string & key) -> float {
171- int id = gguf_find_key (ctx_gguf. get () , key.c_str ());
172- return id < 0 ? 0 .0f : gguf_get_val_f32 (ctx_gguf. get () , id);
196+ int id = gguf_find_key (gguf_ctx , key.c_str ());
197+ return id < 0 ? 0 .0f : gguf_get_val_f32 (gguf_ctx , id);
173198 };
174199 LLM_KV llm_kv = LLM_KV (LLM_ARCH_UNKNOWN);
175200
@@ -190,8 +215,6 @@ static void llama_adapter_lora_init_impl(llama_model & model, const char * path_
190215 }
191216
192217 adapter.alpha = get_kv_f32 (llm_kv (LLM_KV_ADAPTER_LORA_ALPHA));
193- adapter.task_name = get_kv_str (llm_kv (LLM_KV_ADAPTER_LORA_TASK_NAME));
194- adapter.prompt_prefix = get_kv_str (llm_kv (LLM_KV_ADAPTER_LORA_PROMPT_PREFIX));
195218 }
196219
197220 int n_tensors = gguf_get_n_tensors (ctx_gguf.get ());
@@ -385,12 +408,43 @@ llama_adapter_lora * llama_adapter_lora_init(llama_model * model, const char * p
385408 return nullptr ;
386409}
387410
388- const char * llama_adapter_lora_task_name (llama_adapter_lora * adapter) {
389- return adapter->task_name .c_str ();
411+ int32_t llama_adapter_meta_val_str (const llama_adapter_lora * adapter, const char * key, char * buf, size_t buf_size) {
412+ const auto & it = adapter->gguf_kv .find (key);
413+ if (it == adapter->gguf_kv .end ()) {
414+ if (buf_size > 0 ) {
415+ buf[0 ] = ' \0 ' ;
416+ }
417+ return -1 ;
418+ }
419+ return snprintf (buf, buf_size, " %s" , it->second .c_str ());
390420}
391421
392- const char * llama_adapter_lora_prompt_prefix (llama_adapter_lora * adapter) {
393- return adapter->prompt_prefix .c_str ();
422+ int32_t llama_adapter_meta_count (const llama_adapter_lora * adapter) {
423+ return (int )adapter->gguf_kv .size ();
424+ }
425+
426+ int32_t llama_adapter_meta_key_by_index (const llama_adapter_lora * adapter, int i, char * buf, size_t buf_size) {
427+ if (i < 0 || i >= (int )adapter->gguf_kv .size ()) {
428+ if (buf_size > 0 ) {
429+ buf[0 ] = ' \0 ' ;
430+ }
431+ return -1 ;
432+ }
433+ auto it = adapter->gguf_kv .begin ();
434+ std::advance (it, i);
435+ return snprintf (buf, buf_size, " %s" , it->first .c_str ());
436+ }
437+
438+ int32_t llama_adapter_meta_val_str_by_index (const llama_adapter_lora * adapter, int32_t i, char * buf, size_t buf_size) {
439+ if (i < 0 || i >= (int )adapter->gguf_kv .size ()) {
440+ if (buf_size > 0 ) {
441+ buf[0 ] = ' \0 ' ;
442+ }
443+ return -1 ;
444+ }
445+ auto it = adapter->gguf_kv .begin ();
446+ std::advance (it, i);
447+ return snprintf (buf, buf_size, " %s" , it->second .c_str ());
394448}
395449
396450void llama_adapter_lora_free (llama_adapter_lora * adapter) {
0 commit comments