Skip to content

Studio: LFM3-Omni audio input, export, LoRA defaults and Stop for custom-code generate - #16242

Merged
danielhanchen merged 36 commits into
unslothai:mainfrom
LeoBorcherding:leo/lfm3-omni-audio-upstream
Nov 3, 2026
Merged

danielhanchen merged 36 commits into
unslothai:mainfrom
LeoBorcherding:leo/lfm3-omni-audio-upstream

Conversation

@LeoBorcherding

@LeoBorcherding LeoBorcherding commented Oct 30, 2026 •

Copy link
Copy Markdown
Collaborator

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 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.

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

before: attach refused after: attached
GIFs of the full flow

Before:

After:

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 (Studio: chat with LFM3-Audio-2B (text and speech in, text out) #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).

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

LeoBorcherding and others added 30 commits October 30, 2026 03:18
The tier probe parses config.json with trust_remote_code=False, so a custom-code
config (LFM3) fails in every sidecar and lands on the 5.3.0 floor, where its
@strict config class cannot load. Route these by transformers_version instead,
and offer the latest transformers when no installed tier is new enough.
LFM3-Omni's remote generate lists cache_implementation in
_generation_fields_unsupported and raises when it is set, so FastModel's
generate wrapper failed on every call. Leave the cache fields unset for
such models.
LFM3-Omni's remote generate raises on logits_processor and stopping_criteria,
which every Studio chat request sets, so each prompt failed with an internal
error. Drop them for models that mark a custom generate.
LFM3-Omni's processor signature is (text, audio, ..., images), so the
positional (images, text) call handed it the image as text and failed.
…adapters

A text-only LoRA on a VLM saves a bare tokenizer, so the export load wrapped
no processor: merged exports had no processor_config.json or processor code
(AutoProcessor fails) and GGUF skipped the mmproj. Wrap the adapter's
tokenizer in the base model's processor. The load also leaves training's
use_cache=False on every config, which a merged config.json then persists;
restore it, since custom generate code can reject use_cache=False.
[skip ci]
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
…-upstream

# Conflicts:
#	studio/backend/core/inference/inference.py
#	studio/backend/tests/test_custom_generate_kwargs.py
#	studio/backend/tests/test_transformers_latest.py
#	studio/backend/utils/transformers_latest.py
#	studio/backend/utils/transformers_version.py
@LeoBorcherding

Copy link
Copy Markdown
Collaborator Author

Codex review on the fork mirror (LeoBorcherding#658) found no major issues at 2e57e2dc8d, this PR's head: result. Before/after screenshots (WAV refused vs answered, Stop mid-reply) are on the mirror.

@LeoBorcherding

Copy link
Copy Markdown
Collaborator Author

CI clean on the fork mirror (LeoBorcherding#658) at 2e57e2dc8d. Nothing red comes from this diff: Backend a-f was a timing flake in test_web_fetch_extraction that passed on rerun (job), and pip scan hf-stack is the zoo digest baseline main also failed on until 1341718c2c (run). Core zoo was cancelled by the fork's time limit mid-pytest, not failed.

@danielhanchen danielhanchen self-assigned this Nov 2, 2026
danielhanchen added a commit to NilayYadav/unsloth that referenced this pull request Nov 2, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 2, 2026
danielhanchen added a commit to NilayYadav/unsloth that referenced this pull request Nov 2, 2026
shimmyshimmer pushed a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Nov 2, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 2, 2026
shimmyshimmer pushed a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Nov 2, 2026
@danielhanchen

danielhanchen commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

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

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 6ad796d512 (this PR's d06f82aef)

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

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: 6ad796d512

No triage reaction was recorded on the mirror

Verdict

The round converged at mirror 6ad796d512 (this PR's d06f82aef).

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

@danielhanchen
danielhanchen merged commit 2548528 into unslothai:main Nov 3, 2026
danielhanchen added a commit that referenced this pull request Nov 3, 2026
Replaces #16128, which GitHub closed when #16096 merged and its base
branch was deleted. Built on merged #16242. This PR adds LFM3-Audio-2B
chat through the multimodal loader; its diff now contains only the child
layer.

LFM3-Audio-2B takes audio in and answers in text, but it has no image
processor, so Unsloth Studio loaded it on the text path. That builds the
bare `Lfm3AudioModel`, which has no `generate()`.

- A processor whose `audio_token` sits beside a `feature_extractor` is
now typed `audio_vlm`, as an image processor already does for LFM3-Omni,
so audio input is advertised.
- An `audio_vlm` checkpoint with no vision loads through
`AutoModelForMultimodalLM` (`Lfm3AudioForConditionalGeneration` via the
repo's `auto_map`). Audio turns use the existing audio-input path, text
turns the text path. A load that still can't generate is refused by
name, as before.
- Omni and Gemma 3n keep the VLM load. Plain text models are unchanged.

Tests: the focused loader, metadata and generation suites pass all 64
tests on Transformers 4.57.6 and 5.22.1 after integrating the parent
squash. Retained differentials reproduce the missing audio
classification and chat loader. Tiny random checkpoints also exercise
real GPU FastModel loading and text/synthetic-audio turns in 16-bit and
4-bit modes; they do not establish pretrained output quality.

Original real-model check reported by the author on Colab G4 (RTX PRO
6000), Linux, transformers 5.22.1, at `f03b06a0cd`: Audio-2B answered
"Four" to a text question and "The capital of France is Paris." to a
spoken WAV question. LFM3-Omni-2B still loads as a VLM and answers text,
image and WAV turns.

Not covered: the audio-input path doesn't split `<think>` reasoning yet,
so Audio-2B's spoken-question replies include it raw. Unsloth Studio
LoRA training on Audio-2B still loads without the multimodal class, and
merging its LoRA needs unslothai/unsloth-zoo's remote-code rename fix.

Part of #16054.

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

### Audio-input UI evidence

Before `25485284fe5de5f612432a2c3810fc2110f5d2f2` (merged parent
#16242), after `02f00f83945292dc46ae08e89837c05266cbe9bb` (child with
the parent squash integrated). This pair isolates the child layer
against its current merge base. 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/16243/pr16243_audio_upload_detail-1945e7c9a1bc.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>
LeoBorcherding added a commit to LeoBorcherding/unsloth that referenced this pull request Nov 8, 2026
…o voice mode any-audio

Conflicts were the LFM3 backend and tests, where this branch held older fork copies
of what main now has (unslothai#16242, unslothai#16243, unslothai#16972): C's versions are kept, and this
branch's spoken-reply streaming is re-applied on top, with main's unset speech budget
moved into the shared _speech_inputs. chat-page keeps C's releaseBeforeBorrow, which
already releases an owned voice when the chat model's voice is picked, so the
duplicate voiceReplacedByServing is dropped.
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.

2 participants