-
Notifications
You must be signed in to change notification settings - Fork 13.9k
model: LFM2-VL fixes #17577
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
Merged
ngxson
merged 13 commits into
ggml-org:master
from
Liquid4All:tarek/feat/upstream_17290
Nov 30, 2025
+162
−13
Merged
model: LFM2-VL fixes #17577
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
2386891
Adjust to pytorch
tdakhran c509073
Add antialiasing upscale
tdakhran 80b4e97
Increase number of patches to 1024
tdakhran 1cd4e2f
Handle default marker insertion for LFM2
tdakhran 40e08b8
Switch to flag
tdakhran 65789e5
Reformat
tdakhran 7cf67d6
Cuda implementation of antialias kernel
tdakhran 7c8b098
Change placement in ops.cpp
tdakhran 3ea706e
consistent float literals
tdakhran 0b14906
Pad only for LFM2
tdakhran b81928f
Address PR feedback
tdakhran 31be1a9
Rollback default marker placement changes
tdakhran 2385ecf
Fallback to CPU implementation for antialias implementation of upscale
tdakhran 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2012,7 +2012,7 @@ struct clip_graph { | |
| ggml_tensor * pos_embd = model.position_embeddings; | ||
| const int height = img.ny / patch_size; | ||
| const int width = img.nx / patch_size; | ||
| const uint32_t mode = GGML_SCALE_MODE_BILINEAR; | ||
| const uint32_t mode = GGML_SCALE_MODE_BILINEAR | GGML_SCALE_FLAG_ANTIALIAS; | ||
| const int n_per_side = (int)std::sqrt(pos_embd->ne[1]); | ||
|
|
||
| GGML_ASSERT(pos_embd); | ||
|
|
@@ -2787,7 +2787,8 @@ struct clip_model_loader { | |
| { | ||
| get_u32(KEY_PROJ_SCALE_FACTOR, hparams.n_merge, false); | ||
| // ref: https://huggingface.co/LiquidAI/LFM2-VL-3B/blob/main/preprocessor_config.json | ||
| hparams.set_limit_image_tokens(64, 256); | ||
| // config above specifies number of tokens after downsampling, while here it is before, relax lowerbound to 64 | ||
| hparams.set_limit_image_tokens(64, 1024); | ||
tdakhran marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } break; | ||
| case PROJECTOR_TYPE_PIXTRAL: | ||
| case PROJECTOR_TYPE_LIGHTONOCR: | ||
|
|
@@ -3737,12 +3738,13 @@ struct img_tool { | |
| const int width = inp_size.width; | ||
| const int height = inp_size.height; | ||
|
|
||
| auto round_by_factor = [f = align_size](float x) { return static_cast<int>(std::round(x / static_cast<float>(f))) * f; }; | ||
| auto ceil_by_factor = [f = align_size](float x) { return static_cast<int>(std::ceil(x / static_cast<float>(f))) * f; }; | ||
| auto floor_by_factor = [f = align_size](float x) { return static_cast<int>(std::floor(x / static_cast<float>(f))) * f; }; | ||
|
|
||
| // always align up first | ||
| int h_bar = std::max(align_size, ceil_by_factor(height)); | ||
| int w_bar = std::max(align_size, ceil_by_factor(width)); | ||
| int h_bar = std::max(align_size, round_by_factor(height)); | ||
| int w_bar = std::max(align_size, round_by_factor(width)); | ||
|
|
||
| if (h_bar * w_bar > max_pixels) { | ||
| const auto beta = std::sqrt(static_cast<float>(height * width) / max_pixels); | ||
|
|
@@ -4357,7 +4359,8 @@ bool clip_image_preprocess(struct clip_ctx * ctx, const clip_image_u8 * img, str | |
| const std::array<uint8_t, 3> pad_color = {122, 116, 104}; | ||
|
|
||
| clip_image_u8 resized_img; | ||
| img_tool::resize(*img, resized_img, target_size, img_tool::RESIZE_ALGO_BILINEAR, true, pad_color); | ||
| const bool pad = (ctx->proj_type() != PROJECTOR_TYPE_LFM2); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. self-note: probably kimi-vl also need padding, to be verified later |
||
| img_tool::resize(*img, resized_img, target_size, img_tool::RESIZE_ALGO_BILINEAR, pad, pad_color); | ||
| clip_image_f32_ptr res(clip_image_f32_init()); | ||
| normalize_image_u8_to_f32(resized_img, *res, params.image_mean, params.image_std); | ||
| res_imgs->entries.push_back(std::move(res)); | ||
|
|
||
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.