Skip to content

Conversation

@yiwzhao
Copy link
Collaborator

@yiwzhao yiwzhao commented Dec 5, 2025

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.

@yiwzhao yiwzhao requested a review from piyifan123 December 5, 2025 05:20
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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.

Comment on lines 59 to 63
elif (
"ForSequenceClassification" in architecture
and type(model_config) in AutoModelForSequenceClassification._model_mapping.keys()
):
load_class = AutoModelForSequenceClassification
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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.

@Luosuu Luosuu changed the title [model][feat]: add AutoModelForSequenceClassification support in HuggingfaceLoader [model] feat: add AutoModelForSequenceClassification support in HuggingfaceLoader Dec 7, 2025
elif type(model_config) in AutoModelForVision2Seq._model_mapping.keys(): # assume built-in models
load_class = AutoModelForVision2Seq
elif (
"ForSequenceClassification" in architecture
Copy link
Collaborator

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?

@yiwzhao yiwzhao closed this Jan 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants