Lfm3VlForConditionalGeneration, registered through the same vllm.general_plugins entry point. Reuses Lfm3ForCausalLM as the language backbone; adds the LFM3-VL vision encoder (gated depthwise 3x3 conv + GQA attention with axial 2D RoPE, MMEncoderAttention / FLASH_ATTN on XPU), the 2x2-merge projector and the vLLM multimodal processor (Qwen2-VL-style pixel_values + image_grid_thw, <|image|> expansion). Images only; video inputs are rejected. Liquid's VL config and processor files are vendored (Apache-2.0) so the checkpoint loads without --trust-remote-code. Verified against Transformers fp32: exact image-token counts and identical 64-token greedy output on 4 images + text-only. Text model unchanged (FP8 greedy output bit-identical). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
60 lines
2.3 KiB
Python
60 lines
2.3 KiB
Python
# SPDX-License-Identifier: Apache-2.0
|
|
"""Out-of-tree vLLM plugin for LiquidAI LFM3 (Lfm3ForCausalLM) and LFM3-VL
|
|
(Lfm3VlForConditionalGeneration).
|
|
|
|
Loaded through the ``vllm.general_plugins`` entry point in every vLLM process
|
|
(API server, EngineCore, workers).
|
|
"""
|
|
|
|
import logging
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
def register() -> None:
|
|
from vllm import ModelRegistry
|
|
|
|
if "Lfm3ForCausalLM" not in ModelRegistry.get_supported_archs():
|
|
# lazy "module:class" form: the model module is only imported when used
|
|
ModelRegistry.register_model("Lfm3ForCausalLM", "vllm_lfm3.model:Lfm3ForCausalLM")
|
|
if "Lfm3VlForConditionalGeneration" not in ModelRegistry.get_supported_archs():
|
|
ModelRegistry.register_model(
|
|
"Lfm3VlForConditionalGeneration", "vllm_lfm3.model_vl:Lfm3VlForConditionalGeneration"
|
|
)
|
|
|
|
# Lets transformers (and therefore vLLM) parse config.json with model_type "lfm3"
|
|
# without --trust-remote-code.
|
|
from transformers import AutoConfig
|
|
|
|
from .configuration_lfm3 import Lfm3Config
|
|
|
|
try:
|
|
AutoConfig.register("lfm3", Lfm3Config)
|
|
except ValueError:
|
|
pass # already registered (e.g. a future transformers ships lfm3)
|
|
|
|
_register_vl()
|
|
|
|
|
|
def _register_vl() -> None:
|
|
"""Same for LFM3-VL: config (``lfm3_vl`` / ``lfm3_vl_vision``) and Liquid's processor,
|
|
image and video processor classes, so AutoProcessor finds them locally."""
|
|
from transformers import AutoConfig, AutoImageProcessor, AutoProcessor, AutoVideoProcessor
|
|
|
|
from .configuration_lfm3_vl import Lfm3VlConfig, Lfm3VlVisionConfig
|
|
from .image_processing_lfm3_vl import Lfm3VlImageProcessor
|
|
from .processing_lfm3_vl import Lfm3VlProcessor
|
|
from .video_processing_lfm3_vl import Lfm3VlVideoProcessor
|
|
|
|
for register in (
|
|
lambda: AutoConfig.register("lfm3_vl", Lfm3VlConfig),
|
|
lambda: AutoConfig.register("lfm3_vl_vision", Lfm3VlVisionConfig),
|
|
lambda: AutoImageProcessor.register(Lfm3VlConfig, fast_image_processor_class=Lfm3VlImageProcessor),
|
|
lambda: AutoVideoProcessor.register(Lfm3VlConfig, Lfm3VlVideoProcessor),
|
|
lambda: AutoProcessor.register(Lfm3VlConfig, Lfm3VlProcessor),
|
|
):
|
|
try:
|
|
register()
|
|
except ValueError:
|
|
pass # already registered
|