From e91cfd5ac406386a04df58fcc47af10bc1af0b3c Mon Sep 17 00:00:00 2001 From: ayushmk7 Date: Mon, 14 Sep 2026 19:25:47 -0400 Subject: [PATCH 1/2] Fix media prefill sequence length for full-context encoder shapes set_sequence_length_in_shape only rewrote a sequence dimension equal to 1. lm_encoder outputs are now reported at full context (e.g. [1, 128000, 1024]), so the stored inputs_embeds shape kept 128000 and run_chunk_prefill_path ran about 1000 decoder_prefill_chunk passes for a ~1k-token image prompt. On Metal this looks like a hang in waitUntilCompleted; on CPU it spins at full load. Write the dimension that sequence_length_from_shape reads. Fixes #802 Signed-off-by: ayushmk7 --- cactus-engine/src/model.cpp | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/cactus-engine/src/model.cpp b/cactus-engine/src/model.cpp index 2fc60d1e4..7f0430d0c 100644 --- a/cactus-engine/src/model.cpp +++ b/cactus-engine/src/model.cpp @@ -2098,17 +2098,9 @@ size_t sequence_length_from_shape(const std::vector& shape) { void set_sequence_length_in_shape(std::vector& shape, size_t sequence_length) { if (shape.empty()) return; - if (shape.size() >= 2 && shape[0] == 1 && shape[1] == 1) { - shape[1] = sequence_length; - return; - } - if (shape.size() >= 2 && shape[shape.size() - 2] == 1) { - shape[shape.size() - 2] = sequence_length; - return; - } - if (shape.size() == 1 && shape[0] == 1) { - shape[0] = sequence_length; - } + if (shape.size() >= 2 && shape[0] == 1) shape[1] = sequence_length; + else if (shape.size() >= 2) shape[shape.size() - 2] = sequence_length; + else shape[0] = sequence_length; } std::string Model::image_preprocess_strategy() const { From 972bc7db4ef82144a983eaa8501709ed3b76b650 Mon Sep 17 00:00:00 2001 From: ayushmk7 Date: Mon, 14 Sep 2026 19:26:11 -0400 Subject: [PATCH 2/2] Default LFM2-VL bundles without a media strategy to lfm2_vl Published LFM2-VL bundles (weights tag v2.0) predate the media_image_preprocess_strategy manifest key. With it empty the engine preprocessed images through the Gemma 4 path, skipped the vision projector and never spliced image features, and the tokenizer fell back to a single 1024-token tile. Completions ran but ignored the image. Fall back to lfm2_vl when the key is missing and the manifest family is lfm2_vl. Signed-off-by: ayushmk7 --- cactus-engine/src/model.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/cactus-engine/src/model.cpp b/cactus-engine/src/model.cpp index 7f0430d0c..c62715cd0 100644 --- a/cactus-engine/src/model.cpp +++ b/cactus-engine/src/model.cpp @@ -936,6 +936,7 @@ bool Model::load_manifest() { return ""; }; image_preprocess_strategy_ = read_string_key("media_image_preprocess_strategy"); + if (image_preprocess_strategy_.empty() && family_ == "lfm2_vl") image_preprocess_strategy_ = "lfm2_vl"; audio_preprocess_strategy_ = read_string_key("media_audio_preprocess_strategy"); media_injection_strategy_ = read_string_key("media_injection_strategy"); media_prefill_fallback_ = read_string_key("media_prefill_fallback");