From b75ecd1971bf2d3f29d5d334520868a01942cbc6 Mon Sep 17 00:00:00 2001 From: Tarek Dakhran Date: Mon, 17 Aug 2026 19:41:32 +0200 Subject: [PATCH] mtmd : skip thumbnail for non-tiled LFM2 images (#27246) * mtmd : skip thumbnail for non-tiled LFM2 images Matches HF behavior. * Update tools/mtmd/mtmd-image.cpp --------- Co-authored-by: Xuan-Son Nguyen --- tools/mtmd/mtmd-image.cpp | 14 ++++++++++++++ tools/mtmd/mtmd-image.h | 1 + 2 files changed, 15 insertions(+) diff --git a/tools/mtmd/mtmd-image.cpp b/tools/mtmd/mtmd-image.cpp index d4b5ec0d9..769b6efe6 100644 --- a/tools/mtmd/mtmd-image.cpp +++ b/tools/mtmd/mtmd-image.cpp @@ -999,6 +999,20 @@ mtmd_image_preprocessor_llava_uhd::slice_instructions mtmd_image_preprocessor_mi // mtmd_image_preprocessor_lfm2 // +mtmd_image_preproc_out mtmd_image_preprocessor_lfm2::preprocess(const clip_image_u8 & img) { + auto const inst = get_slice_instructions(img.get_size()); + if (!inst.slices.empty()) { + return mtmd_image_preprocessor_llava_uhd::preprocess(img); + } + + // single tile: no thumbnail + // note: not using output.overview here because it will emit <|img_thumbnail|> token, which we don't want in this case + auto sliced = slice_image(img, inst); + mtmd_image_preproc_out output; + output.append(hparams, sliced.overview, true); + return output; +} + mtmd_image_preprocessor_llava_uhd::slice_instructions mtmd_image_preprocessor_lfm2::get_slice_instructions(const clip_image_size & original_size) { mtmd_image_preprocessor_llava_uhd::slice_instructions inst; const int align_size = hparams.patch_size * hparams.n_merge; diff --git a/tools/mtmd/mtmd-image.h b/tools/mtmd/mtmd-image.h index 238332934..40dfea7eb 100644 --- a/tools/mtmd/mtmd-image.h +++ b/tools/mtmd/mtmd-image.h @@ -145,6 +145,7 @@ struct mtmd_image_preprocessor_lfm2 : mtmd_image_preprocessor_llava_uhd { static constexpr int tile_size = 512; using mtmd_image_preprocessor_llava_uhd::mtmd_image_preprocessor_llava_uhd; + mtmd_image_preproc_out preprocess(const clip_image_u8 & img) override; slice_instructions get_slice_instructions(const clip_image_size & original_size) override; private: