-
Notifications
You must be signed in to change notification settings - Fork 4.8k
[Liquid AI] Support LFM VL #17954
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
vincentzed
wants to merge
4
commits into
sgl-project:main
Choose a base branch
from
bzhng-development:vz/lfm-VL-supports
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+657
−270
Open
[Liquid AI] Support LFM VL #17954
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| # Copyright 2025 the HuggingFace Inc. team. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| """PyTorch LFM2-VL model.""" | ||
|
|
||
| from transformers.configuration_utils import PreTrainedConfig | ||
| # TODO: replace this with the sglang logger? | ||
| import logging | ||
| from transformers import CONFIG_MAPPING, AutoConfig | ||
|
|
||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class Lfm2VlConfig(PreTrainedConfig): | ||
| r""" | ||
| This is the configuration class to store the configuration of a [`Lfm2VlForConditionalGeneration`]. It is used to instantiate an | ||
| Lfm2Vl model according to the specified arguments, defining the model architecture. Instantiating a configuration | ||
| with the defaults will yield a similar configuration to that of the Lfm2-VL-1.6B. | ||
|
|
||
| e.g. [LiquidAI/LFM2-VL-1.6B](https://huggingface.co/LiquidAI/LFM2-VL-1.6B) | ||
|
|
||
| Configuration objects inherit from [`PreTrainedConfig`] and can be used to control the model outputs. Read the | ||
| documentation from [`PreTrainedConfig`] for more information. | ||
|
|
||
| Args: | ||
| vision_config (`AutoConfig | dict`, *optional*, defaults to `Siglip2ImageConfig`): | ||
| The config object or dictionary of the vision backbone. | ||
| text_config (`AutoConfig | dict`, *optional*, defaults to `Lfm2Config`): | ||
| The config object or dictionary of the text backbone. | ||
| image_token_id (`int`, *optional*, defaults to 396): | ||
| The image token index to encode the image prompt. | ||
| projector_hidden_act (`str`, *optional*, defaults to `"gelu"`): | ||
| The activation function used by the multimodal projector. | ||
| projector_hidden_size (`int`, *optional*, defaults to 2560): | ||
| The hidden size of the multimodal projector. | ||
| projector_bias (`bool`, *optional*, defaults to `True`): | ||
| Whether to use bias in the multimodal projector. | ||
| projector_use_layernorm (`bool`, *optional*, defaults to `True`): | ||
| Whether to use layernorm in the multimodal projector. | ||
| downsample_factor (`int`, *optional*, defaults to 2): | ||
| The downsample_factor factor of the vision backbone. | ||
| tie_word_embeddings (`bool`, *optional*, defaults to `True`): | ||
| Whether to tie the word embeddings of the text backbone. | ||
| """ | ||
|
|
||
| model_type = "lfm2_vl" | ||
| sub_configs = {"text_config": AutoConfig, "vision_config": AutoConfig} | ||
|
|
||
| def __init__( | ||
| self, | ||
| vision_config=None, | ||
| text_config=None, | ||
| image_token_id=396, | ||
| projector_hidden_act="gelu", | ||
| projector_hidden_size=2560, | ||
| projector_bias=True, | ||
| projector_use_layernorm=True, | ||
| downsample_factor=2, | ||
| tie_word_embeddings=True, | ||
| **kwargs, | ||
| ): | ||
| self.image_token_id = image_token_id | ||
| self.projector_hidden_act = projector_hidden_act | ||
| self.projector_hidden_size = projector_hidden_size | ||
| self.projector_bias = projector_bias | ||
| self.projector_use_layernorm = projector_use_layernorm | ||
| self.downsample_factor = downsample_factor | ||
|
|
||
| if isinstance(vision_config, dict): | ||
| vision_config["model_type"] = vision_config.get("model_type", "siglip2_vision_model") | ||
| vision_config = CONFIG_MAPPING[vision_config["model_type"]](**vision_config) | ||
| elif vision_config is None: | ||
| vision_config = CONFIG_MAPPING["siglip2_vision_model"]() | ||
|
|
||
| if isinstance(text_config, dict): | ||
| text_config["model_type"] = text_config.get("model_type", "lfm2") | ||
| text_config = CONFIG_MAPPING[text_config["model_type"]](**text_config) | ||
| elif text_config is None: | ||
| text_config = CONFIG_MAPPING["lfm2"]() | ||
|
|
||
| self.vision_config = vision_config | ||
| self.text_config = text_config | ||
| self.tie_word_embeddings = getattr(text_config, "tie_embedding", tie_word_embeddings) | ||
|
|
||
| super().__init__(**kwargs) | ||
|
|
||
| # Override HuggingFace's Lfm2VlConfig with our version | ||
| # Cannot use .register() because lfm2_vl may already be registered by transformers | ||
| # Directly modify the internal _extra_content dict instead | ||
| CONFIG_MAPPING._extra_content["lfm2_vl"] = Lfm2VlConfig | ||
|
|
||
| __all__ = ["Lfm2VlConfig"] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.