Instructions to use LiquidAI/LFM2-VL-1.6B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use LiquidAI/LFM2-VL-1.6B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="LiquidAI/LFM2-VL-1.6B") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("LiquidAI/LFM2-VL-1.6B") model = AutoModelForMultimodalLM.from_pretrained("LiquidAI/LFM2-VL-1.6B", 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": "What animal is on the candy?"} ] }, ] 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=256) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use LiquidAI/LFM2-VL-1.6B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "LiquidAI/LFM2-VL-1.6B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "LiquidAI/LFM2-VL-1.6B", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/LiquidAI/LFM2-VL-1.6B
- SGLang
How to use LiquidAI/LFM2-VL-1.6B with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "LiquidAI/LFM2-VL-1.6B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "LiquidAI/LFM2-VL-1.6B", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use 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 "LiquidAI/LFM2-VL-1.6B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "LiquidAI/LFM2-VL-1.6B", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use LiquidAI/LFM2-VL-1.6B with Docker Model Runner:
docker model run hf.co/LiquidAI/LFM2-VL-1.6B
Update configs for most recent transformers package
Browse files- config.json +5 -4
- preprocessor_config.json +25 -4
- processor_config.json +1 -15
config.json
CHANGED
|
@@ -4,7 +4,9 @@
|
|
| 4 |
],
|
| 5 |
"do_image_splitting": true,
|
| 6 |
"downsample_factor": 2,
|
|
|
|
| 7 |
"encoder_patch_size": 16,
|
|
|
|
| 8 |
"image_token_index": 396,
|
| 9 |
"max_image_tokens": 256,
|
| 10 |
"max_num_patches": 1024,
|
|
@@ -36,6 +38,7 @@
|
|
| 36 |
"conv_dim": 2048,
|
| 37 |
"conv_dim_out": 2048,
|
| 38 |
"conv_use_xavier_init": true,
|
|
|
|
| 39 |
"eos_token_id": 7,
|
| 40 |
"hidden_size": 2048,
|
| 41 |
"initializer_range": 0.02,
|
|
@@ -66,18 +69,17 @@
|
|
| 66 |
"num_hidden_layers": 16,
|
| 67 |
"num_key_value_heads": 8,
|
| 68 |
"rope_theta": 1000000.0,
|
| 69 |
-
"torch_dtype": "bfloat16",
|
| 70 |
"use_cache": true,
|
| 71 |
"use_pos_enc": true,
|
| 72 |
"vocab_size": 65536
|
| 73 |
},
|
| 74 |
"tile_size": 512,
|
| 75 |
-
"
|
| 76 |
-
"transformers_version": "4.55.0",
|
| 77 |
"use_image_special_tokens": true,
|
| 78 |
"use_thumbnail": true,
|
| 79 |
"vision_config": {
|
| 80 |
"attention_dropout": 0.0,
|
|
|
|
| 81 |
"hidden_act": "gelu_pytorch_tanh",
|
| 82 |
"hidden_size": 1152,
|
| 83 |
"intermediate_size": 4304,
|
|
@@ -88,7 +90,6 @@
|
|
| 88 |
"num_hidden_layers": 26,
|
| 89 |
"num_patches": 256,
|
| 90 |
"patch_size": 16,
|
| 91 |
-
"torch_dtype": "bfloat16",
|
| 92 |
"vision_use_head": false
|
| 93 |
}
|
| 94 |
}
|
|
|
|
| 4 |
],
|
| 5 |
"do_image_splitting": true,
|
| 6 |
"downsample_factor": 2,
|
| 7 |
+
"dtype": "bfloat16",
|
| 8 |
"encoder_patch_size": 16,
|
| 9 |
+
"image_token_id": 396,
|
| 10 |
"image_token_index": 396,
|
| 11 |
"max_image_tokens": 256,
|
| 12 |
"max_num_patches": 1024,
|
|
|
|
| 38 |
"conv_dim": 2048,
|
| 39 |
"conv_dim_out": 2048,
|
| 40 |
"conv_use_xavier_init": true,
|
| 41 |
+
"dtype": "bfloat16",
|
| 42 |
"eos_token_id": 7,
|
| 43 |
"hidden_size": 2048,
|
| 44 |
"initializer_range": 0.02,
|
|
|
|
| 69 |
"num_hidden_layers": 16,
|
| 70 |
"num_key_value_heads": 8,
|
| 71 |
"rope_theta": 1000000.0,
|
|
|
|
| 72 |
"use_cache": true,
|
| 73 |
"use_pos_enc": true,
|
| 74 |
"vocab_size": 65536
|
| 75 |
},
|
| 76 |
"tile_size": 512,
|
| 77 |
+
"transformers_version": "4.57.1",
|
|
|
|
| 78 |
"use_image_special_tokens": true,
|
| 79 |
"use_thumbnail": true,
|
| 80 |
"vision_config": {
|
| 81 |
"attention_dropout": 0.0,
|
| 82 |
+
"dtype": "bfloat16",
|
| 83 |
"hidden_act": "gelu_pytorch_tanh",
|
| 84 |
"hidden_size": 1152,
|
| 85 |
"intermediate_size": 4304,
|
|
|
|
| 90 |
"num_hidden_layers": 26,
|
| 91 |
"num_patches": 256,
|
| 92 |
"patch_size": 16,
|
|
|
|
| 93 |
"vision_use_head": false
|
| 94 |
}
|
| 95 |
}
|
preprocessor_config.json
CHANGED
|
@@ -1,11 +1,18 @@
|
|
| 1 |
{
|
| 2 |
-
"
|
| 3 |
-
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
| 5 |
"do_convert_rgb": null,
|
|
|
|
| 6 |
"do_normalize": true,
|
|
|
|
| 7 |
"do_rescale": true,
|
| 8 |
"do_resize": false,
|
|
|
|
|
|
|
| 9 |
"image_mean": [
|
| 10 |
0.5,
|
| 11 |
0.5,
|
|
@@ -17,10 +24,24 @@
|
|
| 17 |
0.5,
|
| 18 |
0.5
|
| 19 |
],
|
|
|
|
|
|
|
| 20 |
"max_num_patches": 1024,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
"patch_size": 16,
|
| 22 |
"processor_class": "Lfm2VlProcessor",
|
| 23 |
"resample": 2,
|
| 24 |
"rescale_factor": 0.00392156862745098,
|
| 25 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
}
|
|
|
|
| 1 |
{
|
| 2 |
+
"crop_size": null,
|
| 3 |
+
"data_format": "channels_first",
|
| 4 |
+
"default_to_square": true,
|
| 5 |
+
"device": null,
|
| 6 |
+
"disable_grouping": null,
|
| 7 |
+
"do_center_crop": null,
|
| 8 |
"do_convert_rgb": null,
|
| 9 |
+
"do_image_splitting": true,
|
| 10 |
"do_normalize": true,
|
| 11 |
+
"do_pad": true,
|
| 12 |
"do_rescale": true,
|
| 13 |
"do_resize": false,
|
| 14 |
+
"downsample_factor": 2,
|
| 15 |
+
"encoder_patch_size": 16,
|
| 16 |
"image_mean": [
|
| 17 |
0.5,
|
| 18 |
0.5,
|
|
|
|
| 24 |
0.5,
|
| 25 |
0.5
|
| 26 |
],
|
| 27 |
+
"input_data_format": null,
|
| 28 |
+
"max_image_tokens": 256,
|
| 29 |
"max_num_patches": 1024,
|
| 30 |
+
"max_pixels_tolerance": 2.0,
|
| 31 |
+
"max_tiles": 10,
|
| 32 |
+
"min_image_tokens": 64,
|
| 33 |
+
"min_tiles": 2,
|
| 34 |
+
"pad_size": null,
|
| 35 |
"patch_size": 16,
|
| 36 |
"processor_class": "Lfm2VlProcessor",
|
| 37 |
"resample": 2,
|
| 38 |
"rescale_factor": 0.00392156862745098,
|
| 39 |
+
"return_row_col_info": true,
|
| 40 |
+
"return_tensors": null,
|
| 41 |
+
"size": {
|
| 42 |
+
"height": 512,
|
| 43 |
+
"width": 512
|
| 44 |
+
},
|
| 45 |
+
"tile_size": 512,
|
| 46 |
+
"use_thumbnail": true
|
| 47 |
}
|
processor_config.json
CHANGED
|
@@ -1,18 +1,4 @@
|
|
| 1 |
{
|
| 2 |
-
"auto_map": {
|
| 3 |
-
"AutoProcessor": "processing_lfm2_vl.Lfm2VlProcessor"
|
| 4 |
-
},
|
| 5 |
-
"do_image_splitting": true,
|
| 6 |
-
"downsample_factor": 2,
|
| 7 |
-
"encoder_patch_size": 16,
|
| 8 |
-
"max_image_tokens": 256,
|
| 9 |
-
"max_num_patches": 1024,
|
| 10 |
-
"max_pixels_tolerance": 1.5,
|
| 11 |
-
"max_tiles": 10,
|
| 12 |
-
"min_image_tokens": 64,
|
| 13 |
-
"min_tiles": 2,
|
| 14 |
"processor_class": "Lfm2VlProcessor",
|
| 15 |
-
"
|
| 16 |
-
"use_image_special_tokens": true,
|
| 17 |
-
"use_thumbnail": true
|
| 18 |
}
|
|
|
|
| 1 |
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
"processor_class": "Lfm2VlProcessor",
|
| 3 |
+
"use_image_special_tokens": true
|
|
|
|
|
|
|
| 4 |
}
|