Skip to content

Qwen3 MOE models w/non-empty mlp_only_layers fail when output_router_logits=True #39203

@ntenenz

Description

@ntenenz

System Info

MLPs insert a None into the router logit list. Therefore, when enabled in the model, they need to be filtered out either before or within the aux_loss function.

Who can help?

@ArthurZucker

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

from transformers import AutoConfig, AutoModelForCausalLM

config = AutoConfig.from_pretrained("Qwen/Qwen3-30B-A3B")  # or any qwen3_moe model
config.update({"mlp_only_layers": [0]})  # or any non-empty list
model = AutoModelForCausalLM.from_config(config)

_ = model(INPUT_TOKENS, output_router_logits=True)  # raises an error in the aux_loss function

Expected behavior

Model should output router logits and not raise an exception.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions