Skip to content

Fix experts implementation in two spots#47097

Open
remi-or wants to merge 3 commits into
mainfrom
fix-experts-impl
Open

Fix experts implementation in two spots#47097
remi-or wants to merge 3 commits into
mainfrom
fix-experts-impl

Conversation

@remi-or

@remi-or remi-or commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

CI

This PR fixes one potential bug and one regression:

  • in the main generate loop, the context manager _optimize_model_for_decode is entered / exited for every single token generated, rather than wrapping the decode as a whole. This PR fixes that: it leads to improvements for small MoEs like Qwen3-Omni-30B thinker (+5.2% eager on B200)
  • in _optimize_model_for_decode the entirety of the model is walked, which can lead to a bug in multimodal models. If there is a model with an MoE text model and an image model with no MoE, the model enters the set_experts_implementation function and starts iterating on all submodules, regardless of whether or not they _can_set_experts_implementation. On exit, for the vision submodules, the context manager tries to restore a non-existent experts implementation, falling back to grouped_mm. This calls _grouped_mm_can_dispatch and it crashes because _can_set_experts_implementation is false. This PR fixes that by skipping submodules where _can_set_experts_implementation is False, and since that function is expensive to call, we add a cached flag on the class when can the method successfully runs. Same for the attn setter.

Results: for models like Llava with a MoE text model and a non-MoE vision encoder, no more crashes. For tiny MoEs: better perf.

@remi-or remi-or requested a review from ArthurZucker July 6, 2026 06:57
@remi-or remi-or self-assigned this Jul 6, 2026
@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

CI recap

Dashboard: View test results in Grafana
Latest run: 28775802395:1
Result: failure | Jobs: 15 | Tests: 171,050 | Failures: 6 | Duration: 22h 46m

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