Repository navigation
Studio: detect audio input for LFM3-Omni from the processor's audio_token - #16101
Closed
LeoBorcherding wants to merge 13 commits into
Closed
LeoBorcherding wants to merge 13 commits into
LeoBorcherding wants to merge 13 commits into
Conversation
LFM3-Omni ships a transformers 5 tokenizer_config.json with no added_tokens_decoder, so the <|audio|> marker audio detection looks for only lives in tokenizer.json and processor_config.json. Studio typed the model vision-only, dropped attached audio and sent the prompt as text. Read processor_config.json too and count its audio_token, limited to the markers the tokenizer patterns already accept.
Detecting LFM3-Omni's audio_token (a19ca07) types it audio_vlm, and the export gated the vision load on having no audio_type at all. An image LoRA then exported through the text load: the merged folder had no processor_config.json or processor code, so AutoProcessor failed on it. Let audio_vlm through the vision probe, so the load wraps the base processor like any VLM adapter.
…configs LFM3-Audio-2B's config.json has no top-level transformers_version; only its lfm and depthformer sub-configs carry 5.19.0.dev0. The custom-code routing read the top level only, so the load stayed on tier 530 and failed with 'Lfm3Config must be a dataclass before applying @strict'.
The default q/k/v/o/gate/up/down list has no match for LFM3's w1/w2/w3 MLP, so an audio run trained attention only and stalled at loss ~1.7 where all-linear reaches ~0.003 on the same data.
LFM3-Omni's generate rejects stopping_criteria, so dropping them left a stop match or a user cancel running to max_new_tokens while holding the generation lock. The cancel and stop events now ride on the streamer: put() raises once one is set, the custom generate ends its streamers and unwinds, and the worker treats that as an early finish.
A processor's audio_token now marks audio_vlm only beside an image processor (LFM3-Omni). LFM3-Audio-2B has none, so it was typed audio_vlm, loaded on the text path as the bare Lfm3AudioModel and failed on the first chat turn. A text load that cannot generate is now refused by name.
# Conflicts: # studio/backend/tests/test_custom_generate_kwargs.py
Collaborator
Author
|
Codex review on the fork mirror (LeoBorcherding#658) is clean at
Tested on Colab A100 and G4, an AMD RX 9060 XT on Linux, and Windows AMD (load only). Audio-path Stop on a T4 (LFM3-Omni-2B, WAV question, cancel after 8 chunks, then a text request): at Not actioned here: with an audio+image dataset on an audio-input model, training dropped the images. That's |
…into leo/lfm3-omni-audio-upstream
This was referenced Oct 30, 2026
This was referenced Oct 30, 2026
Merged
danielhanchen
added a commit
to NilayYadav/unsloth
that referenced
this pull request
Nov 2, 2026
…et (unslothai#16124) Training an audio VLM (Gemma 3n, Gemma 4, LFM3-Omni) in Unsloth Studio on a dataset with both audio and image columns trained on audio + text only. There was no warning, and the images never reached the model. **Why.** `pre_detect` routes these runs to the audio VLM path and sets `is_vlm` False (`trainer.py:615`, `:1313`). That routing is fine, since the path loads with `FastModel` and the processor takes images and audio together. But `_format_audio_vlm_dataset` built an audio + text user turn, and `audio_vlm_collate_fn` called `processor(text=, audio=)` with no `images`. **Fix.** - The formatter finds the image column (mapped `image` role, else detection) and adds one image slot per image. A list-of-images column stays a list. - The collator passes each row's images as RGB. - The eval split uses the same image column as the train split. - Audio-only datasets go through the exact same processor call as before. **Tests.** `tests/test_trainer_audio_vlm_image_and_audio.py`, 7 tests, CPU only: 3 fail on main, all pass here. Existing audio VLM masking and eval-split tests pass. **Real processor check** (Gemma 3n E2B processor on CPU, no weights): | dataset | `pixel_values` | image tokens / row | audio tokens / row | |---|---|---|---| | main, one image per row | missing | 0 | 188 | | this PR, one image per row | (2, 3, 768, 768) | 256 | 188 | | this PR, rows with 1 and 2 images | (3, 3, 768, 768) | 256 / 512 | 188 | **GPU train** (A100 40GB, unsloth/gemma-3n-E2B-it, Unsloth Studio trainer, 80 steps; each colour maps to an arbitrary code, so it can only be learned from the image; scored on 8 held-out images): | commit | batch | held-out answers | |---|---|---| | main base `a00356eecf` | no `pixel_values` | 1/8 | | this PR `11fe262f1a` | `pixel_values` (4, 3, 768, 768) | 8/8 | | `11fe262f1a`, two images per row | `pixel_values` (8, 3, 768, 768) | 5 steps ran | | `11fe262f1a`, rows with and without an image | images `[[img], [], [], []]` | 5 steps ran | Not run: LFM3-Omni's processor. Found while testing LFM3 for unslothai#16054; related to unslothai#16101. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Daniel Han <[email protected]>
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: attach refused | after: attached | |---|---| |  |  | <details><summary>GIFs of the full flow</summary> Before:  After:  </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.  <!-- 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>
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.
Stacked on #16096 (base branch
studio-lfm3-custom-code-load), which LFM3-Omni needs to load at all. Review only the top commit,47e13ed470.What breaks
LiquidAI/LFM3-Omni-2B(safetensors, custom code) loads as vision-only. The backend logsis_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_decoderintokenizer_config.json(<|audio|>/<audio_soft_token>->audio_vlm). LFM3-Omni was saved by transformers 5, whosetokenizer_config.jsonhas noadded_tokens_decoderat all:<|audio|>only lives intokenizer.jsonand inprocessor_config.json("audio_token": "<|audio|>"). So detection read the tokenizer config, found nothing, and answered a definitive "not audio".Fix
processor_config.jsonjoins the files audio detection reads (local dir, HF cache and Hub), andclassify_audio_tokenscounts a config'saudio_token. Only the markers the tokenizer patterns already accept route toaudio_vlm, so Qwen2-Audio's<|AUDIO|>stays where it was.generate_audio_input_responseneeded no change: it goes throughprocessor.apply_chat_template, and transformers' base implementation calls the processor withtext=,audio=by keyword, so LFM3's text-first signature is not a problem on this path (the positional issue Studio: load LFM3 custom-code models (route by saving transformers version, fix generate, chat and export) #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.0782561c9aa19ca071ed/api/models/configaudio_type=None,has_audio_input=False,model_type=visionaudio_type=audio_vlm,has_audio_input=TrueGIFs of the full flow
Before:
After:
Image chat still works after the change (
/v1/chat/completionswith 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 on0782561c9a, green here. Every test file touchingtokenizer_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_forfailed once in the loaded full run and passes alone.Not covered
audio_out) is untouched; this is audio in, text out./v1/chat/completionsnon-streaming, LFM3's image answer lands inreasoning_contentwith emptycontent. Separate from this PR.Related
All from the same LFM3-Omni report (#16054): #16096 (LFM3 load, chat, training and export), #16098 (video input when ffmpeg is missing).