Skip to content

fix(audio): do not read an unreadable tokenizer_config.json as "not an audio model" - #8625

Merged
danielhanchen merged 13 commits into
unslothai:mainfrom
LeoBorcherding:fix/audio-type-detection-not-definitive
Aug 13, 2026
Merged

danielhanchen merged 13 commits into
unslothai:mainfrom
LeoBorcherding:fix/audio-type-detection-not-definitive

Conversation

@LeoBorcherding

Copy link
Copy Markdown
Collaborator

The bug

An Orpheus LoRA run failed with:

Dataset conversion failed: Could not auto-detect format mapping
Training error: Could not auto-detect format mapping

The dataset was GianDiego/orpheus-tts-spanish-female, whose columns are audio, text, file_id. _resolve_audio_columns accepts audio/speech and text/sentence/transcript/transcription, so that dataset needs no mapping at all and never reaches the code that complained.

Root cause

detect_audio_type returns None for two different answers: "definitely not an audio model" and "the repo could not be read". Its own docstring says so, and points callers gating a user action at detect_audio_type_checked, which returns (type, definitive). routes/models.py uses the checked variant and surfaces the flag as audio_type_known. The trainer used the ambiguous one.

On this host tokenizer_config.json was not readable, so:

detect_audio_type("unsloth/orpheus-3b-0.1-ft")                        -> 'snac'
detect_audio_type("unsloth/orpheus-3b-0.1-ft", local_files_only=True) -> None

_audio_type became None, is_audio became False, the snac branch was skipped, and the run fell through to the text chat-template path, which cannot map an audio dataset. The error a user sees is a column-mapping complaint about a dataset with correct columns, seven steps from the read that failed.

Any cause of an unreadable tokenizer_config.json produces this: a gated repo without a token, offline mode, or a cache holding a model's weights but not its tokenizer files.

The fix

Both probe sites take detect_audio_type_checked and keep the definitive flag next to the type, so a reassignment cannot leave the flag describing the previous probe. When the probe was inconclusive and the dataset has an audio column, the run stops and names the file it could not read:

Could not determine whether this model is an audio model: its tokenizer_config.json could not be read (gated repo, offline, or a cache holding the weights but not the tokenizer files). The dataset has an audio column, so training cannot fall back to the text path. Re-download the model or provide a token, then retry.

Deliberately narrow

probe dataset before after
definitive "not audio" any text path unchanged
inconclusive no audio column text path unchanged
inconclusive has audio column text path, misleading error refused, names the file
detected audio type any audio branch unchanged

A text run against a gated repo keeps working. Only the case that was already broken changes.

The guard reads its two inputs through getattr. load_and_format_dataset is also driven against lightweight stand-ins that set only the attributes they exercise, and a probe that never ran is not an inconclusive one, so both defaults leave the guard closed. I found this the direct way: without it, seven test_training_preflight tests failed on 'types.SimpleNamespace' object has no attribute '_audio_type_known'.

Tests

Five, three of which fail without the change. The behavioral ones drive the real load_and_format_dataset through the existing preflight stub pattern and assert on what reaches _update_progress: the refusal names tokenizer_config.json and does not say "Could not auto-detect format mapping". The other two cases assert the unaffected paths still return a dataset and report nothing.

84 passed  (this suite, audio token detection, training preflight, audio decode)

One pre-existing failure, test_the_soundfile_decoder_resamples_to_the_cast_rate, reproduces on a clean main checkout and is untouched here.

Related

Does not overlap #8436, which installs the audio decode shim before the worker reads a row. That one fixed the decode failure this run hit first; this one fixes the misdiagnosis that followed it. Both were visible in the same session, in that order.

Not addressed

Why the tokenizer files were missing from the active cache in the first place. That traces to Studio resolving models against one HF cache root while the model picker scans several, which needs its own report.

…dio model"

detect_audio_type returns None for both "definitely not an audio model" and "the
repo could not be read", and its docstring already says callers gating a user
action want detect_audio_type_checked instead. The trainer used the ambiguous one
to pick a preprocessing path.

So a TTS run whose tokenizer_config.json was unreadable -- gated repo, offline, or
a cache holding the weights but not the tokenizer files -- came back None, the
model was treated as text, the snac/csm/bicodec/dac branches were skipped, and the
run failed further along with "Could not auto-detect format mapping". That names a
column-mapping problem on a dataset whose columns were fine, and says nothing
about the read that actually failed.

