Fix CTC model class resolution by passing model_type to TasksManager#1154
Open
codykk wants to merge 2 commits into
Open
Fix CTC model class resolution by passing model_type to TasksManager#1154codykk wants to merge 2 commits into
codykk wants to merge 2 commits into
Conversation
codykk
marked this pull request as ready for review
July 21, 2026 03:43
DingmaomaoBJTU
approved these changes
Jul 22, 2026
xieofxie
reviewed
Jul 22, 2026
codykk
force-pushed
the
yongyue/fix-ctc-model-class-resolution
branch
from
July 22, 2026 06:12
9d42f4d to
0643c4d
Compare
added 2 commits
July 22, 2026 15:56
When a task like automatic-speech-recognition maps to multiple model classes (AutoModelForSpeechSeq2Seq, AutoModelForCTC), Optimum defaults to the first one without model_type context. This caused CTC-based ASR models (e.g. Wav2Vec2ForCTC) to fail with an incorrect class. Passing model_type_norm enables Optimum to select the correct class per architecture family. Add regression recipe for jonatasgrosman/wav2vec2-large-xlsr-53-russian (cpu/fp32 and cpu/fp16).
The USER_TASK branch called get_model_class_for_task without model_type, causing models like Wav2Vec2 (CTC) to resolve to AutoModelForSpeechSeq2Seq instead of AutoModelForCTC when task is explicit but model_class is not. Add regression test for explicit-task resolution without model-class override.
codykk
force-pushed
the
yongyue/fix-ctc-model-class-resolution
branch
from
July 22, 2026 07:56
0643c4d to
8fe87bf
Compare
xieofxie
reviewed
Jul 22, 2026
| try: | ||
| resolved = TasksManager.get_model_class_for_task(normalized, framework="pt") | ||
| resolved = TasksManager.get_model_class_for_task( | ||
| normalized, framework="pt", model_type=model_type_norm or None |
Contributor
There was a problem hiding this comment.
Please pass the raw model_type to TasksManager here rather than model_type_norm. The normalization is needed for WinML's internal mapping keys, but Optimum registers some model types with underscores. For example, speech_to_text is a supported Transformers model type; converting it to speech-to-text prevents Optimum from matching AutoModelForSpeechSeq2Seq, so explicit ASR resolution raises instead of resolving the class. The Stage 2 call added by this PR has the same issue. Please keep model_type_norm for _get_custom_model_class, pass model_type to both TasksManager calls, and add an underscore-containing regression case.
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.
Pass
model_typeto Optimum'sTasksManager.get_model_class_for_taskinresolve_task()Stage 2, fixing model class resolution for all CTC-based ASR architectures (Wav2Vec2ForCTC, HubertForCTC, WavLMForCTC, etc.). One-line generalized fix — no per-model hardcoding. Add regression recipe forjonatasgrosman/wav2vec2-large-xlsr-53-russian(cpu/fp32, cpu/fp16).Effort: L1-light | Goal: L1 (perf) | Outcome: L1
Model metadata
automatic-speech-recognition(CTC decoding)Wav2Vec2ForCTC
├── Wav2Vec2FeatureEncoder (7 CNN layers: raw audio → features)
├── Wav2Vec2FeatureProjection (LayerNorm + Linear → hidden_size=1024)
├── Wav2Vec2Encoder (24× transformer layers, 16 heads)
└── Linear CTC head (1024 → 39 Cyrillic vocab)
Validation and support evidence
Baseline (main): Build FAIL —
Unrecognized configuration class Wav2Vec2Config for this kind of AutoModel: AutoModelForSpeechSeq2SeqRoot cause:
TasksManager.get_model_class_for_task("automatic-speech-recognition")withoutmodel_typedefaults toAutoModelForSpeechSeq2Seq; CTC models needAutoModelForCTC.Goal ceiling: L1 (perf) — L2/L3 CLI-BLOCKED (
automatic-speech-recognitionnot inwinml evalsupported tasks)Outcome: L1 — generalized code fix + regression recipes
Delta:
resolution.pyline 647 — addedmodel_type=model_type_norm or None. Whenmodel_type_normis available (fromconfig.model_type), Optimum looks up the correct class per architecture family instead of defaulting to the first registered class. Empty string falls back toNone(original behavior preserved).Reproduce: