Skip to content

fix: propagate num_labels/id2label to text_config in Qwen3_5Config#44920

Closed
s-zx wants to merge 1 commit intohuggingface:mainfrom
s-zx:fix/qwen3-5-num-labels-propagation-v2
Closed

fix: propagate num_labels/id2label to text_config in Qwen3_5Config#44920
s-zx wants to merge 1 commit intohuggingface:mainfrom
s-zx:fix/qwen3-5-num-labels-propagation-v2

Conversation

@s-zx
Copy link
Copy Markdown

@s-zx s-zx commented Mar 22, 2026

What does this PR do?

Fixes num_labels not being propagated from Qwen3_5Config to its text_config when loading via AutoConfig.from_pretrained(model, num_labels=N).

Root cause: Qwen3_5Config.__post_init__ initializes text_config with default label settings, then calls super().__post_init__(**kwargs) which correctly sets self.id2label on the outer config. However, text_config already has the default id2label (2 labels) and never gets updated.

Fix: After super().__post_init__(**kwargs) runs, propagate id2label and label2id from the outer config to text_config when num_labels or id2label was explicitly provided.

Before:

config = AutoConfig.from_pretrained(model_name, num_labels=1)
print(config.num_labels)             # 1
print(config.text_config.num_labels) # 2  ← wrong

After:

config = AutoConfig.from_pretrained(model_name, num_labels=1)
print(config.num_labels)             # 1
print(config.text_config.num_labels) # 1  ← correct

Both modular_qwen3_5.py and the generated configuration_qwen3_5.py are updated.

Fixes #44625

…t_config

When num_labels (or id2label) is passed to AutoConfig.from_pretrained,
super().__post_init__(**kwargs) correctly sets self.id2label on the outer
config, but the already-initialized text_config retains its default
id2label (2 labels). This prevents Qwen3_5ForSequenceClassification from
using the correct number of labels.

Fix by propagating id2label and label2id from the outer config to
text_config after super().__post_init__() runs, when num_labels or
id2label was explicitly provided.

Fixes huggingface#44625
@github-actions
Copy link
Copy Markdown
Contributor

[For maintainers] Suggested jobs to run (before merge)

run-slow: qwen3_5

@zucchini-nlp
Copy link
Copy Markdown
Member

Nope, not what we want as per comment under the issue. Also we'd need a bigger PR to sync all multimodal/nested models

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.

Qwen3.5 num_labels not propagated from core config to text config

3 participants