Skip to content

Studio: name FFmpeg when a video GGUF can't decode, and shrink clips with the ffmpeg llama-server uses - #16098

Merged
danielhanchen merged 14 commits into
unslothai:mainfrom
LeoBorcherding:night-shift-tester/issue-16065
Nov 2, 2026
Merged

danielhanchen merged 14 commits into
unslothai:mainfrom
LeoBorcherding:night-shift-tester/issue-16065

Conversation

@LeoBorcherding

@LeoBorcherding LeoBorcherding commented Oct 30, 2026 •

Copy link
Copy Markdown
Collaborator

Follow-up to #16094 (which closed #16065).

  • A video request to a model whose /props advertises video, but where llama-server can't find ffmpeg/ffprobe, now gets a 400 naming FFmpeg instead of the generic "cannot take video input".
  • Clip preprocessing uses the selected --video-ffmpeg-dir when available and receives the running server's prepared loader environment. Otherwise it retains normal executable lookup.
  • A build confirmed to lack --video-ffmpeg-dir ignores LLAMA_ARG_VIDEO_FFMPEG_DIR, and the reachability check follows that behavior. An inconclusive probe preserves the inherited override.
  • supports_video_ffmpeg_dir is probed from --help. A confirmed supported build can receive an automatically found folder on POSIX; Windows keeps native application-directory search precedence. Inconclusive probes preserve explicit and inherited overrides.

Edge cases run on macOS against a real llama-server with Homebrew ffmpeg: ffmpeg on PATH, no ffmpeg, ffmpeg and ffprobe in different folders, a user's own --video-ffmpeg-dir or env var, and a build without that flag.

API Monitor before and after

Merge base 6fe27d2c5 versus corrected head 19b224260. API Monitor now names llama-server's FFmpeg search path and explains how to correct a configured override. Both sides use independently built Studio installs with the same injected loaded video GGUF state; authentication, the HTTP request, rejection, monitor recording, and frontend rendering are real. This fixture checks the visible error and performs no model inference.

API Monitor: generic video refusal before, FFmpeg search-path and override guidance after

The follow-up fixes preserve native Windows executable lookup and application-directory precedence, inherited overrides after an inconclusive help probe, directory whitespace, and the running server's prepared loader environment during preprocessing. Native Windows controls reproduce the earlier lookup and precedence failures; the corrected head keeps both behaviors working.

llama-server spawns ffprobe and ffmpeg for every clip, but Studio advertised
video from /props alone, so a machine without FFmpeg on PATH (most Windows
installs) let a clip through and got "Failed to load image or audio file".
Gate has_video_input on the tools, pin llama-server to the folder Studio
found with --video-ffmpeg-dir, and refuse with a message naming FFmpeg.
…-ffmpeg-dir

An older llama-server ignores the env twin and searches PATH, so the video
check has to search PATH as well there.
pre-commit-ci Bot and others added 7 commits October 30, 2026 10:39
The Windows launch prepends llama-server's own folder to the child PATH, so
ffmpeg beside llama-server.exe was found by the child but not by Studio's
check, which turned video off.
Main's _video_tools_reachable (PR 16094) now decides whether a GGUF takes
video, so the duplicate check in _query_server_n_ctx and the child-PATH
search are dropped. Kept: --video-ffmpeg-dir pinned to the folder Studio
checked, the clip shrink using that folder, and a 400 naming FFmpeg. The
gate no longer reads LLAMA_ARG_VIDEO_FFMPEG_DIR on a build without
--video-ffmpeg-dir, which ignores it.
When the tools are only on the child's search path (beside llama-server.exe
on Windows) nothing was pinned, so the clip shrink searched Studio's PATH,
found nothing and sent the clip unshrunk. The gate's search is now one
helper, and a load that keeps video records it for the shrink.
@LeoBorcherding

Copy link
Copy Markdown
Collaborator Author

