transformers - ✅(Solved) Fix Qwen3.5 `num_labels` not propagated from core config to text config [1 pull requests, 2 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
huggingface/transformers#44625Fetched 2026-04-08 00:43:05
View on GitHub
Comments
2
Participants
2
Timeline
10
Reactions
0
Author
Timeline (top)
cross-referenced ×3commented ×2referenced ×2labeled ×1

Fix Action

Fixed

PR fix notes

PR #44630: Fix Qwen3.5 num_labels propagation to text_config (fix #44625)

Description (problem / solution / changelog)

What does this PR do?

Fixes a bug where num_labels passed to AutoConfig.from_pretrained for Qwen3.5 did not propagate from the top‑level Qwen3_5Config into the text_config, so AutoModelForSequenceClassification still saw the default text_config.num_labels=2.

This made it impossible to correctly configure Qwen3.5 ForSequenceClassification by just passing num_labels on the main config; users had to manually pass a nested text_config={"num_labels": ..., "id2label": ...} instead (see #44625).

Changes:

  • In Qwen3_5Config (both modular and generated versions), ensure that the text sub-config stays in sync with the top‑level label space:
    • After construction, if text_config.num_labels differs from num_labels, set text_config.num_labels = num_labels.
    • Override __setattr__ so that any later assignment to config.num_labels also updates config.text_config.num_labels.
    • Add an update(...) override in the modular config to keep behavior consistent when configs are updated via config.update(...).

With this change, the reporter’s snippet now behaves as expected:

config = AutoConfig.from_pretrained(model_name, num_labels=1)
assert config.num_labels == 1
assert config.text_config.num_labels == 1

model = AutoModelForSequenceClassification.from_pretrained(model_name, config=config)
assert model.config.num_labels == 1

Fixes #44625

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline, Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the documentation guidelines, and here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

@zucchini-nlp (Qwen / multimodal + classification configs) Optional: @CyrilVallez for config / model-loading context.

Changed files

  • src/transformers/models/qwen3_5/configuration_qwen3_5.py (modified, +22/-0)
  • src/transformers/models/qwen3_5/modular_qwen3_5.py (modified, +20/-0)

Code Example

from transformers import AutoConfig, AutoModelForSequenceClassification

model_name = "onnx-internal-testing/tiny-random-Qwen3_5ForConditionalGeneration"
# Fails:
config = AutoConfig.from_pretrained(model_name, num_labels=1)
# Works:
# config = AutoConfig.from_pretrained(model_name, num_labels=1, text_config={"num_labels": 1, "id2label": {0: "LABEL_0"}})

print(config.num_labels) # 1
print(config.text_config.num_labels) # 2

model = AutoModelForSequenceClassification.from_pretrained(model_name, config=config)
print(model.config.num_labels) # 2

---

You passed `num_labels=1` which is incompatible to the `id2label` map of length `2`.
RAW_BUFFERClick to expand / collapse

System Info

  • transformers version: 5.3.0.dev0
  • Platform: Windows-10-10.0.26200-SP0
  • Python version: 3.11.6
  • Huggingface_hub version: 1.6.0
  • Safetensors version: 0.6.2
  • Accelerate version: 1.13.0.dev0
  • Accelerate config: not found
  • DeepSpeed version: not installed
  • PyTorch version (accelerator?): 2.10.0+cu128 (CUDA)
  • Using distributed or parallel set-up in script?: No
  • Using GPU in script?: No
  • GPU type: NVIDIA GeForce RTX 3090

Who can help?

@zucchini-nlp

Information

  • The official example scripts
  • My own modified scripts

Tasks

  • An officially supported task in the examples folder (such as GLUE/SQuAD, ...)
  • My own task or dataset (give details below)

Reproduction

When passing num_labels to AutoConfig.from_pretrained for Qwen3.5, the outer config has num_labels=1, but the text_config still has the default 2. This prevents me from loading a Qwen3.5 model for Sequence Classification by passing the num_labels to the config. Note that the Sequence Classification model from Qwen3.5 only uses the text config/modality.

from transformers import AutoConfig, AutoModelForSequenceClassification

model_name = "onnx-internal-testing/tiny-random-Qwen3_5ForConditionalGeneration"
# Fails:
config = AutoConfig.from_pretrained(model_name, num_labels=1)
# Works:
# config = AutoConfig.from_pretrained(model_name, num_labels=1, text_config={"num_labels": 1, "id2label": {0: "LABEL_0"}})

print(config.num_labels) # 1
print(config.text_config.num_labels) # 2

model = AutoModelForSequenceClassification.from_pretrained(model_name, config=config)
print(model.config.num_labels) # 2

It only works if I pass text_config={"num_labels": 1, "id2label": {0: "LABEL_0"}}. I also have to pass the id2label part, or I'll get:

You passed `num_labels=1` which is incompatible to the `id2label` map of length `2`.

And it'll still keep the num_labels on the text config at 2.

Expected behavior

I expect the above script to return 1 for all num_labels by having the num_labels on the main config propagate to the subconfigs. I'm not sure if this is the expected behaviour in transformers, or whether this is a bug. Either way, I've not experienced it myself before.

  • Tom Aarsen

extent analysis

Fix Plan

To fix the issue, you need to update the text_config with the correct num_labels when loading the model configuration.

Here are the steps:

  • Load the model configuration using AutoConfig.from_pretrained
  • Update the text_config with the correct num_labels
  • Create the model using AutoModelForSequenceClassification.from_pretrained with the updated configuration

Example Code

from transformers import AutoConfig, AutoModelForSequenceClassification

model_name = "onnx-internal-testing/tiny-random-Qwen3_5ForConditionalGeneration"
num_labels =

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

I expect the above script to return 1 for all num_labels by having the num_labels on the main config propagate to the subconfigs. I'm not sure if this is the expected behaviour in transformers, or whether this is a bug. Either way, I've not experienced it myself before.

  • Tom Aarsen

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

transformers - ✅(Solved) Fix Qwen3.5 `num_labels` not propagated from core config to text config [1 pull requests, 2 comments, 2 participants]