Feature Request: Expose a safe MTMD memory-usage probe for non-causal image limits #29851
ardan-bkennedy
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Problem
llama.cpp commit
552f18f912a32ea86edf82e2b76431cb7131538dchangedllama-serverandmtmd-clito inspect an mmproj before normal initialization. For projectors using non-causal image attention, they cap the effective image token maximum to the text context's physical batch size:Other apps needs the same pre-initialization information. A global
image_max_tokens = n_ubatchworkaround is incorrect because causal projectors can process image tokens in chunks and should not have their supported resolution reduced.Current upstream API gap
mtmd_get_memory_usageis unsuitable for C and FFI consumers:extern "C"block.mtmd_memory_usageby value using the C++ ABI.mtmd_memory_usagecontainsstd::map<ggml_backend_dev_t, size_t>.Yzma uses Go/libffi and must not mirror a compiler- and standard-library-specific
std::maplayout or bind a mangled C++ symbol.Capability needed upstream
A supported upstream interface must allow a binding to probe an mmproj before normal MTMD initialization and obtain:
image_max_tokens;The API and returned data must be C-compatible and exported from the installed/shared MTMD interface. Kronk does not require the per-device byte map. If upstream keeps that map in the public result, it needs a C representation, explicit ownership rules, and a corresponding release function.
The exact API design belongs to llama.cpp. Viable designs include a small projector-capability probe or a C-compatible replacement for
mtmd_get_memory_usage.Duplicate and related-work search
No standalone llama.cpp issue or active implementation PR was found for this exact API gap as of 2026-10-02.
There is already an exact request by
JamePengin the only comment on #29773. It proposes replacing the exposedstd::mapwith a C-compatible entry array and explicit ownership/status handling. Any new upstream tracker should reference that comment rather than presenting the problem as previously unreported.Related upstream work:
n_ubatchclamp and the two required probe values.mtmd_get_memory_usage, but did not make it C-compatible.mtmd_decode_use_non_causal(ctx, nullptr)is public after a context exists, but Kronk needs the information before its normal initialization so it can set the effective image limits correctly.Search terms already checked included
mtmd_get_memory_usage,mtmd_memory_usage,image_max_tokens,use_non_causal,n_ubatch,extern C,C-compatible, andFFIacross llama.cpp issues and pull requests.Source links
All reactions