fix(build): honor loader.model_class on pretrained load path#997
Merged
Conversation
The pretrained branch of _load_model dropped the explicit config.loader.model_class when calling load_hf_model, so class resolution fell back to the (model_type, task) lookup alone. After #836 began threading config.loader.model_type as a build-variant override, CLIP feature-extraction broke: the variant tag 'clip_text_model' is not a key in MODEL_CLASS_MAPPING (which is keyed on the native 'clip'), so resolution fell through to AutoModel and loaded the full CLIPModel. Export with text-only inputs then failed with 'You have to specify pixel_values'. Forwarding model_class lets resolve_task take its Stage-0 user-class path, which resolves CLIPTextModelWithProjection directly and ignores the model_type override. Safe for the qwen3 transformer-only variant since Stage 0 only activates when model_class is set.
KayMKM
approved these changes
Jun 30, 2026
DingmaomaoBJTU
approved these changes
Jun 30, 2026
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.
Problem
winml build -c <build_config.json> -m openai/clip-vit-base-patch32 --device cpufails with:even though the build config explicitly requests the text-only CLIP variant:
Root cause
Bisected to #836 (
3946a01, "Enable static quantization for Qwen3-0.6B decoder").The pretrained branch of
_load_model(build/hf.py) calledload_hf_modelwithout forwardingconfig.loader.model_class, so class resolution depended entirely on the(model_type, task)lookup inMODEL_CLASS_MAPPING.#836 began threading
config.loader.model_typeintoload_hf_modelas a build-variant override. For CLIP this regresses resolution:model_type = "clip_text_model".MODEL_CLASS_MAPPINGis keyed on the native type:("clip", "feature-extraction") -> CLIPTextModelWithProjection."clip_text_model"is not a key, so resolution falls through toTasksManager→AutoModel→ the fullCLIPModel, which requirespixel_values. Export with text-only inputs then fails.The override scheme works for
qwen3_transformer_onlybecause that variant tag is a registered key; CLIP's is not, and the explicitmodel_classthat would have saved it was dropped on the pretrained path (the random-init path already honors it).Fix
Forward
config.loader.model_classtoload_hf_modelon the pretrained path.resolve_taskthen takes its Stage-0 user-class path, resolvingCLIPTextModelWithProjectiondirectly and ignoring themodel_typeoverride. Safe for the qwen3 transformer-only variant since Stage 0 only activates whenmodel_classis set.Verification
CLIPTextModelWithProjectionand exporting text-only inputs through optimize + fp16.test_pretrained_load_threads_model_class.tests/unit/build/,tests/unit/loader/test_load_hf_model.py,tests/unit/commands/test_build.pyall pass (192 + new test).