Skip to content

Measure routing mismatch for Qwen models#4060

Open
xuefgu wants to merge 1 commit into
mainfrom
xfgu-routing-mismatch
Open

Measure routing mismatch for Qwen models#4060
xuefgu wants to merge 1 commit into
mainfrom
xfgu-routing-mismatch

Conversation

@xuefgu

@xuefgu xuefgu commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator

Description

This PR implements MoE routing mismatch measurement during training. It compares the model's natural routing decisions with forced_routed_experts passed to the model call, and logs the average mismatch rate.

Crucially, this PR only measures the mismatch and does not force the routing. The model's natural routing is still used for the actual computation.

The changes are only scoped to Qwen3 and Qwen3.5. More model support should be added at a later time.

Tests

Unit tests.

Checklist

Before submitting this PR, please make sure (put X in square brackets):

  • I have performed a self-review of my code. For an optional AI review, add the gemini-review label.
  • I have necessary comments in my code, particularly in hard-to-understand areas.
  • I have run end-to-end tests tests and provided workload links above if applicable.
  • I have made or will make corresponding changes to the doc if needed, including adding new documentation pages to the relevant Table of Contents (toctree directive) as explained in our documentation.

@xuefgu xuefgu force-pushed the xfgu-routing-mismatch branch from 2139c05 to 533473f Compare June 4, 2026 00:06
@xuefgu xuefgu changed the title Measure routing mismatch for Qwen and DeepSeek models Measure routing mismatch for Qwen models Jun 4, 2026
@xuefgu xuefgu force-pushed the xfgu-routing-mismatch branch 3 times, most recently from 718e421 to db2b48f Compare June 4, 2026 00:22
@codecov

codecov Bot commented Jun 4, 2026

Copy link
Copy Markdown

@xuefgu xuefgu force-pushed the xfgu-routing-mismatch branch 12 times, most recently from 7dafd25 to fc983eb Compare June 8, 2026 21:41
@xuefgu xuefgu marked this pull request as ready for review June 9, 2026 21:34
Comment thread src/maxtext/layers/decoders.py Outdated
Comment thread src/maxtext/layers/moe.py
Comment thread src/maxtext/layers/nnx_decoders.py Outdated
@xuefgu xuefgu force-pushed the xfgu-routing-mismatch branch from 61fd64d to 1b071c3 Compare June 18, 2026 18:04
Calculate the mismatch rate between model-calculated routing and externally
supplied forced_routed_experts. This is limited to Qwen3 and Qwen3.5 models
in training mode.

The mismatch rate is logged as 'learning/routing_mismatch_rate'.
@xuefgu xuefgu force-pushed the xfgu-routing-mismatch branch from 1b071c3 to 58e4ddc Compare June 18, 2026 18:15
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