Skip to content

Studio: enable audio input for Gemma 4 GGUFs; default chat model to Qwen3.5-4B-MTP - #6000

Merged
danielhanchen merged 3 commits into
mainfrom
studio-gemma4-audio-input-and-default-model
Jun 4, 2026
Merged

danielhanchen merged 3 commits into
mainfrom
studio-gemma4-audio-input-and-default-model

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

Two Unsloth Studio changes:

  1. Enable audio file upload for Gemma 4 vision plus audio GGUF models (the audio attach button was hidden even though the models accept audio input).
  2. Switch the default chat model and the dataset-analysis helper to unsloth/Qwen3.5-4B-MTP-GGUF (UD-Q4_K_XL).

1. Gemma 4 audio input

Gemma 4 GGUFs such as unsloth/gemma-4-12b-it-GGUF ship an mmproj with an audio encoder (clip.has_audio_encoder=True, projector gemma4ua, 128 mel bins), so they accept audio input. Studio still hid the audio upload because of two issues:

  • Audio-input detection only matched Gemma 3n's <audio_soft_token>. Gemma 4 uses <|audio|>, so audio_vlm was never detected.
  • The GGUF load and status responses hardcoded has_audio_input=False, dropping the flag even when audio_vlm was detected. This also affected Gemma 3n GGUFs.

Fix:

  • Recognize <|audio|> alongside <audio_soft_token> in the llama-server token probe (_detect_audio_type_strict) and the tokenizer-config pattern (_AUDIO_TOKEN_PATTERNS). csm's uppercase <|AUDIO|> stays distinct.
  • Read clip.has_audio_encoder from the mmproj as an independent, model-agnostic signal (read_mmproj_audio_capability in gguf_metadata.py), reusing the existing header parser so no new dependency is added.
  • Compute a single has_audio_input on the backend (token probe OR mmproj audio encoder) and emit it on the GGUF load and status responses.

The frontend needs no change; it already gates the audio attach button on has_audio_input.

2. Default model

chat-adapter.ts (auto-loaded chat default) and llm_assist.py (dataset helper) now point to unsloth/Qwen3.5-4B-MTP-GGUF (UD-Q4_K_XL) instead of gemma-4-E2B-it.

