- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 10.9k
Add the support for the qwen3 next model (a hybrid attention model). #24526
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
    
      
        
          +2,476
        
        
          −61
        
        
          
        
      
    
  
  
     Merged
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            17 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      a41c465
              
                Add the support for the qwen3 next model (a hybrid attention model).
              
              
                sighingnow 26c707f
              
                MTP + full cuda graph bugfix.
              
              
                sighingnow 1282d73
              
                Fixes the typo.
              
              
                sighingnow c0243db
              
                Fixes lint issues.
              
              
                sighingnow 1e10ee3
              
                GDN attn: optimize the attn metadata preparation.
              
              
                sighingnow 6416eeb
              
                Fixes the CI failures.
              
              
                sighingnow 93c7aae
              
                Fixes loading quantization models for qwen3_next and qwen3_next_mtp.
              
              
                sighingnow 861de80
              
                Fixes cases for non-cuda-graph settings.
              
              
                sighingnow 2ff5f2d
              
                Merge remote-tracking branch 'origin/main' into dev/qwen3.5-moe
              
              
                sighingnow 6291179
              
                Remove the debug print.
              
              
                sighingnow 3e946b3
              
                Fixes bugs with cuda graph padding for non-mtp cases.
              
              
                sighingnow 035d3ff
              
                Fixes the l2 norm implementation in fused_recurrent.
              
              
                sighingnow 6de8124
              
                Fixes a size bug in spec_token_masks.
              
              
                sighingnow 2027f9c
              
                Merge remote-tracking branch 'origin/main' into dev/qwen3.5-moe
              
              
                sighingnow 5fe3249
              
                Remove the safe_exp, apply https://github.com/fla-org/flash-linear-at…
              
              
                sighingnow 0a6515d
              
                Merge branch 'main' into dev/qwen3-next
              
              
                jeejeelee 558f9f4
              
                Fixes a bug in l2_normal kernel.
              
              
                sighingnow File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      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
    
  
  
    
              
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -1 +1,2 @@ | ||
| collect_env.py | ||
| vllm/model_executor/layers/fla/ops/*.py | 
  
    
      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
    
  
  
    
              
  
    
      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
    
  
  
    
              
              
  
    
      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
    
  
  
    
              
  
    
      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
    
  
  
    
              
  
    
      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
    
  
  
    
              
              
  
    
      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
    
  
  
    
              
  
    
      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
    
  
  
    
              
  
    
      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
    
  
  
    
              
  
    
      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
    
  
  
    
              
  
    
      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
    
  
  
    
              
  
    
      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
    
  
  
    
              
              
  
    
      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
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -70,6 +70,15 @@ def short_conv_state_dtype( | |
| model_dtype) | ||
| return (conv_state_dtype, ) | ||
|  | ||
| @classmethod | ||
| def gated_delta_net_state_dtype( | ||
| cls, | ||
| model_dtype: Union[ModelDType, torch.dtype], | ||
| mamba_cache_dtype: MambaDType, | ||
| ) -> tuple[torch.dtype, torch.dtype]: | ||
| state_dtype = get_kv_cache_torch_dtype(mamba_cache_dtype, model_dtype) | ||
| return (state_dtype, state_dtype) | ||
|          | ||
|  | ||
|  | ||
| class MambaStateShapeCalculator: | ||
|  | ||
|  | @@ -163,3 +172,31 @@ def extra_groups_for_head_shards(cls, ngroups: int, tp_size: int): | |
|  | ||
| # for n_groups == 1, this is exactly tp_size - n_groups | ||
| return tp_size - ngroups | ||
|  | ||
| @classmethod | ||
| def gated_delta_net_state_shape( | ||
| cls, | ||
| tp_world_size: int, | ||
| num_k_heads: int, | ||
| num_v_heads: int, | ||
| head_k_dim: int, | ||
| head_v_dim: int, | ||
| conv_kernel_size: int, | ||
| num_spec: int = 0, | ||
| use_v1: bool = True, | ||
| ): | ||
| conv_dim = (head_k_dim * num_k_heads * 2 + head_v_dim * num_v_heads) | ||
| conv_state_shape = ( | ||
| divide(conv_dim, tp_world_size), | ||
| conv_kernel_size - 1 + num_spec, | ||
| ) | ||
|  | ||
| # In V0, the conv_state shape was swapped during allocation in | ||
| # MambaCacheManager, but in V1 it needs to be determined here at the | ||
| # calculation level | ||
| if use_v1: | ||
| conv_state_shape = conv_state_shape[1], conv_state_shape[0] | ||
|  | ||
| temporal_state_shape = (divide(num_v_heads, | ||
| tp_world_size), head_k_dim, head_v_dim) | ||
| return conv_state_shape, temporal_state_shape | ||
      
      Oops, something went wrong.
        
    
  
  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.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This
elifblock forqwen3_next_mtpis nearly identical to the preceding blocks forernie_mtpanddeepseek_mtp. This code duplication makes the code harder to maintain and increases the risk of bugs if one block is updated but the others are not.Consider refactoring these blocks to reduce duplication. For example:
This would replace lines 2221-2250 and make the code more scalable and maintainable for future MTP models.