You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Design feedback: MODEL_TASK_DEFAULTS introduces a second parallel registry
sam.py now expresses the same fact — "sam2's canonical export task is mask-generation" — in two places:
# 1. MODEL_TASK_DEFAULTSMODEL_TASK_DEFAULTS= {"sam2": "mask-generation"}
# 2. MODEL_CLASS_MAPPING (already implies this via its primary entry)MODEL_CLASS_MAPPING= {
("sam2", "mask-generation"): SAM2MaskGeneration, # same information
("sam2", "feature-extraction"): Sam2VisionEncoder,
}
The value of MODEL_TASK_DEFAULTS["sam2"] and the key of MODEL_CLASS_MAPPING's primary entry are the same string. Adding a new model now requires keeping two tables in sync, with no enforcement — it's easy to define MODEL_TASK_DEFAULTS["newmodel"] = "task-a" while forgetting to add ("newmodel", "task-a") to MODEL_CLASS_MAPPING, causing a silent wrong-class fallback.
Alternative: encode the default task as a None-sentinel entry in MODEL_CLASS_MAPPING
# sam.py — one table instead of twoMODEL_CLASS_MAPPING= {
("sam2", None): "mask-generation", # None = default task for auto-detection
("sam2", "mask-generation"): SAM2MaskGeneration,
("sam2", "feature-extraction"): Sam2VisionEncoder,
...
}
_get_custom_model_class reads the sentinel before the class lookup:
Single table; the sentinel entry structurally enforces that a matching class entry must exist
task.py no longer imports MODEL_TASK_DEFAULTS — all model-specific data flows through the existing MODEL_CLASS_MAPPING path
Adding a new model still only requires editing hf/newmodel.py
The only cost is that MODEL_CLASS_MAPPING's value type becomes str | type (sentinel entries hold a task string, others hold a class). Worth considering as a follow-up if this pattern is going to extend to other model families.
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
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.
No description provided.