c/engine: add litert_lm_engine_settings_set_max_num_images (C API parity for #1686)#2157
Open
DenisovAV wants to merge 1 commit intogoogle-ai-edge:mainfrom
Open
c/engine: add litert_lm_engine_settings_set_max_num_images (C API parity for #1686)#2157DenisovAV wants to merge 1 commit intogoogle-ai-edge:mainfrom
DenisovAV wants to merge 1 commit intogoogle-ai-edge:mainfrom
Conversation
Multimodal vision models require max_num_images > 0 to be set on the main executor settings before engine_create — otherwise the vision tower stays uninitialized and image inputs are silently dropped, so the model hallucinates a response from text alone (the original bug in google-ai-edge#1686). Kotlin EngineConfig.maxNumImages and the JNI's GetMutableMainExecutorSettings().SetMaxNumImages() call (added in the google-ai-edge#1686 fix) handle this on the JVM path. The C API in c/engine.h didn't get the parity setter, so any cross-language consumer still hits the original bug. Add a thin wrapper that mirrors the JNI behavior: void litert_lm_engine_settings_set_max_num_images( LiteRtLmEngineSettings* settings, int max_num_images); with a max_num_images > 0 guard on the impl side (matches the Kotlin `require(maxNumImages == null || maxNumImages > 0)` precondition). Closes google-ai-edge#2156.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Adds the C API parity for `max_num_images` so multimodal vision models work via the C API path. Without this, vision input is silently dropped on the C API path even though the Kotlin/JVM path was fixed in #1686.
Closes #2156.
What changes
`c/engine.h` — new declaration:
```c
LITERT_LM_C_API_EXPORT
void litert_lm_engine_settings_set_max_num_images(
LiteRtLmEngineSettings* settings, int max_num_images);
```
`c/engine.cc` — one-line impl that mirrors what `kotlin/.../jni/litertlm.cc:474` already does:
```cpp
settings->settings->GetMutableMainExecutorSettings().SetMaxNumImages(max_num_images);
```
with a `max_num_images > 0` guard matching the Kotlin `require` precondition.
`+21/-0` total. No new behavior on the runtime side — `SetMaxNumImages` already exists in the executor settings; this just exposes a setter to the C API surface.
Test plan
Cross-references
If a Windows shared-lib build (#2154 / PR #2155) lands, the new entry will need to be added to `c/windows_exports.def`. Happy to follow up there if both land.
CLA
Will sign Individual CLA before merge if needed; flagging upfront.