fix(task): make detect_task architecture-aware for multi-task model types#841
Merged
Conversation
…ypes detect_task short-circuited on the first (model_type, task) key in MODEL_CLASS_MAPPING, so every encoder-decoder type (bart/t5/marian/...) auto-detected as feature-extraction regardless of the architecture head and disagreed with the head-aware config/build path. Short-circuit only when a model_type maps to exactly one real task; otherwise fall through to architecture-aware detection. A (model_type, None) default-class sentinel no longer forces a fall-through, so single-real-task types like sam resolve to their real task (mask-generation).
DingmaomaoBJTU
left a comment
Collaborator
There was a problem hiding this comment.
Overall this is a correct and clean fix. The core logic is sound: collect only the non-None task entries for a given model_type, and short-circuit only when there is exactly one — otherwise fall through to the architecture-aware TasksManager path. Three issues worth addressing below.
Addresses PR review: annotate distinct_tasks as set[str] (so next(iter(...)) types as str), add a sam2 multi-task fall-through regression test, and mark test_task_consistency as network since it calls AutoConfig.from_pretrained.
…into zhiwang/detect-task-head-aware
DingmaomaoBJTU
approved these changes
Jun 9, 2026
DingmaomaoBJTU
left a comment
Collaborator
There was a problem hiding this comment.
3 of 4 previously raised issues are resolved. One remains open (see inline comment).
- Type safety (
distinct_tasks: set[str]) ✅ Fixed. sam2unit test (test_detect_task_falls_through_for_multi_task_model_type_sam2) ✅ Added.- Network marker (
pytestmark = pytest.mark.network) ✅ Applied module-wide with a helpful comment. - Performance (O(n) scan) — Still open; see inline comment. Not a blocker given the current mapping size, but worth tracking.
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.
What
detect_taskshort-circuited to the first(model_type, task)key inMODEL_CLASS_MAPPING, so every encoder-decoder model type (bart,t5,marian,mu2,qwen3,blip,vision-encoder-decoder) auto-detected asfeature-extractionregardless of the architecture head — and disagreed with the already-head-awareconfig/buildpath (which uses_detect_task_and_class_from_config).Change
Short-circuit step 1 only when a
model_typemaps to exactly one real (non-None) task. With multiple distinct tasks, fall through to architecture-aware detection. A(model_type, None)default-class sentinel no longer forces a fall-through, so single-real-task types likesamresolve to their real task (mask-generation).Result —
inspectnow agrees withconfig/build*
fill-maskfor seq2seq generation models is still semantically wrong (optimum mapsBartForConditionalGenerationtofill-mask). This PR only makesinspectconsistent withconfig/build. Correcting*ForConditionalGeneration -> text2text-generation— which changes build artifacts and needs atext2text-generationexport path — is Step 2, tracked in #838.Tests
Nonesentinel (sam) resolves to its real task; a single-entry type still short-circuits.test_task_consistency): addedbart-large-mnli -> text-classificationandsam-vit-base -> mask-generation.Addresses #838 (Step 1 of 2).