Codex review on the fork mirror (LeoBorcherding#651) is clean at 60b60b83a4, this PR's head: result. The last fix makes the clip shrink use the same ffmpeg folder llama-server searches. The ffmpeg cases ran against a real llama-server on macOS: ffmpeg on PATH, no ffmpeg, ffmpeg and ffprobe in different folders, a user's own --video-ffmpeg-dir or env var, and a build without that flag.

@LeoBorcherding LeoBorcherding changed the title Studio: turn off video input when ffmpeg is missing instead of failing the request Studio: name FFmpeg when a video GGUF can't decode, and shrink clips with the ffmpeg llama-server uses Oct 30, 2026
@LeoBorcherding

Copy link
Copy Markdown
Collaborator Author

CI clean on the fork mirror (LeoBorcherding#651) at 60b60b83a4. The three red checks are the AV-shapes lint baseline (test_sd_cpp_probe_error_mode.py, studio-tauri-smoke.yml), outside this diff and failing the same way at the base.

@shimmyshimmer

Copy link
Copy Markdown
Member

Review record for #16098, carried over from the mirror it was reviewed on: danielhanchen/unsloth-staging-review#698.

Findings are quoted as posted and attributed to the account that posted them. The reactions shown are the triage recorded on the mirror; none were re-applied here. Commits are named as the mirror's, with this PR's equivalent where one was found.

Round 1: reviewed mirror 91741919ba (this PR's 6e973cc82)

chatgpt-codex-connector[bot] (on the mirror)

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: 91741919ba

No triage reaction was recorded on the mirror

Verdict

The round converged at mirror 91741919ba (this PR's 6e973cc82).

This is the review as it stood at that commit. Anything pushed to this PR afterwards was not part of it.

danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 2, 2026
@danielhanchen
danielhanchen merged commit f4c7a8f into unslothai:main Nov 2, 2026
danielhanchen added a commit that referenced this pull request Nov 3, 2026
…tom-code generate (#16242)

Replaces #16101, which GitHub closed when #16096 merged and its base
branch was deleted. Same branch, now merged with main; the diff is only
this PR's changes.

## What breaks

`LiquidAI/LFM3-Omni-2B` (safetensors, custom code) loads as vision-only.
The backend logs `is_vision=True ... audio_type=None,
audio_type_known=True`, the chat chip says "Vision", and attaching a WAV
through "Add photos & files" is refused ("cannot accept audio"), so the
prompt goes out text-only and the model says it has no clip. The GGUF of
the same model takes audio fine, because llama.cpp reads the vocab.

## Why

Audio-input detection fingerprints `added_tokens_decoder` in
`tokenizer_config.json` (`<|audio|>` / `<audio_soft_token>` ->
`audio_vlm`). LFM3-Omni was saved by transformers 5, whose
`tokenizer_config.json` has no `added_tokens_decoder` at all:
`<|audio|>` only lives in `tokenizer.json` and in
`processor_config.json` (`"audio_token": "<|audio|>"`). So detection
read the tokenizer config, found nothing, and answered a definitive "not
audio".

## Fix

- `processor_config.json` joins the files audio detection reads (local
dir, HF cache and Hub), and `classify_audio_tokens` counts a config's
`audio_token`. Only the markers the tokenizer patterns already accept
route to `audio_vlm`, so Qwen2-Audio's `<|AUDIO|>` stays where it was.
- `generate_audio_input_response` needed no change: it goes through
`processor.apply_chat_template`, and transformers' base implementation
calls the processor with `text=`, `audio=` by keyword, so LFM3's
text-first signature is not a problem on this path (the positional issue
#16096 fixed was on the image path only).

## Evidence

Colab L4 (NVIDIA L4, 22.5 GB), Linux, transformers 5.22.0 latest sidecar
(installed through Studio's own upgrade prompt). Same VM, same WAV (2.9
s, macOS `say`: "Hello. The secret word for today is pineapple."), same
prompt "What is the secret word in this audio clip?", driven headless
with Playwright through the real "Add photos & files" picker.

| | before `0782561c9a` | after `a19ca071ed` |
|---|---|---|
| `/api/models/config` | `audio_type=None`, `has_audio_input=False`,
`model_type=vision` | `audio_type=audio_vlm`, `has_audio_input=True` |
| chip | Vision | Vision · Audio Input |
| attach WAV | refused: "LFM3-Omni-2B cannot accept audio" | attached |
| reply | "you haven't provided the audio clip" | "The secret word for
today is pineapple." |

![before/after
reply](https://raw.githubusercontent.com/LeoBorcherding/unsloth/d2f4a7b4cd6d193512de4b14506bf103154ca062/lfm3-omni-audio-2026-10/before-after-reply.png)

| before: attach refused | after: attached |
|---|---|
|
![](https://raw.githubusercontent.com/LeoBorcherding/unsloth/d2f4a7b4cd6d193512de4b14506bf103154ca062/lfm3-omni-audio-2026-10/before-04-attach-refused.png)
|
![](https://raw.githubusercontent.com/LeoBorcherding/unsloth/d2f4a7b4cd6d193512de4b14506bf103154ca062/lfm3-omni-audio-2026-10/after-04-attached.png)
|

<details><summary>GIFs of the full flow</summary>

Before:
![](https://raw.githubusercontent.com/LeoBorcherding/unsloth/d2f4a7b4cd6d193512de4b14506bf103154ca062/lfm3-omni-audio-2026-10/before.gif)

After:
![](https://raw.githubusercontent.com/LeoBorcherding/unsloth/d2f4a7b4cd6d193512de4b14506bf103154ca062/lfm3-omni-audio-2026-10/after.gif)
</details>

Image chat still works after the change (`/v1/chat/completions` with a
red-circle PNG: "Red circle on white background").

## Tests

Three new tests in `studio/backend/tests/test_audio_token_detection.py`
(classifier, local checkpoint shaped like the published repo, Hub
fetch). Red on `0782561c9a`, green here. Every test file touching
`tokenizer_config` / `detect_audio_type` / `audio_tokens` (84 files, Mac
M5, Unsloth Studio venv): no new failures. The other failures there are
the same on base (mostly MLX trainer tests that can't run on this Mac);
`test_memory_estimate::test_a_weightless_probe_never_runs_the_evaluations_its_model_asks_for`
failed once in the loaded full run and passes alone.

## Not covered

- Windows (the reporter's OS) and Unsloth Desktop: the change is in
backend detection, which is platform-independent, but no Windows run.
- Spoken-reply (`audio_out`) is untouched; this is audio in, text out.
- Seen in passing: with `/v1/chat/completions` non-streaming, LFM3's
image answer lands in `reasoning_content` with empty `content`. Separate
from this PR.


## Also in this PR (added after review and GPU testing)

- **Stop and stop sequences for custom-code `generate`:** LFM3's
`generate` rejects `stopping_criteria`, so Stop or a matched stop string
ran to `max_new_tokens` while holding the generation lock. Cancellation
now goes through the streamer on the text, vision and audio-input paths.
Stop strings use the existing text and vision stop-sequence streamers;
audio-input stop strings remain unsupported. T4, LFM3-Omni-2B, WAV
question cancelled after 8 chunks: the next request waited 80.3 s
before, 0.3 s after.
- **Export:** an `audio_vlm` checkpoint with a vision tower loads as a
VLM for export, so the processor, audio tokenizer and mmproj ship. Gemma
3n/4 exports are byte-identical before and after (G4).
- **LoRA defaults:** LFM3's MLP is `w1/w2/w3`, which the default
`up_proj/down_proj` targets miss, so every LFM3 repo defaults to
`all-linear`.
- **LFM3-Audio-2B:** its `audio_token` has no image processor beside it,
so it isn't advertised as an audio VLM, and a text-path load whose model
has no `generate` is refused by name instead of crashing on the first
message (#16128 builds the real chat path).
- **Routing:** a custom-code config whose `transformers_version` is only
on nested sub-configs (LFM3-Audio-2B) routes by that.

Hardware: Colab A100 / G4 / T4 / L4 (NVIDIA, Linux); RX 9060 XT gfx1200
on Linux (chat, LoRA, export); RX 6500 XT gfx1034 on Windows 11
(LFM3-1.7B chat and LoRA); RX 5700 XT gfx1010 loads but LFM3's own
Triton conv doesn't compile there (separate fix).

## Related

All from the LFM3 report #16054: #16096 (merged: LFM3 load, chat,
training and export), the Audio-2B chat PR stacked on this one, #16121
(API `reasoning_content`), #16124 (audio + image training), #16098
(video and ffmpeg), unslothai/unsloth-zoo#2278 (LoRA merge on renamed
weights).

<!-- lfm3-audio-ui:start -->

### Audio-input UI evidence

Before `4f4305ea10c4a9940a2a00f7c4b454a47d6e38fc`, after
`1dfec8c3537e3ddda2042eacf6c8f333a157c7da`. The scene runs each side's
actual metadata classifier on the same published configuration, supplies
that measured capability through an intercepted inference-status
response, and opens the real Compare chat attachment menu. Upload audio
is absent before and visible after. This proves metadata-derived
presentation; no model load or generation runs in this scene.

![Before and after audio-input attachment
menu](https://raw.githubusercontent.com/danielhanchen/unsloth-staging-2/pr-media/pr/16242/pr16242_audio_upload_detail-f213e4162adc.png)

<!-- lfm3-audio-ui:end -->

---------

Co-authored-by: Daniel Han <[email protected]>
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.

[Bug] LFM3-Omni Video Input Fails

3 participants