Fix experts implementation in two spots#47097
Open
remi-or wants to merge 3 commits into
Open
Conversation
|
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. |
Contributor
CI recapDashboard: View test results in Grafana |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes one potential bug and one regression:
_optimize_model_for_decodeis 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)_optimize_model_for_decodethe 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 theset_experts_implementationfunction 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 togrouped_mm. This calls_grouped_mm_can_dispatchand it crashes because_can_set_experts_implementationis false. This PR fixes that by skipping submodules where_can_set_experts_implementationis 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.