Testing

  • New unit tests: test_audio_token_detection.py (audio_vlm matches <|audio|>, not csm's <|AUDIO|>) and read_mmproj_audio_capability cases in test_gguf_metadata.py. All 21 passing.
  • Live check: loaded unsloth/gemma-4-12b-it-GGUF (UD-Q4_K_XL) in Studio; the load response now reports has_audio_input: true, audio_type: "audio_vlm", is_vision: true, and the audio attach button appears.

danielhanchen and others added 3 commits June 4, 2026 07:54
Audio file upload was disabled for Gemma 4 vision+audio GGUFs (e.g.
gemma-4-12b-it-GGUF) even though their mmproj carries an audio encoder
(clip.has_audio_encoder, gemma4ua). Two causes:

- Audio-input detection only matched Gemma 3n's <audio_soft_token>;
  Gemma 4 uses <|audio|>, so audio_vlm was never detected.
- The GGUF load/status responses hardcoded has_audio_input=False, so the
  flag was dropped even when audio_vlm was detected (affected Gemma 3n
  GGUFs too).

Changes:
- Recognize <|audio|> alongside <audio_soft_token> in the llama-server
  token probe and the tokenizer-config pattern.
- Read clip.has_audio_encoder from the mmproj as an independent,
  model-agnostic signal (read_mmproj_audio_capability).
- Emit the computed has_audio_input on the GGUF load/status responses.
- Tests for the new pattern and the mmproj reader.
Switch the auto-loaded chat default and the dataset-analysis helper GGUF
from gemma-4-E2B-it to unsloth/Qwen3.5-4B-MTP-GGUF (UD-Q4_K_XL).
@danielhanchen
danielhanchen merged commit 4c06c1d into main Jun 4, 2026
28 of 34 checks passed
@danielhanchen
danielhanchen deleted the studio-gemma4-audio-input-and-default-model branch June 4, 2026 07:56

@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: c66418814e

ℹ️ 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".

is_audio = _gguf_is_audio,
audio_type = _gguf_audio,
has_audio_input = False,
has_audio_input = llama_backend._has_audio_input,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Do not advertise GGUF audio before accepting it

When a Gemma 4/Gemma 3n GGUF now returns has_audio_input=true, the frontend will show the audio attachment control and include audio_base64 in /api/inference/chat, but the GGUF generation path still unconditionally returns 400 "Audio input is not supported for GGUF chat models yet." whenever payload.audio_base64 is present. In the loaded/status responses this therefore exposes a capability that is guaranteed to fail for the exact GGUF models this change targets; either the chat path needs to forward audio to llama-server or this flag should remain false until that path is implemented.

Useful? React with 👍 / 👎.

@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 introduces support for audio input capability detection in GGUF models, specifically handling Gemma 4's <|audio|> token and parsing the clip.has_audio_encoder boolean metadata from projector files (mmproj). It also updates the default helper model to Qwen3.5-4B-MTP-GGUF and adds corresponding unit tests. The review feedback suggests improving encapsulation by exposing the private _has_audio_input attribute as a public @property on LlamaCppBackend rather than accessing it directly or via getattr in the route handlers.

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.

Comment on lines +701 to +702
self._has_audio_input: bool = False
self._mmproj_has_audio: bool = False # clip.has_audio_encoder, set at load

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.

medium

Since _has_audio_input is accessed externally by route handlers in routes/inference.py, please expose it via a public @property on LlamaCppBackend to maintain proper encapsulation.

Comment on lines +797 to 799
has_audio_input = getattr(llama_backend, "_has_audio_input", False),
inference = inference_config,
requires_trust_remote_code = bool(

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.

medium

To preserve encapsulation and maintain consistency with the established design patterns in LlamaCppBackend (which exposes public properties for its internal state, e.g., is_vision, chat_template), avoid accessing the private _has_audio_input attribute directly or via getattr from outside the class. Instead, define a public @property has_audio_input on LlamaCppBackend and use it here.

                    has_audio_input = llama_backend.has_audio_input,

has_audio_input = False,
has_audio_input = llama_backend._has_audio_input,
inference = inference_config,
requires_trust_remote_code = bool(

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.

medium

Avoid accessing the private _has_audio_input attribute directly from outside the class. Instead, use the public @property has_audio_input on LlamaCppBackend to preserve encapsulation.

Suggested change
requires_trust_remote_code = bool(
has_audio_input = llama_backend.has_audio_input,

has_audio_input = False,
has_audio_input = getattr(llama_backend, "_has_audio_input", False),
loading = [],
loaded = [_display_model_id] if _display_model_id else [],

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.

medium

Avoid accessing the private _has_audio_input attribute via getattr from outside the class. Instead, use the public @property has_audio_input on LlamaCppBackend to preserve encapsulation.

Suggested change
loaded = [_display_model_id] if _display_model_id else [],
has_audio_input = llama_backend.has_audio_input,

wtfashwin added a commit to wtfashwin/unsloth that referenced this pull request Jun 4, 2026
unslothai#6000 added <|audio|> as a second audio_vlm probe next to <audio_soft_token>. The no-match and bicodec simulation fixtures only neutralized the latter, so the fake server's default tokenized <|audio|> to one token and audio_vlm matched early — returning 'audio_vlm' where the tests expect bicodec/None. Map <|audio|> to a multi-token response wherever audio_vlm should fall through.
github-actions Bot pushed a commit to josephGuo/unsloth that referenced this pull request Jun 5, 2026
… `<|audio|>` probe (unslothai#6018)

* Studio: fix load_freeze audio-type tests for unslothai#6000 Gemma 4 <|audio|> probe

unslothai#6000 extended LlamaCppBackend._detect_audio_type_strict audio_vlm arm to
also probe Gemma 4 `<|audio|>` (alongside Gemma 3n `<audio_soft_token>`),
but did not update the load_freeze simulation suite (last touched by unslothai#5922).
Its "no-match" and "bicodec" fixtures only defeat `<audio_soft_token>`; the
unmapped `<|audio|>` probe falls through to FakeLlamaServer 1-token default,
so detect_audio_type now returns audio_vlm where these tests expect
None / bicodec:

  - test_functional_equivalence_no_match
  - test_functional_equivalence_bicodec_match
  - test_response_shape_matches_pre_fix_for_no_match

main push-CI does not run "Repo tests (CPU)" (pull_request-only), so this
surfaces in every open PR merge-ref (e.g. unslothai#5940, which is unrelated to audio).

Fix: map `<|audio|>` to a 2-token response in the three fixtures that intend
a non-audio_vlm result (restoring their original semantics), and add a
positive test_functional_equivalence_audio_vlm_match locking in unslothai#6000 new
`<|audio|>` detection.

Co-Authored-By: Claude Opus 4.8 <[email protected]>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: Claude Opus 4.8 <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
LeoBorcherding pushed a commit to LeoBorcherding/unsloth that referenced this pull request Jun 5, 2026
…wen3.5-4B-MTP (unslothai#6000)

* Studio: enable audio input for Gemma 4 GGUF models

Audio file upload was disabled for Gemma 4 vision+audio GGUFs (e.g.
gemma-4-12b-it-GGUF) even though their mmproj carries an audio encoder
(clip.has_audio_encoder, gemma4ua). Two causes:

- Audio-input detection only matched Gemma 3n's <audio_soft_token>;
  Gemma 4 uses <|audio|>, so audio_vlm was never detected.
- The GGUF load/status responses hardcoded has_audio_input=False, so the
  flag was dropped even when audio_vlm was detected (affected Gemma 3n
  GGUFs too).

Changes:
- Recognize <|audio|> alongside <audio_soft_token> in the llama-server
  token probe and the tokenizer-config pattern.
- Read clip.has_audio_encoder from the mmproj as an independent,
  model-agnostic signal (read_mmproj_audio_capability).
- Emit the computed has_audio_input on the GGUF load/status responses.
- Tests for the new pattern and the mmproj reader.

* Studio: default chat model and dataset helper to Qwen3.5-4B-MTP

Switch the auto-loaded chat default and the dataset-analysis helper GGUF
from gemma-4-E2B-it to unsloth/Qwen3.5-4B-MTP-GGUF (UD-Q4_K_XL).

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
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.

1 participant