LFM2.5-VL-3B-MNN

Introduction

LFM2.5-VL-3B-MNN is an MNN-format export of LiquidAI/LFM2.5-VL-3B β€” a 3B-parameter language foundation model with native image understanding. The checkpoint was converted with llmexport and runs on the MNN runtime (llm engine + visual encoder) on Android, iOS, Linux and Windows, on CPU.

The LLM is a hybrid: 30 layers, hidden size 2048, interleaving short-convolution layers (attn_type: short_conv) with full attention layers; word embeddings are tied with the output projection, so the export keeps a single tied embedding table β€” no separate lm_head weights.

The vision side is a SigLIP2 ViT (27 layers, hidden 1152, patch-16 as a linear projection, learned 16Γ—16 positional embeddings). The processor tiles the image: every image is first resized to a 512Γ—512 global view and additionally split into 512Γ—512 tiles (up to 10 tiles + 1 thumbnail); the projector downsamples patches 2Γ—2, so each view contributes 256 tokens to the LLM sequence.

Quantization applied during export:

Part Quant Block Notes
LLM linear weights 4-bit 64 HQQ calibration, alpha stored in fp16
Embedding / lm_head (tied) 4-bit 64 one shared table, --seperate_embed not used
Vision tower + projector 8-bit 128 visual.mnn.weight

Total download size is β‰ˆ 1.97 GB (1,972,599,457 bytes).

Note: config.json/llm_config.json sizes depend on line endings (git stores LF, the CRLF export is ~4% larger); the app rewrites both configs in place on first load, so do not gate llm_config.json on a fixed byte size in clients.

Files

File Size (bytes) Content
llm.mnn 1,442,192 LLM graph
llm.mnn.weight 1,518,038,622 LLM weights (4-bit, block 64)
visual.mnn 569,032 SigLIP2 encoder + projector graph
visual.mnn.weight 447,158,818 vision weights (8-bit, block 128)
tokenizer.mtok 5,385,965 tokenizer
llm_config.json 6,828 engine config: chat template, special tokens, vision_processor
config.json 661 runtime defaults (backend, threads, precision)

Vision contract in llm_config.json: is_visual: true, vision_processor = {version: 2, family: "lfm2_vl", input_layout: "native", output_layout: "tbc"}, image_size: 512, image_mean [127.5Γ—3], image_norm [1/127.5Γ—3]. Special tokens: image_token_id (image_pad) 124907 = <image>, vision_start 125009 = <|image_start|>, vision_end 125010 = <|image_end|>, global_image 125008 = <|img_thumbnail|>, plus the grid tokens <|img_row_N_col_M|> (1..10).

The chat template is the official LFM2.5 ChatML template with a thinking switch: with thinking on, the model opens a <think>…</think> block before the answer. The context window is 32768 positions.

⚠️ MNN 3.6.2 runtime requirements

This export needs two MNN 3.6.2 fixes to render prompts correctly. Both are small and upstream-friendly; without them every prompt renders without its content (the model receives an empty user turn) β€” for text and vision.

  1. Engine (C++, header-only): MNN's built-in mini Jinja engine (transformers/llm/engine/src/tokenizer/jinja.hpp) does not implement dict.get() / .items() β€” MethodCallExpr::evaluate falls through to return "" for any non-string method. The LFM2.5 template guards content with {%- if message.get("content") -%}, so the guard is always falsy and the user content is dropped. The fix is to add object-method support (get/items/keys/values) to MethodCallExpr::evaluate before the fallthrough return "";:

    // Object/dict methods (jinja: get/items/keys/values)
    if (obj_val.is_object()) {
        if (method == "get") {
            if (!args.empty()) {
                json k = args[0]->evaluate(context);
                if (k.is_string() && obj_val.contains(k.get<std::string>())) {
                    return obj_val[k.get<std::string>()];
                }
            }
            if (args.size() > 1) return args[1]->evaluate(context);
            return json();
        } else if (method == "items") {
            json arr = json::array();
            for (json::const_iterator it = obj_val.begin(); it != obj_val.end(); ++it) {
                json pair = json::array();
                pair.push_back(it.key());
                pair.push_back(it.value());
                arr.push_back(pair);
            }
            return arr;
        } else if (method == "keys") {
            json arr = json::array();
            for (json::const_iterator it = obj_val.begin(); it != obj_val.end(); ++it)
                arr.push_back(it.key());
            return arr;
        } else if (method == "values") {
            json arr = json::array();
            for (json::const_iterator it = obj_val.begin(); it != obj_val.end(); ++it)
                arr.push_back(it.value());
            return arr;
        }
    }
    

    Models whose templates use message['content'] subscripting (e.g. Qwen2.5-VL) are unaffected; only .get()-style templates (LFM2.5) hit this.

  2. Exporter (Python, transformers/llm/export/utils/vision.py, Lfm2VlVision):

    • load: the native checkpoint puts the encoder at model.visual.vision_model (a bare Siglip2VisionModel), not model.visual.vision_model.vision_model. Use self.vision_model = getattr(self.visual, 'vision_model', self.visual) (guarded by hasattr(self.visual, 'vision_model') and hasattr(self.visual.vision_model, 'embeddings')).
    • forward: the projector has no final layer_norm (only linear_1/linear_2), so guard it: ln = getattr(self.multi_modal_projector, 'layer_norm', None); return ln(pooled) if ln is not None else pooled.

    Export command used:

    python llmexport.py --path /path/to/LFM2.5-VL-3B --export mnn \
      --dst_path ./LFM2.5-VL-3B-MNN --quant_bit 4 --quant_block 64 --hqq \
      --visual_quant_bit 8 --visual_quant_block 128 --disable_transformer_c4
    

Download

Method 1

Use pip to install the MNN package, then export the upstream checkpoint yourself (with the exporter notes above):

pip install MNN

Method 2

Use the Hugging Face Python API:

from huggingface_hub import snapshot_download
snapshot_download(local_dir="./LFM2.5-VL-3B-MNN",
                  repo_type="model",
                  repo_id="Juxoola/LFM2.5-VL-3B-MNN")

Usage

Build MNN with LLM, vision and low-memory support, then run llm_demo against config.json:

cd MNN/build
cmake .. -DMNN_LOW_MEMORY=true -DMNN_CPU_WEIGHT_DEQUANT_GEMM=true \
         -DMNN_BUILD_LLM=true -DMNN_SUPPORT_TRANSFORMER_FUSE=true \
         -DMNN_BUILD_OPENCV=true -DMNN_IMGCODECS=true
make -j
./llm_demo /path/to/LFM2.5-VL-3B-MNN/config.json prompt.txt

Use the CPU backend. Image input goes through the OpenCV-enabled build (the runtime resizes the image into 512Γ—512 tiles). In prompts, reference a local file as <img>photo.jpg</img>; the engine's vision_processor performs the tiling automatically.

Measured performance

Desktop x86_64 host (MNN 3.6.2, CPU, 4 threads, llm_demo), single 720Γ—1280 photo (7 global + tile views, 280 prompt tokens):

  • vision encode β‰ˆ 6.3 s per photo (SigLIP2 tower, 8-bit);
  • prefill β‰ˆ 47 token/s, steady decode β‰ˆ 19.7–26 token/s;
  • plain text turn (21 prompt tokens): decode β‰ˆ 26 token/s.

The model reads text in photos correctly on this export (OCR-style answers come back verbatim, Russian text included).

Verified on Android (emulator x86_64 API 34, 8 cores, MNN 3.6.2 CPU backend, 4 threads, memory low; app ru.localassistant):

  • plain text turn (β‰ˆ730 prompt tokens incl. system prompt): prefill β‰ˆ 28 s, steady decode 6.3–7.3 token/s;
  • vision turn (720Γ—1280 photo β†’ seqLen 2676): vision encode + prefill β‰ˆ 102 s, decode 6.8 token/s, 128 tokens; the photo's printed text is read correctly (OCR content reproduced in the answer);
  • model load β‰ˆ 40 s, RSS β‰ˆ 2.3 GB.

Note: on Android keep the app in the foreground during generation β€” the OS process freezer (Doze) freezes background apps mid-prefill, which looks exactly like a hang.

Document

This export is distributed under the LFM Open License v1.0 (see the source model card); it inherits the license and the usage restrictions of the base model.

Downloads last month
48
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Model tree for Juxoola/LFM2.5-VL-3B-MNN

Finetuned
(24)
this model