Skip to content

Commit a5a8737

Browse files
committed
Read interleaved_n_text/interleaved_n_audio from config [noci]
1 parent 006639c commit a5a8737

2 files changed

Lines changed: 25 additions & 3 deletions

File tree

tools/liquid-audio/convert_vocoder_to_gguf.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,15 @@ def __init__(
6262
"depthformer_n_embd",
6363
config_json["depthformer"]["dim"],
6464
)
65+
# interleaved modality cadence; fall back to runtime defaults if absent
66+
self.gguf_writer.add_uint32(
67+
"interleaved_n_text",
68+
config_json.get("interleaved_n_text", 6),
69+
)
70+
self.gguf_writer.add_uint32(
71+
"interleaved_n_audio",
72+
config_json.get("interleaved_n_audio", 12),
73+
)
6574

6675
def load_tensors(self, path, predicate):
6776
tensors = {}

tools/mtmd/audio-decoder.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,15 @@ struct audio_decoder_ggml_ctx {
209209
return std::make_pair(t, data);
210210
}
211211

212+
// read an optional u32 hyperparameter, falling back if the key is absent
213+
uint32_t get_hparam_u32(const char * key, uint32_t fallback) const {
214+
auto key_id = gguf_find_key(ctx_gguf, key);
215+
if (key_id < 0) {
216+
return fallback;
217+
}
218+
return gguf_get_val_u32(ctx_gguf, key_id);
219+
}
220+
212221
ggml_tensor * get_weight(const char * fmt, ...) {
213222
std::vector<char> str(128);
214223
va_list va;
@@ -674,9 +683,10 @@ class audio_decoder_lfm25 : public mtmd_audio_decoder {
674683
// output modality switch
675684
std::vector<mtmd_output_modality> modalities;
676685

677-
static constexpr auto interleaved_n_text = 6;
678-
static constexpr auto interleaved_n_audio = 12;
679-
int modality_left = INT_MAX;
686+
// interleaved modality cadence, read from gguf with fallback defaults
687+
int interleaved_n_text = 6;
688+
int interleaved_n_audio = 12;
689+
int modality_left = INT_MAX;
680690

681691
// sampling
682692
llama_sampler_ptr smpl;
@@ -688,6 +698,9 @@ class audio_decoder_lfm25 : public mtmd_audio_decoder {
688698
ctx(use_gpu) {
689699
ctx.load_gguf(vocoder_path.c_str());
690700

701+
interleaved_n_text = ctx.get_hparam_u32("interleaved_n_text", interleaved_n_text);
702+
interleaved_n_audio = ctx.get_hparam_u32("interleaved_n_audio", interleaved_n_audio);
703+
691704
decoder_model.init(ctx);
692705

693706
// audio tokenizer

0 commit comments

Comments
 (0)