Repository navigation
Resolve the auto class for omni checkpoints, and guard embedding lookups - #11467
Conversation
Two load failures on Qwen/Qwen3-Omni-30B-A3B-Instruct, transformers 5.17.0. First, the architecture is named Qwen3OmniMoeForConditionalGeneration so it reads as a VLM, but transformers registers qwen3_omni_moe only under AutoModelForTextToWaveform. AutoModelForVision2Seq then raises 'Unrecognized configuration class' before any weight is touched. The existing auto_map fallback does not help, because this is a native transformers architecture with no auto_map at all. Consult the other auto classes only when the chosen one genuinely has no mapping for the config, and fall back to the concrete class the checkpoint names. Anything that resolves today is unchanged. vision.py keys is_vlm off the selected class to decide between AutoProcessor and AutoTokenizer, so the same membership test now covers the omni auto classes; a model registered under AutoModelForTextToWaveform still needs a processor. Second, for_training and for_inference guarded their embedding lookups with hasattr(model, 'get_input_embeddings'). That is not the question: transformers 5 defines the method on every PreTrainedModel and has the base implementation raise NotImplementedError, so a composite checkpoint with no single embedding passes the hasattr check and then raises. Every other caller in this file already asks by calling and catching, including the existing patch_enable_input_require_grads; these two were the exceptions. Verified on 8xB200, torch 2.13.0+cu130, transformers 5.17.0, 10 step LoRA runs at seq 512. unsloth/gemma-3-27b-it and meta-models/Muse-Glimmer-30B produce losses identical to main to every digit, and Qwen/Qwen3.6-35B-A3B matches within its own run to run MoE noise. Qwen3-Omni now loads, quantizes and attaches LoRA where it previously failed at from_pretrained.
_patched_enable_input_require_grads caught NotImplementedError, which covers the transformers 5 base implementation, but not the other way a model declines to answer: remote code can declare a non-standard signature. stepfun-ai/Step-3.7-Flash defines get_input_embeddings(self, input_ids), so calling it with no arguments raises TypeError and the run dies inside prepare_model_for_training. Neither case is a model to guess about, so treat them the same and skip.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
… omni-auto-class-resolution
Widening is_vlm to the omni auto classes also armed the image-processor
repair path in vision.py, so loading a speech-seq2seq checkpoint called
_construct_vlm_processor_fallback("openai/whisper-tiny", "whisper") --
an image processor build for an audio model, measured as 1 invocation on
this branch against 0 on main.
is_vlm goes back to exactly the image-text classes it names on main, and
processor selection moves to its own predicate. AutoModelForSpeechSeq2Seq
is dropped from both lists: Whisper already reaches AutoProcessor through
is_whisper, so it never needed to be there.
Adds tests/test_omni_auto_class_resolution.py, which pins the omni
resolution, that ordinary VLMs are never rerouted, and that Whisper stays
out of the set.
|
@codex review |
|
@codex security review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 257f9ded38
ℹ️ 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".
| for architecture in architectures or []: | ||
| model_class = getattr(transformers, str(architecture), None) | ||
| if model_class is not None: | ||
| return model_class |
There was a problem hiding this comment.
Resolve remote waveform registrations from auto_map
When a trust_remote_code omni checkpoint registers only AutoModelForTextToWaveform in config.auto_map, the preceding loader branch ignores that key and resolve_model_class cannot discover the dynamic registration. Falling back to getattr(transformers, architecture) also cannot find a class defined only in the checkpoint's remote module, so this path returns None and the original unsupported image-text auto class still fails. Inspect the waveform entry in auto_map when selecting the auto class rather than assuming the concrete remote class is exported by transformers.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not taking this one. It describes a checkpoint shape nobody has named: Qwen3-Omni, the model this PR exists for, is native to transformers and carries no auto_map. For the hypothetical remote-code omni checkpoint, the outcome is that the resolver returns None, the caller keeps the class it already chose, and the existing error surfaces unchanged, which is exactly main's behaviour. So there is no regression to fix, only an unhandled case, and 5706656 deliberately narrowed this helper further in the same direction. Reading auto_map for a waveform entry can be added when a real checkpoint needs it and can be tested against.
The resolver could return AutoModelForCausalLM, AutoModel, or the concrete class the checkpoint names. None of those is in the processor set, so for a config the loader had already identified as multimodal, head picked an AutoTokenizer where main picked an AutoProcessor. The candidate list is now exactly the two multimodal auto classes, and the concrete-architecture fallback is gone. Nothing matching returns None, which leaves the caller's own choice alone and so reproduces main exactly. A test asserts every name the resolver can return is in the processor set, so the two lists cannot drift apart again.
_resolve_offload_embedding caught the exception but handed an explicit offload_embedding=True straight back, and the caller then calls model.get_input_embeddings() unguarded, so the load failed on exactly the models the function exists to keep loading. Its own docstring says the offload is a VRAM optimisation and should be turned off where it cannot help rather than failing the load. Qwen3-Omni only reaches that line now that it gets past auto-class resolution, so this PR is what makes it reachable. Declining also prints the reason for an explicit request and stays silent for the default, which is what _decline already does everywhere else here.
Qwen3OmniMoeConfig keeps its vision config under thinker_config, so the hasattr term is False, and with is_vlm correctly narrowed to the image-text classes is_vlm_config was False too. That skipped the fast_inference guard and called load_vllm, get_vllm_state_dict and convert_vllm_to_huggingface with is_vision_model=False for a model qwen3_omni_moe is not listed in VLLM_SUPPORTED_VLM for. is_vlm_config now also takes needs_processor, which is the same multimodal intent without arming the image-processor repair path that is_vlm gates. The guard's existing message is the result instead of a failure further inside vLLM. Re-ran the earlier evidence after the change: Whisper still makes zero calls to _construct_vlm_processor_fallback, and the real Qwen3-Omni checkpoint still resolves to AutoModelForTextToWaveform and reaches weight loading.
|
Codex Review: Didn't find any major issues. 👍 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
Codex Review: Didn't find any major issues. Can't wait for the next one! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
Codex Review: Didn't find any major issues. 🚀 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
…d up The comment said AutoModelForImageTextToText is bound only on transformers 5 and that naming it directly would NameError on 4.x. The declared floor, 4.51.3, ships that class, so the try branch of the import above succeeds across the whole supported range and the fallback branch is dead; 5.5.0 is the version that drops AutoModelForVision2Seq. The lookup is still the right call, for the opposite reason to the one given.
Catching TypeError around the call could not tell a getter that declines to take zero arguments from one that takes zero arguments and fails inside. The second is a real bug in the model, and swallowing it silently cost that module its input-gradient hook: under PEFT with gradient checkpointing the frozen embedding output then carries no gradient, so backward fails or the adapter trains on nothing. Bind the signature before calling. Only a genuine argument mismatch skips; a TypeError raised inside a working getter propagates as it did before this branch. An uninspectable getter falls through to the call, since undecidable is not a reason to skip.
|
pre-commit.ci run |
|
Codex Review: Didn't find any major issues. What shall we delve into next? Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
Delete-first pass over what this branch introduced, not the files around it. Multi-line rationales collapse to one line each, the measured asides and restatements go, and the facts that cannot be recovered from the code stay: why the concrete-class fallback is wrong, why Whisper must stay out of the multimodal set, why an uninspectable embedding declines an explicit request. Comment lines added by the branch: 52 to 33. Comments, docstrings and whitespace only; comment_tools.py check reports 4/4 code unchanged.
#11450 landed on main as one squashed commit, so GitHub retargeted this PR to main and the merge no longer recognised the base commits this branch already carried. Three conflicts, all of the same shape: this branch adds a block where main has none, so HEAD wins in each. The rest of import_fixes.py auto merged, which matters because main moved on separately, and the resolution keeps that work: nothing in main's copy of any of the three files is missing here. The part the merge got wrong on its own: main carries the quant_state check at _gpu_init.py:110 with its `del` at 123, and this branch moved the call below the repair with its own `del`. Auto merge kept both, which is not merely the duplicate warning #11452 already fixed once, it is a NameError on `import unsloth`, since the second `del` deletes a name the first already removed. `test_the_check_is_called_once_and_after_the_repair` catches the duplicate call that causes it. Resolved to one call, after the repair, and one `del`. Verified after resolving: no duplicate top-level definitions, 106 passed and 4 skipped across the three suites, and 24 passed with 1 skipped in a venv holding only pytest and packaging. test_formatter_fixed_point reports studio/backend/tests/test_diffusion_xpu_training.py and tests/test_omni_auto_class_resolution.py as not fixed points. Both arrived from main today, in #9534 and #11467, and the same test fails on main itself at b7aca55, so they are pre-existing and not touched here.
…ups (unslothai#11467) * Resolve the auto class for omni checkpoints, and guard embedding lookups Two load failures on Qwen/Qwen3-Omni-30B-A3B-Instruct, transformers 5.17.0. First, the architecture is named Qwen3OmniMoeForConditionalGeneration so it reads as a VLM, but transformers registers qwen3_omni_moe only under AutoModelForTextToWaveform. AutoModelForVision2Seq then raises 'Unrecognized configuration class' before any weight is touched. The existing auto_map fallback does not help, because this is a native transformers architecture with no auto_map at all. Consult the other auto classes only when the chosen one genuinely has no mapping for the config, and fall back to the concrete class the checkpoint names. Anything that resolves today is unchanged. vision.py keys is_vlm off the selected class to decide between AutoProcessor and AutoTokenizer, so the same membership test now covers the omni auto classes; a model registered under AutoModelForTextToWaveform still needs a processor. Second, for_training and for_inference guarded their embedding lookups with hasattr(model, 'get_input_embeddings'). That is not the question: transformers 5 defines the method on every PreTrainedModel and has the base implementation raise NotImplementedError, so a composite checkpoint with no single embedding passes the hasattr check and then raises. Every other caller in this file already asks by calling and catching, including the existing patch_enable_input_require_grads; these two were the exceptions. Verified on 8xB200, torch 2.13.0+cu130, transformers 5.17.0, 10 step LoRA runs at seq 512. unsloth/gemma-3-27b-it and meta-models/Muse-Glimmer-30B produce losses identical to main to every digit, and Qwen/Qwen3.6-35B-A3B matches within its own run to run MoE noise. Qwen3-Omni now loads, quantizes and attaches LoRA where it previously failed at from_pretrained. * Also skip models whose get_input_embeddings cannot be called at all _patched_enable_input_require_grads caught NotImplementedError, which covers the transformers 5 base implementation, but not the other way a model declines to answer: remote code can declare a non-standard signature. stepfun-ai/Step-3.7-Flash defines get_input_embeddings(self, input_ids), so calling it with no arguments raises TypeError and the run dies inside prepare_model_for_training. Neither case is a model to guess about, so treat them the same and skip. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Keep Whisper out of the vision-model membership test Widening is_vlm to the omni auto classes also armed the image-processor repair path in vision.py, so loading a speech-seq2seq checkpoint called _construct_vlm_processor_fallback("openai/whisper-tiny", "whisper") -- an image processor build for an audio model, measured as 1 invocation on this branch against 0 on main. is_vlm goes back to exactly the image-text classes it names on main, and processor selection moves to its own predicate. AutoModelForSpeechSeq2Seq is dropped from both lists: Whisper already reaches AutoProcessor through is_whisper, so it never needed to be there. Adds tests/test_omni_auto_class_resolution.py, which pins the omni resolution, that ordinary VLMs are never rerouted, and that Whisper stays out of the set. * Only ever resolve to a class that takes a processor The resolver could return AutoModelForCausalLM, AutoModel, or the concrete class the checkpoint names. None of those is in the processor set, so for a config the loader had already identified as multimodal, head picked an AutoTokenizer where main picked an AutoProcessor. The candidate list is now exactly the two multimodal auto classes, and the concrete-architecture fallback is gone. Nothing matching returns None, which leaves the caller's own choice alone and so reproduces main exactly. A test asserts every name the resolver can return is in the processor set, so the two lists cannot drift apart again. * Decline an embedding offload we cannot inspect, explicit or not _resolve_offload_embedding caught the exception but handed an explicit offload_embedding=True straight back, and the caller then calls model.get_input_embeddings() unguarded, so the load failed on exactly the models the function exists to keep loading. Its own docstring says the offload is a VRAM optimisation and should be turned off where it cannot help rather than failing the load. Qwen3-Omni only reaches that line now that it gets past auto-class resolution, so this PR is what makes it reachable. Declining also prints the reason for an explicit request and stays silent for the default, which is what _decline already does everywhere else here. * Carry the multimodal intent into the vLLM guard Qwen3OmniMoeConfig keeps its vision config under thinker_config, so the hasattr term is False, and with is_vlm correctly narrowed to the image-text classes is_vlm_config was False too. That skipped the fast_inference guard and called load_vllm, get_vllm_state_dict and convert_vllm_to_huggingface with is_vision_model=False for a model qwen3_omni_moe is not listed in VLLM_SUPPORTED_VLM for. is_vlm_config now also takes needs_processor, which is the same multimodal intent without arming the image-processor repair path that is_vlm gates. The guard's existing message is the result instead of a failure further inside vLLM. Re-ran the earlier evidence after the change: Whisper still makes zero calls to _construct_vlm_processor_fallback, and the real Qwen3-Omni checkpoint still resolves to AutoModelForTextToWaveform and reaches weight loading. * Update the two tests the offload and embedding changes moved * Correct the version note on why the multimodal auto classes are looked up The comment said AutoModelForImageTextToText is bound only on transformers 5 and that naming it directly would NameError on 4.x. The declared floor, 4.51.3, ships that class, so the try branch of the import above succeeds across the whole supported range and the fallback branch is dead; 5.5.0 is the version that drops AutoModelForVision2Seq. The lookup is still the right call, for the opposite reason to the one given. * Ask the embedding getter's signature instead of catching its TypeError Catching TypeError around the call could not tell a getter that declines to take zero arguments from one that takes zero arguments and fails inside. The second is a real bug in the model, and swallowing it silently cost that module its input-gradient hook: under PEFT with gradient checkpointing the frozen embedding output then carries no gradient, so backward fails or the adapter trains on nothing. Bind the signature before calling. Only a genuine argument mismatch skips; a TypeError raised inside a working getter propagates as it did before this branch. An uninspectable getter falls through to the call, since undecidable is not a reason to skip. * Trim the comments added by this branch Delete-first pass over what this branch introduced, not the files around it. Multi-line rationales collapse to one line each, the measured asides and restatements go, and the facts that cannot be recovered from the code stay: why the concrete-class fallback is wrong, why Whisper must stay out of the multimodal set, why an uninspectable embedding declines an explicit request. Comment lines added by the branch: 52 to 33. Comments, docstrings and whitespace only; comment_tools.py check reports 4/4 code unchanged. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Problem
Qwen/Qwen3-Omni-30B-A3B-Instructcannot be loaded at all:The checkpoint names
Qwen3OmniMoeForConditionalGeneration, so it reads as aVLM and
FastModelpicksAutoModelForVision2Seq. transformers registersqwen3_omni_moeonly underAutoModelForTextToWaveform, and asking an autoclass that has no mapping is a hard failure before the weights are touched,
not a fallback.
Two further assumptions break on the same class of model:
is_vlmwas decided by membership in the two image-text auto classes, so anomni checkpoint registered elsewhere was treated as text-only and given a
tokenizer where it needs a processor.
for_trainingandfor_inferenceguard their embedding lookups withhasattr(model, "get_input_embeddings"). That is not the question ontransformers 5, which defines the method on every
PreTrainedModelwith abase implementation that raises
NotImplementedError. A compositecheckpoint passes the
hasattrcheck and then raises. The rest of the filealready asks by calling and catching; these two callers did not.
Fix
_resolve_omni_auto_modeltries the auto classes an omni checkpoint may beregistered under, most specific first, and returns
Nonewhen none of themmaps the config, so the caller keeps its own choice and the existing error
surfaces unchanged. Falling back to the concrete class the checkpoint names
was tried and removed: a concrete class is in no auto mapping, so it took the
model out of the processor set and downgraded it to an
AutoTokenizer. It isconsulted only when the class already chosen has no mapping for the
config, so every checkpoint that resolves today keeps the exact class it
resolves to now.
_multimodal_auto_classes()builds theis_vlmmembership test at calltime from the names that exist in the installed transformers, so the audio
and speech auto classes count as multimodal without naming anything that is
absent on 4.x.
_embeddings_or_nonereplaces the twohasattrguards, asking by calling._patched_enable_input_require_gradsskips a module whoseget_input_embeddingsraises. Besides theNotImplementedErrorabove,remote code can declare a signature that cannot be called with no arguments:
stepfun-ai/Step-3.7-Flashdefinesget_input_embeddings(self, input_ids),which raised
TypeErrorstraight out ofprepare_model_for_training._resolve_offload_embeddingnow declines the offload when the model'sembeddings cannot be inspected, instead of honouring an explicit
offload_embedding = Truethrough the failure. Its caller goes straight onto call
get_input_embeddings()unguarded, so honouring the request turned aVRAM optimisation that cannot be applied into a failed load, which is the
outcome this function exists to avoid. Qwen3-Omni reaches this line only now
that it loads at all.
Scope
This moves Qwen3-Omni from failing inside
from_pretrainedto loading. Itdoes not make it trainable: the top-level
Qwen3OmniMoeForConditionalGenerationdefines no
forwardof its own (the trainable text model is the thinker), soa training step still fails, and plain Transformers plus PEFT fails the same
way on the same checkpoint. The remaining work is a separate matter from
picking the right auto class.
Platform coverage
Run on three runners, each installing torch, torchvision, transformers, numpy, accelerate,
peft, trl, datasets and unsloth_zoo first, plus
triton-windowson Windows, soimport unslothcompletes and the tests really execute rather than skipping for want of a dependency. Counts are
the executed totals, not the colour of the badge:
tests/test_omni_auto_class_resolution.py+ the two suites this PR movedubuntu-latest(x64 Linux)windows-latest(x64 Windows)macos-15(Apple Silicon)The red check was inherited from
main, andmainhas since fixed itRepo tests (CPU, studio)was red at3696f9781with 13 failures, all intests/studio/test_desktop_reliability_frontend_contract.py,tests/studio/test_ui_font_scale_contract.pyandtests/studio/test_update_release_notes.py. This branch changes no file understudio/.A
pull_requestrun tests a merge built when the run was created, so the run kept failing againsta
mainthat had already moved. Checkingmainout on its own at1fd6b42d0leaves 1 of the 13:test_no_raw_pixel_text_utilities, onstudio/frontend/src/features/settings/components/cache-storage-rows.tsxusing
text-[11px]where the contract wants atext-ui-*token, which arrived with #10528. #11520then fixed that line on
mainas well.So all 13 are
main's, andmainnow carries every fix. Merging currentmaininto this branchrebuilds the merge ref, and those three suites are
244 passedlocally at the merged head.Earlier runs of this branch were also red on all three
Core zoolegs, from two unsloth_zoosecurity tests at the pinned revision that failed identically on #11468 with a
disjoint diff. Those are green again now.
What this still does not prove
Qwen3-Omni trains. It does not, and the Scope section above says why: the top-level class has no
forwardof its own. Plain Transformers plus PEFT fails the same way on the same checkpoint, sothis is not a regression introduced or hidden by the change.