Both probe sites now take the checked variant and keep the definitive flag beside
the type, so a reassignment cannot leave the flag describing the previous probe.
When the probe was inconclusive and the dataset has an audio column, the run stops
and names the file it could not read.

Deliberately narrow: a definitive "not audio" is unchanged, and an inconclusive
probe on a dataset with no audio column still trains on the text path, so a text
run against a gated repo keeps working. The guard reads its two inputs through
getattr because this method is also driven against lightweight stand-ins, and a
probe that never ran is not an inconclusive one.
@LeoBorcherding LeoBorcherding changed the title Studio: do not read an unreadable tokenizer_config.json as "not an audio model" fix(audio): do not read an unreadable tokenizer_config.json as "not an audio model" Aug 12, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 7d0dadfb30

ℹ️ 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_dataset_audio reaches the trainer from the client, which fills it from the format
check's is_audio. That flag is set by a column-NAME keyword match
(audio|speech|wav|waveform|sound) that never inspects the value, so a text dataset
with a column called audio holding filenames arrives here flagged as audio. Combined
with an inconclusive probe, the new guard refused a run that previously took the text
path and worked.

The loaded dataset's own features answer this exactly, so the refusal now stands down
when the schema positively shows no Audio column. Unknown schemas (a DatasetDict, an
iterable dataset) still refuse: not being able to tell is not evidence of absence, and
an unreadable model probe remains the likelier explanation.

Adds three cases: a text dataset with an audio-named column is no longer refused, a
real Audio column still is, and a dataset that cannot report a schema still is.
@danielhanchen

Copy link
Copy Markdown
Member

Reviewed this together with #8436 and validated both end to end.

The fix works, but it cannot be demonstrated against its own merge base

Measured on this host: at 22cb12ec, an inconclusive probe on an audio dataset dies at To support decoding audio data, please install 'torchcodec'. before it can reach the text path at all, because this box has torchcodec installed with FFmpeg's shared libraries absent. #8436 is what gets a decoder into the worker; without it, this PR's effect is unreachable and a before/after comparison shows two identical torchcodec errors.

So the honest pair is #8436's head versus #8436 + this PR:

#8436 alone + this PR
banner a format/column complaint Could not determine whether this model is an audio model: its tokenizer_config.json could not be read (gated repo, offline, or a cache holding the weights but not the tokenizer files)...
phase / step error, step 0 error, step 0 (unchanged — the claim is a better refusal, not a run that now succeeds)

Induced with a complete openai/whisper-tiny snapshot with only tokenizer_config.json withheld — the exact cause your description names. Measured on both sides rather than assumed: detect_audio_type_checked returns ('whisper', True) intact and (None, False) withheld. Worth knowing: the base already logged tokenizer_config.json was unreadable four times; what it could not do was act on it.

That variant is also the only workable one. pre_detect_and_load_tokenizer calls AutoTokenizer.from_pretrained with no try/except (trainer.py:305-327) and the failure propagates at worker.py:4135, so a gated repo or an offline cache miss — which also go non-definitive — abort before the dataset and never reach your guard. Whisper's tokenizer loads from config.json + tokenizer.json alone, so it survives.

One fix pushed: a false positive that took away working behaviour

_is_dataset_audio arrives from the client, which fills it from the format check's is_audio. That flag is set by a column-name keyword match (audio|speech|wav|waveform|sound) at utils/datasets/format_detection.py:487-493 which never inspects the value. So a text dataset with a column called audio holding filenames arrives here flagged as audio, and combined with an inconclusive probe the guard refused a run that previously took the text path and worked.

The blast radius is narrower than it first looks — \b means sound_effects and audio_id do not match — but audio, speech, sound, wav and waveform do.

The loaded dataset's own features answer this exactly, so the refusal now stands down when the schema positively shows no Audio column. Unknown schemas (a DatasetDict, an iterable dataset) still refuse: not being able to tell is not evidence of absence, and an unreadable probe remains the likelier explanation. Three cases added; the false-positive one fails without the change.

What I checked beyond that

  • The definitive flag never goes stale. Both _audio_type = None sites after an audio_vlm answer leave _audio_type_known alone, which is correct — audio_vlm is a definitive answer, so the guard stays shut. There is no third probe site.
  • Truth table. All 16 combinations of _audio_type × known × dataset_audio: the refusal fires in exactly one, and the getattr defaults keep it closed for objects missing any of the three attributes.
  • Text runs are untouched — identical outcomes on the merge base, each PR alone, and both merged. An inconclusive probe with a non-audio dataset is never refused, which is the case that would have turned a narrow audio fix into an outage.
  • [Windows, Linux, WSL, macOS] × [NVIDIA, AMD, CPU]: the added lines carry no host-specific branching, and audio on Apple Silicon is rejected earlier at worker.py:3368.
  • The refusal string renders without overflow in Chromium (Chrome/Edge), Firefox and WebKit (Safari) at 1500/1024/768/414/360 px — it is ~11× longer than what it replaces and contains an unbreakable 21-character token, which is the only browser-visible risk here.
  • detect_audio_type stays exported, signatures unchanged, no new imports, no frontend file touched.

Both PRs merge cleanly with each other. Suites: 88 in the audio/preflight modules on this branch, plus 282 source-level and 26 end-to-end checks across the merge base, each PR, and both combined.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: fd538b8d5e

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

…usal

Three cases where the inconclusive-probe guard answered wrongly.

An audio dataset loaded from JSON or CSV carries its audio as a Value(string) of
paths until the preprocessor casts it, which _preprocess_snac_dataset does, so
checking the schema alone called a real audio dataset textual and handed it to the
text path the guard exists to prevent. The helper now looks at the values when the
schema has no Audio feature, which is safe there precisely because nothing decodes.

raw and CPT runs read the text column and ignore any audio one by design, so they
are not the unsafe audio-to-text fallback being guarded, and refusing them removed a
valid way to pretrain on transcripts. They are exempt.

The probe and the tokenizer load are two reads of the same repo, so a timeout or 5xx
could leave the probe inconclusive while the download right after it succeeded, and
the run was then refused claiming tokenizer_config.json was unreadable when it had
just been read. It is asked again once the tokenizer is in, and only a definitive
answer replaces the first.

Four tests, each failing without its own change.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

pre-commit-ci Bot and others added 2 commits August 13, 2026 10:05
…, and sniff more than one row

Two follow-ups on the previous commit.

The loader is chosen from the audio type, so the retry probe that runs after the
tokenizer is loaded could flip the type to whisper (or spark) with an AutoTokenizer
already stored on self.tokenizer. _preprocess_whisper_dataset reads .feature_extractor
and .tokenizer off the processor, so every sample would be skipped and the run would
end with "No valid examples after Whisper preprocessing". The tokenizer load is now a
local function that the retry calls again when, and only when, the answer changed.

The value fallback used to read a single row, so a dataset whose first audio value is
null or empty was reported textual and the guard reopened the unsafe text path. It now
sniffs up to 16 rows and answers None ("unknown", keep refusing) when it never saw a
usable value at all.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

pre-commit-ci Bot and others added 2 commits August 13, 2026 10:27
… judge only audio-named columns

Two follow-ups on the previous commit.

The retry sat after a successful tokenizer load, so it could not help the one layout
that needs it most. An inconclusive probe leaves the audio type None, the Spark-TTS
subfolder kwarg is chosen from that type, and the repo root holds no tokenizer, so the
read raises before the retry runs. The retry is now a local function called from the
failure path as well: re-probe, and if the answer changed, load again for it. A load
that fails with an already definitive type still propagates untouched.

The row sniff took any populated field as evidence that a dataset is textual, but a
path-backed audio dataset has a transcript in every row, so a run of null audio values
inside the sniff window answered False on the strength of the text. Only a column whose
name matches the keywords that set the flag can answer False now; audio-like values
still count wherever they appear, and no evidence either way stays unknown.
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 13, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 13, 2026
@unslothai unslothai deleted a comment from LeoBorcherding Aug 13, 2026
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: bec5f39754

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

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

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

self._audio_type,
self.is_audio,
)
return self._audio_type != previous_type

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 audio-VLM detection when deciding to retry

When the initial probe is inconclusive and the first tokenizer load fails, a successful retry that detects audio_vlm sets _audio_type back to None before this comparison. Since previous_type was also None, the function returns False, and the exception handler at line 458 re-raises the original load error instead of retrying. This specifically prevents recovery from a transient tokenizer-load failure for Gemma audio-VLM models; compare the detected retried_type before normalizing audio_vlm, or return a separate state-changed flag.

Useful? React with 👍 / 👎.

@danielhanchen
danielhanchen merged commit e10ed80 into unslothai:main Aug 13, 2026
31 of 40 checks passed
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