-
Notifications
You must be signed in to change notification settings - Fork 138
[model] feat: add AutoModelForSequenceClassification support in HuggingfaceLoader #256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request adds support for AutoModelForSequenceClassification in HuggingfaceLoader. The changes are straightforward, involving an import and a new condition to select the correct model class. However, I've identified a significant issue with the logic for selecting the model class. The current implementation, which your change follows, relies on checking only the first architecture from the model's config. This can lead to incorrect model class selection if the desired architecture (e.g., for sequence classification) is not the first in the list. I've left a detailed comment with high severity on this issue. Addressing this would make the model loader much more robust.
veomni/models/loader.py
Outdated
| elif ( | ||
| "ForSequenceClassification" in architecture | ||
| and type(model_config) in AutoModelForSequenceClassification._model_mapping.keys() | ||
| ): | ||
| load_class = AutoModelForSequenceClassification |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While this change correctly adds support for AutoModelForSequenceClassification, it inherits a potential issue from the existing logic. The architecture variable is derived from _get_model_arch_from_config, which only considers the first element if model_config.architectures is a list. This can cause this check to fail if the ...ForSequenceClassification architecture is not the first in the list. For example, if model_config.architectures is ['MistralModel', 'MistralForSequenceClassification'], architecture will be 'MistralModel' and this condition will fail.
To make this more robust, you should check against all architectures in model_config.architectures. This would likely require refactoring how architecture is obtained and used throughout this if/elif chain, including for the ForCausalLM case. A robust implementation would handle model_config.architectures as a list (or ensure it is one) and check if any of the items contain the target substring. This is a high-severity issue as it can lead to incorrect model loading.
veomni/models/loader.py
Outdated
| elif type(model_config) in AutoModelForVision2Seq._model_mapping.keys(): # assume built-in models | ||
| load_class = AutoModelForVision2Seq | ||
| elif ( | ||
| "ForSequenceClassification" in architecture |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would this break ForCausalLM from loading? or the config would properly point to that?
anyway, is it possible to write a simple unit test for this function?
I added AutoModelForSequenceClassification support in our HuggingfaceLoader so that whenever a config’s architectures indicate a ForSequenceClassification class, we now instantiate the corresponding HF classification model instead of falling back to AutoModel.