Local Inference Vision Support: The Overlooked Projection Parameter
This article explains why a local inference service may reject image inputs even when the underlying model has multimodal capabilities. It shows that vision support often requires a separate projection or connector weight file, in addition to the main language-model weights. The article breaks down the three-stage multimodal inference pipeline, outlines startup and request configuration, covers VRAM and image-token budgeting, and compares general-purpose VLMs with specialized OCR models through structured document and UI-to-code tests. It closes with task routing, preprocessing, validation, and troubleshooting recommendations for running code assistance and document understanding on a single GPU.
1. Origin: Wasted Compute
The team’s setup was straightforward: a consumer GPU with 24GB VRAM, a 27B-class quantized general model, and a local inference service exposing an HTTP API compatible with common OpenAI-style protocols. IDE plugins connected to it for code completion, unit test generation, and error explanation. Everything worked smoothly until someone asked whether a screenshot of a design mockup could be passed in and turned directly into page structure.
The first assumption was that the model did not support images. After reviewing the local inference framework documentation, however, the issue seemed to be deployment, not model capability. When starting the service, only the main language-model weights were loaded. Vision capability depends on a separate weight file, commonly called the multimodal projection layer (projection or connector) weights. Without it, the server did not recognize image inputs at all and treated such requests as unsupported.
This is the overlooked parameter this article focuses on. In a local inference framework, the output of a vision encoder must be mapped into the language model’s token embedding space through a projection layer, and that mapping weight is packaged and loaded separately. Parameter names differ across frameworks. Common forms include --vision-projector <file>, --mm <file>, or a vision_config field in a configuration file. This article uses “projection file” as a generic term.
An analogy: the main weights are like a complete camera body, the vision encoder is the lens, and the projection layer is the mount. If the body, lens, and mount do not match, the problem is not image blurriness; the lens simply cannot be attached.
2. How Multimodal Inference Works: A Three-Stage Pipeline
Once you understand why the parameter must be specified explicitly, the later pitfalls become easier to explain. A typical multimodal large model has three stages in the inference path:
- Vision encoder: usually a ViT structure that splits an image into patches and outputs a set of high-dimensional visual feature vectors.
- Projector / adapter: a smaller multilayer perceptron or cross-attention module that aligns the dimension and distribution of visual features to the language model’s hidden space. Parameterization varies, but the responsibility is the same: make the language model “think” it is reading a batch of special tokens.
- Language model backbone: concatenates projected visual tokens with text tokens into a unified sequence and performs autoregressive generation.
The key point is that the main weight file usually contains only stage 3. Some implementations may package stage 1, but stage 2 is almost always separate. If only the main weights are loaded, projected visual tokens have nowhere to map. The model receives vectors it has never seen before, which may appear as “completely ignoring the image,” “describing something fabricated,” or “outputting garbage.”
This leads to three hard constraints that form the basis for all later troubleshooting:
- Provenance constraint: The projection file must come from the same training configuration as the backbone model: same model family, same vision encoder, and same patch and resolution strategy. Mixing across versions or families will almost certainly fail.
- Precision constraint: Vision encoders are highly sensitive to low-bit quantization. A common industry practice is to keep the projection layer and vision tower at relatively high precision, often half precision, while applying low-bit quantization only to the language-model backbone. Compressing the vision tower to very low bit widths yields minimal benefit and noticeable accuracy loss.
- Template constraint: The insertion position of an image in the sequence is determined by the chat template. If the template is wrong, the relative order of visual tokens and text tokens is wrong, and the model may “see pixels but fail to understand the image.”
3. Configuration Checklist: From Loading to Running
3.1 Startup Configuration
An illustrative startup command is below. Parameter names may differ by framework, but the semantics are similar:
# Illustrative: parameter names differ across frameworks, but the semantics are the samepython -m local_llm_server \--model ./models/llm-27b-q4_k_m.bin \--vision-projector ./models/vision-projector-f16.bin \--ctx-size 16384 \--n-gpu-layers 999 \--host 0.0.0.0 --port 8080
A few details are easy to overlook:
--n-gpu-layers 999, meaning full offload, should be used cautiously in multimodal scenarios. The prefill stage of a vision encoder consumes significantly more VRAM than pure text of the same length. Estimate memory first before fully offloading, otherwise first-token latency can fluctuate severely.- Context length is not always better when larger. A high-resolution screenshot may expand into thousands of visual tokens, and once the window is filled, it can directly crowd out the instruction portion.
- If the framework supports disabling mmap or adjusting KV cache quantization, prefer adjusting KV cache quantization when VRAM is tight, rather than compressing the vision tower.
3.2 Client Side: How to Pass Images
Inference services compatible with common protocols usually support two ways to pass images: publicly or internally accessible image URLs, and base64-encoded data URIs. Local services often use the latter.
curl http://127.0.0.1:8080/v1/chat/completions \-H "Content-Type: application/json" \-d '{"model": "local-vlm","messages": [{"role": "user","content": [{"type": "text", "text": "Please convert this table screenshot into Markdown while preserving merged-cell information."},{"type": "image_url", "image_url": {"url": "data:image/png;base64,<BASE64>"}}]}],"temperature": 0.1}'
Three practical recommendations:
- For OCR-like tasks, reduce
temperatureclose to 0 to limit hallucinated characters. - Prepare different system-prompt templates for different tasks, such as extraction, conversion, and code generation.
- For overly long images, split them first, recognize chunks separately, and then merge results. This is much more stable than feeding in the entire image at once.
3.3 VRAM and Image-Token Budget
A rough estimate is:
VRAM requirement ≈ language-model weights + KV cache (growing linearly with context) + vision encoder weights and activations + projection layer weights.
In practice, running a 27B-class four-bit quantized backbone on a single 24GB GPU is a comfortable zone. Once the vision tower is attached, it is recommended to limit concurrency to 1–2, keep context within 16K, and limit the image’s long side to 1024–1536 pixels.
Resolution is not always better when higher. The number of visual tokens grows roughly with the square of resolution, and prefill cost rises accordingly. In practice, the point where additional resolution yields limited gains is often around a long side of 1024 pixels. Above that, recognition accuracy improves only modestly while latency can double.
4. Test Design: Two Comparison Tasks
With these considerations in mind, we designed two tasks and compared four candidate approaches on a single 24GB GPU: a document-focused OCR model, two quantized versions of general-purpose visual language models (VLMs), and a combination approach that uses a general VLM followed by OCR post-processing.
Test group 1: Structured document recognition. The input was a comparison-table screenshot from a public OCR evaluation set. The output requirement was Markdown as faithful as possible, including header hierarchy, merged cells, and numeric alignment.
Test group 2: UI screenshot to code. The input was a self-built web application screenshot. The output requirement was runnable single-file HTML, including inline styles and minimal interaction.
The evaluation dimensions referenced common industry approaches to OCR and document-understanding evaluation, but the implementation was simplified:
| Evaluation dimension | Focus | General VLM performance | Specialized OCR model performance |
|---|---|---|---|
| Text accuracy | Character error rate, missing or repeated characters | Later portions of long tables may drift across rows | Stable, but affected by layout complexity |
| Table structure | Row/column alignment, merged-cell restoration | Merged cells are often flattened | Requires explicit prompts to output structural markers |
| Formulas and special symbols | Superscripts, subscripts, radicals, Greek letters | Common simplifications and approximations | Better under dedicated branches |
| Stamps, handwriting, multilingual | Occlusion, connected strokes, minor languages | Obvious degradation | Has dedicated optimization, but generalization is limited |
| Speed | Single-image latency and throughput | Dominated by image-token count | Usually about an order of magnitude faster |
| Semantic understanding | Whether it can explain content or perform reasoning | Clear advantage | Only outputs text; does not perform reasoning |
The results of group 2 were clearer. A general VLM could understand layout semantics in the screenshot, such as navigation, cards, and forms, and generate a reasonable page skeleton. However, style values and copy details often had deviations. Feeding the screenshot to an OCR model and then assembling the result produced accurate text but completely lost layout intent.
It should be noted that the above conclusions are qualitative observations from this project under specific hardware and specific quantization configurations. They do not constitute an absolute capability ranking of any model. Different resolution strategies, prompt wording, and post-processing intensity can significantly change the results. Readers should rerun the tests on their own data.
5. Conclusions and Selection Recommendations
First, do not compare OCR and VLM as if they were the same category. They solve different problems. The former extracts text and structure from pixels, while the latter understands images and generates new content. In real systems, they are often used in sequence, not as replacements.
Second, implement task routing. Add a lightweight classifier at the entry point: pure text extraction and layout restoration go to a dedicated OCR model; tasks requiring explanation, summarization, code generation, or semantic retrieval go to a general VLM. The cost savings from routing are often greater than switching models.
Third, preprocessing sets the ceiling. Denoising, background-color removal, perspective correction, row/column splitting, and normalizing the long side to 1024–1536 pixels often provide greater gains than switching to a larger model.
Fourth, use post-processing for validation. For HTML output, perform tag-closing checks, DOM structure comparison, and visual regression screenshot comparison. For OCR output, validate digit-column length consistency. Multimodal output hallucinations are structural and can only be contained through engineering measures.
Fifth, define security boundaries clearly. Document screenshots may contain prompt-injection text, such as “ignore the above instructions.” IDs, signatures, and financial data in images are sensitive information. The biggest advantage of local deployment is that data remains within the local environment. If cloud services are used, an audit chain should be established using general capabilities such as object-storage access control, log masking, and monitoring alerts, and input images should be redacted before upload.
6. Troubleshooting Quick Reference
- The projection file is loaded, but answers are unrelated to the image: Check first whether the chat template matches, then check whether the image URL or base64 data is decoded correctly.
- First-token latency is extremely long: The image resolution is too high, causing too many visual tokens. Reduce the long side or split the image into chunks.
- VRAM OOM: The vision tower may be forced to partially fall back to memory. Try reducing context length, using KV cache quantization, or offloading only the backbone.
- Table columns misaligned or digits out of order: Switch the output format. Markdown and HTML tables can perform very differently. Set temperature to 0.
- The model refuses image input: Confirm that the loaded projection file is the multimodal version, rather than weights containing only the language backbone.
- Abnormal Chinese punctuation or full-width characters: Check whether the tokenizer matches the backbone model and whether the quantization format covers the required character set.
Returning to the opening point: for multimodal capabilities in local inference frameworks, 90% of problems are not because the model is weak. They are usually caused by missing a projection weight during deployment, using the wrong chat template, or providing too high an image resolution. Once these three issues are calibrated, a single-GPU machine can handle both code-assistant and document-understanding workloads.
