LensVLM-9B

Referenties:

Technische Specificaties

  • Modelgrootte: 9 miljard parameters
  • Tensor-type: BF16
  • Basismodel: Qwen/Qwen3.5-9B-Base
  • Finetuned versie: Qwen/Qwen3.5-9B

Licenties

Alle ML-modelbestanden in deze repository, inclusief de wijzigingen van Apple aan het Qwen-model, worden aangeboden onder de voorwaarden van de Apple Machine Learning Research Model License.

De broncode die bij dit model wordt geleverd, wordt apart gedistribueerd en valt onder de voorwaarden van de Apple Sample Code License.

Gebruiksaanwijzing

Gebruik met Transformers

Via een pipeline (high-level helper):

from transformers import pipeline

pipe = pipeline("image-text-to-text", model="apple/LensVLM-9B")

messages = [
    {
        "role": "user",
        "content": [
            {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"},
            {"type": "text", "text": "Wat voor dier staat er op het snoepje?"}
        ]
    },
]

pipe(text=messages)

Direct laden van het model:

from transformers import AutoProcessor, AutoModelForMultimodalLM

processor = AutoProcessor.from_pretrained("apple/LensVLM-9B")
model = AutoModelForMultimodalLM.from_pretrained("apple/LensVLM-9B", device_map="auto")

messages = [
    {
        "role": "user",
        "content": [
            {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"},
            {"type": "text", "text": "Wat voor dier staat er op het snoepje?"}
        ]
    },
]

inputs = processor.apply_chat_template(
    messages,
    add_generation_prompt=True,
    tokenize=True,
    return_dict=True,
    return_tensors="pt",
).to(model.device)

outputs = model.generate(**inputs, max_new_tokens=40)
print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:]))

Gebruik met vLLM

Installatie en server starten:

# Installeer vLLM via pip:
pip install vllm

# Start de vLLM server:
vllm serve "apple/LensVLM-9B"

De server aanroepen via curl (OpenAI-compatibele API):

curl -X POST "http://localhost:8000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "apple/LensVLM-9B",
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "Beschrijf deze afbeelding in één zin."
},
{
"type": "image_url",
"image_url": {
"url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg"
}
}
]
}
]
}'

Gebruik via Docker: docker model run hf.co/apple/LensVLM-9B

Gebruik met SGLang

Installatie en server starten:

# Installeer SGLang via pip:
pip install sglang

# Start de SGLang server:
python3 -m sglang.launch_server \
--model-path "apple/LensVLM-9B" \
--host 0.0.0.0 \
--port 30000

De server aanroepen via curl (OpenAI-compatibele API):

curl -X POST "http://localhost:30000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "apple/LensVLM-9B",
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "Beschrijf deze afbeelding in één zin."
},
{
"type": "image_url",
"image_url": {
"url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg"
}
}
]
}
]
}'

Gebruik via Docker images:

docker run --gpus all \
--shm-size 32g \
-p 30000:30000 \
-v ~/.cache/huggingface:/root/.cache/huggingface \
--env "HF_TOKEN=<secret>" \
--ipc=host \
lmsysorg/sglang:latest \
python3 -m sglang.launch_server \
--model-path "apple/LensVLM-9B" \
--host 0.0.0.0 \
--port 30000

Lokale installatie en inferentie

Installatie van de LensVLM-code:

git clone https://github.com/apple-aiml-research/ml-lensvlm
cd ml-lensvlm
pip install -r requirements.txt
python scripts/run_demo.py --model apple/LensVLM-9B

Voor een eigen document:

python demo.py \
--model apple/LensVLM-9B \
--text_file document.txt \
--question "Wat is de belangrijkste bevinding?" \
--compression 10x

Beschikbare compressie-opties: 5x, 10x, 15x. Raadpleeg de README in de repository voor datavoorbereiding en evaluatie.

Citatie

@article{xie2026lensvlm,
title={LensVLM: Selective Context Expansion for Compressed Visual Representation of Text},
author={Xie, Roy and Friedman, Dan and Yu, Donghan and Pan, Bowen and Fifty, Christopher and Kim, Jang-Hyun and Du, Xianzhi and Gan, Zhe and Rathod, Vivek and Dhingra, Bhuwan},
journal={arXiv preprint arXiv:2605.07019},
year={2026}
}