Skip to content

Fix Qwen3.5 num_labels not propagated to text_config#44691

Open
gambletan wants to merge 2 commits intohuggingface:mainfrom
gambletan:fix/qwen3_5-num-labels-propagation
Open

Fix Qwen3.5 num_labels not propagated to text_config#44691
gambletan wants to merge 2 commits intohuggingface:mainfrom
gambletan:fix/qwen3_5-num-labels-propagation

Conversation

@gambletan
Copy link

Summary

  • Fixes num_labels (and id2label/label2id) not being propagated from the outer Qwen3_5Config to its inner text_config when passed via AutoConfig.from_pretrained(..., num_labels=1).
  • When text_config is None or a dict, label-related kwargs are now forwarded using setdefault (so explicitly provided text_config values take precedence).
  • Both the modular source (modular_qwen3_5.py) and the auto-generated config (configuration_qwen3_5.py) are updated.

Reproduction (from issue)

from transformers import AutoConfig

config = AutoConfig.from_pretrained(
    "onnx-internal-testing/tiny-random-Qwen3_5ForConditionalGeneration",
    num_labels=1,
)
print(config.num_labels)             # 1
print(config.text_config.num_labels) # 2  <-- should be 1

Fix

Before text_config is instantiated, propagate num_labels, id2label, and label2id from kwargs into text_config (as a dict) using setdefault, so that user-supplied values reach the inner config without overriding explicit text_config entries.

Fixes #44625

Test plan

  • Verify AutoConfig.from_pretrained(model, num_labels=1) sets config.text_config.num_labels == 1
  • Verify explicitly passing text_config={"num_labels": 3} still takes precedence
  • Verify default behavior (no num_labels kwarg) is unchanged (text_config.num_labels == 2)

gambletan and others added 2 commits March 14, 2026 12:09
…Config

When passing num_labels to AutoConfig.from_pretrained for Qwen3.5, the
outer config gets the value but text_config keeps the default (num_labels=2).
This prevents loading Qwen3.5 models for Sequence Classification with
custom num_labels.

Propagate num_labels, id2label, and label2id from kwargs to text_config
before it is initialized, using setdefault to respect explicitly provided
text_config values.

Fixes huggingface#44625
@github-actions
Copy link
Contributor

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

run-slow: qwen3_5

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

1 participant