Skip to content

Studio: add mmproj load toggle for GGUF vision models - #5954

Closed
Imagineer99 wants to merge 137 commits into
unslothai:mainfrom
Imagineer99:feat/mmproj-load-toggle
Closed

Imagineer99 wants to merge 137 commits into
unslothai:mainfrom
Imagineer99:feat/mmproj-load-toggle

Conversation

@Imagineer99

@Imagineer99 Imagineer99 commented Jun 2, 2026 •

Copy link
Copy Markdown
Member

Summary

Addresses #5825

Vision-capable GGUF models currently auto-load mmproj, even when the user only wants text inference. This can increase VRAM usage, reduce usable context, and conflict with setups where users want to avoid the vision projector.

  • add a Vision Projector toggle in the GGUF model settings, defaulting on
  • pass the setting through model load requests so vision-capable GGUF models can be loaded text-only without --mmproj
  • keep image attachment behavior tied to the loaded model state, so pending images are only cleared after applying a successful mmproj-off reload

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds a toggle to enable or disable loading the mmproj vision projector for GGUF vision models, allowing users to run vision-capable models as text-only to save VRAM. The changes span backend model loading logic, API models, frontend state management, and the chat settings UI. The review feedback suggests adding the state setter setPendingImages to the dependency array of a useEffect hook in shared-composer.tsx to comply with React's exhaustive-deps linting rule.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@Datta0

Datta0 commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

mmproj doesn't go well with MTP. So we gotta at least warn people when they are unknowingly choosing both.

@Imagineer99

Copy link
Copy Markdown
Member Author

mmproj doesn't go well with MTP. So we gotta at least warn people when they are unknowingly choosing both.

yeah valid point, will add warning/toast

Imagineer99 and others added 4 commits June 3, 2026 09:58
Resolve the composer tools-menu conflict and warn when Vision Projector is combined with MTP speculative decoding.
# Conflicts:
#	studio/backend/routes/inference.py
#	studio/frontend/src/features/chat/chat-settings-sheet.tsx
#	studio/frontend/src/features/chat/hooks/use-chat-model-runtime.ts
@danielhanchen danielhanchen self-assigned this Jun 11, 2026
Imagineer99 and others added 2 commits June 19, 2026 14:22
…le-resolve

# Conflicts:
#	studio/backend/core/inference/llama_cpp.py
#	studio/backend/models/inference.py
#	studio/backend/routes/inference.py
#	studio/frontend/src/features/chat/chat-settings-sheet.tsx
#	studio/frontend/src/features/chat/hooks/use-chat-model-runtime.ts
#	studio/frontend/src/features/chat/shared-composer.tsx
#	studio/frontend/src/features/chat/stores/chat-runtime-store.ts
#	studio/frontend/src/features/chat/types/api.ts
@Imagineer99
Imagineer99 marked this pull request as ready for review June 19, 2026 15:09

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5fda53a25a

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread studio/backend/routes/inference.py Resolved
@LeoBorcherding

Copy link
Copy Markdown
Collaborator
image

…ggle

# Conflicts:
#	studio/frontend/src/features/chat/chat-settings-sheet.tsx
#	studio/frontend/src/features/chat/stores/chat-runtime-store.ts

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d702b7c5cc

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@LeoBorcherding

Copy link
Copy Markdown
Collaborator

Tested this end-to-end on the latest commit (now synced with main, with the merge conflicts in chat-settings-sheet.tsx and chat-runtime-store.ts resolved and pushed).

Setup: RTX 5060 Ti (16 GB), Qwen3.6-27B-GGUF (UD-Q2_K_XL), local Studio build.

Results, all working:

Check Result
Vision Projector toggle present, ON by default ✅
Vision works with projector ON ✅ correctly described an attached image
Projector OFF reloads text-only ✅ loads without --mmproj
VRAM reduction with projector OFF ✅ 15.3 GB to 14.6 GB dedicated (~700 MB freed)
Toggle back ON restores vision ✅ projector reloads, image input works again
Image-attach blocked when projector OFF ✅ no silent no-op attachments
MTP + Vision Projector warning toast ✅ fires as expected

On the MTP point @Datta0 raised, the warning toast shows when both are selected, and it stays advisory (it does not block). With MTP and the projector both on, image input still worked in my run, so the warning correctly flags the risky combo without preventing valid use.

The frontend also typechecks clean (tsc -b) after the merge. LGTM from my testing. 👍

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 45160d5fff

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 695d18999b

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@Imagineer99
Imagineer99 requested a review from Datta0 as a code owner July 23, 2026 13:45
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Jul 23, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Jul 23, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Jul 23, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Jul 23, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Jul 23, 2026
@Imagineer99

Copy link
Copy Markdown
Member Author

@codex review

@Imagineer99

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9c283942c7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread studio/backend/routes/inference.py Outdated
Comment on lines +3234 to +3235
if requested_load_mmproj != bool(llama_backend.load_mmproj):
return False

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reset projector state for diffusion loads

When a Diffusion GGUF is loaded after a vision GGUF that was running text-only, _start_diffusion_server() resets many runtime flags but never assigns _load_mmproj. This new comparison therefore sees the stale false from the previous model against the default load_mmproj=true on an identical diffusion /load or Apply, so the already-loaded check misses and unnecessarily tears down/restarts the diffusion runner. Either reset _load_mmproj on the diffusion path or skip this projector comparison for diffusion models.

Useful? React with 👍 / 👎.

Comment thread studio/backend/routes/inference.py Outdated
Comment on lines +3738 to +3739
if resolved is None:
load_kwargs["load_mmproj"] = load_mmproj

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve projector state on resolved idle reloads

With OpenAI auto-switch enabled, an idle-unloaded model is normally requested again by its known model id, so resolve_local_gguf() succeeds and this resolved is None branch is skipped. In that case the stashed load_mmproj=false is not included in load_kwargs, LoadRequest defaults it back to true, and a vision model that was freed in text-only mode is reloaded with the projector anyway, losing the saved effective load and the memory/download savings. Carry the stashed projector state when the resolved target matches the last unloaded model, or persist it in the auto-switch override.

Useful? React with 👍 / 👎.

Comment on lines +1050 to +1052
const effectiveVisionProjector = ownRemembered
? (ownConfig.visionProjectorEnabled ?? true)
: compareLoadKnobs.visionProjectorEnabled;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Default compare panes to loading the projector

When a compare pane has no remembered config, this falls back to the currently loaded model's projector toggle instead of the per-model default. If the active model was intentionally loaded text-only, comparing against a different unsaved vision GGUF sends load_mmproj=false, so that pane is loaded without vision support and image prompts are rejected even though the selected model's default setting should load the projector. Use the default true for unremembered pane configs, matching the normal model-switch reset.

Useful? React with 👍 / 👎.

speculativeType: speculativeType ?? "auto",
specDraftNMax: specDraftNMax ?? null,
tensorParallel: tensorParallel ?? false,
visionProjectorEnabled,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Include projector state in the sidebar remount key

This adds the projector toggle to the active loaded config, but the active sidebar's configSignature() still omits visionProjectorEnabled while ModelConfigPage snapshots loadedConfig with useState(resolveInitial). If a sidebar reload asks to turn the projector on but the backend falls back to load_mmproj=false (missing/incompatible mmproj), the store updates to false but the page does not remount, leaving the switch showing the stale requested value until some other setting changes.

Useful? React with 👍 / 👎.

@@ -5452,12 +6157,18 @@ def load_model(
# Common
model_identifier: str,
is_vision: bool = False,
load_mmproj: bool = True,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Honor the projector toggle in the load marker

This new parameter is honored by the route-level Hub-download gate, but load_model is decorated with _with_gguf_load_marker, which still recomputes require_mmproj from only is_vision and extras. For an HF vision GGUF loaded with load_mmproj=false while another download for the repo is active, the route can allow a cached text-only load but the decorator rejects it as if the uncached mmproj were still required. Include load_mmproj in the decorator's require_mmproj calculation so text-only loads are not blocked by unrelated projector downloads.

Useful? React with 👍 / 👎.

backend.model_identifier,
getattr(backend, "hf_variant", None),
advertised,
bool(getattr(backend, "load_mmproj", True)),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Check projector state before restoring idle KV

Adding the projector state to the idle identity does not protect the saved slot KV because restore_kv_resume() never compares manifest['identity'], and _slot_launch_fingerprint() does not include _load_mmproj or the emitted --mmproj state. After an idle unload saves KV for a vision load, a manual reload of the same GGUF with the projector toggled the other way can still pass the GGUF/fingerprint checks and restore KV from the incompatible multimodal/text-only session. Include the projector state in the restore validation before applying the saved slots.

Useful? React with 👍 / 👎.

@Imagineer99

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a4dc23ea5a

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +3230 to +3234
requested_load_mmproj = _effective_load_mmproj(
request.load_mmproj,
effective_extra,
)
if not llama_backend.is_diffusion and requested_load_mmproj != bool(llama_backend.load_mmproj):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Strip inherited no-mmproj when enabling projector

When a same-model Apply/reload omits llama_extra_args, effective_extra is rebuilt from the previous load's stored extras, so a hidden inherited --no-mmproj makes this new load_mmproj=true request resolve back to false and the route can return already_loaded instead of ever retrying with the projector enabled. Fresh evidence in this target tree is that the new comparator feeds inherited effective_extra directly into _effective_load_mmproj; only explicit extra args should keep overriding the first-class toggle, while inherited mmproj-disable flags need to be stripped when the UI sends the projector setting.

Useful? React with 👍 / 👎.

@Imagineer99

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9be0d6baa7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +8744 to +8745
requested_load_mmproj = bool(load_mmproj and not extra_args_disable_mmproj(extra_args))
if bool(getattr(self, "_load_mmproj", True)) != requested_load_mmproj:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Skip mmproj comparison for diffusion loads

When the live GGUF is a diffusion runner, _start_diffusion_server records _load_mmproj = False, but duplicate load_model calls still arrive with the default load_mmproj=True. This backend fast path is meant to catch /load calls that raced past the route-level dedupe, so concurrent duplicate loads of the same diffusion model now miss the fast path, kill the healthy diffusion process, and start it again. Gate this comparison to non-diffusion/vision llama-server loads, matching the route-level matcher.

Useful? React with 👍 / 👎.

Comment on lines +3754 to +3755
if stashed_load_mmproj is not None:
load_kwargs["load_mmproj"] = stashed_load_mmproj

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject image auto-switch when stashed projector is off

When an idle-unloaded vision GGUF was stashed with load_mmproj=False, an OpenAI image/audio request naming that model reaches this path and reloads it text-only. The earlier require_vision guard only probes whether the target has an mmproj file, so it treats the target as vision-capable and allows the expensive load, after which the request is rejected because the active backend is not vision. If require_vision is true and the matching stash says the projector is disabled, reject before calling _load_model_impl instead of loading a model that cannot serve the request.

Useful? React with 👍 / 👎.

"speculativeType",
"specDraftNMax",
"tensorParallel",
"visionProjectorEnabled",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3 Badge Bump the per-model config schema for projector state

This adds a persisted load-affecting field while keeping the stored schema at version 1. If a user saves a model as text-only in this build and later opens the same settings with an older v1 client, that client will not hit the future-version guard; it will accept the record, drop the unknown visionProjectorEnabled field on save, and silently re-enable the projector. Store this under a new schema version so older clients refuse to rewrite configs they cannot preserve.

Useful? React with 👍 / 👎.

@Imagineer99

Copy link
Copy Markdown
Member Author

@codex review

@Imagineer99

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@Imagineer99

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2c6af0eba5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +1050 to +1052
const effectiveVisionProjector = ownRemembered
? (ownConfig.visionProjectorEnabled ?? true)
: true;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Use the send-time projector setting in compare loads

In compare mode, this hard-codes unremembered GGUF panes to load with load_mmproj: true. If the user has disabled Vision Projector in the current runtime settings but has not remembered a per-model config, the compare send path ignores the value already captured in compareLoadKnobs.visionProjectorEnabled and re-enables/downloads the mmproj for that pane, reintroducing the VRAM/context pressure the toggle was meant to avoid. Fall back to the send-time snapshot when ownRemembered is false.

Useful? React with 👍 / 👎.

Comment on lines +7841 to +7843
if is_vision and not effective_mmproj_requested:
env.pop("LLAMA_ARG_MMPROJ", None)
env.pop("LLAMA_ARG_MMPROJ_AUTO", None)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Drop projector URL env when disabling mmproj

When Vision Projector is disabled, this strips LLAMA_ARG_MMPROJ and LLAMA_ARG_MMPROJ_AUTO from the child environment but leaves LLAMA_ARG_MMPROJ_URL intact. On hosts that set the URL form of the projector flag, the llama-server process can still receive an explicit mmproj URL even though Studio reports load_mmproj=false and skipped the projector sizing/download path; clear the URL env alongside the file-path env to make the toggle authoritative.

Useful? React with 👍 / 👎.

@Imagineer99

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: cd8eff5f0f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.