- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 10.9k
Bugfix: Cutlass FP8 FusedMoE #27255
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
          
     Open
      
      
            amirkl94
  wants to merge
  2
  commits into
  vllm-project:main
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
amirkl94:bugfix/cutlass-fused-moe
  
      
      
   
  
    
  
  
  
 
  
      
    base: main
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
      
        
          +34
        
        
          −10
        
        
          
        
      
    
  
  
     Open
                    Bugfix: Cutlass FP8 FusedMoE #27255
Changes from all commits
      Commits
    
    
            Show all changes
          
          
            2 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      
    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
    
  
  
    
              
              
  
    
      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 | ||||
|---|---|---|---|---|---|---|
|  | @@ -570,9 +570,13 @@ def get_fused_moe_quant_config( | |||||
|  | ||||||
| return fp8_w8a8_moe_quant_config( | ||||||
| w1_scale=layer.w13_weight_scale, | ||||||
| g1_alphas=(layer.w13_weight_scale * layer.w13_input_scale).squeeze(), | ||||||
| w2_scale=layer.w2_weight_scale, | ||||||
| g2_alphas=(layer.w2_weight_scale * layer.w2_input_scale).squeeze(), | ||||||
| a1_scale=layer.w13_input_scale, | ||||||
| a1_gscale=layer.w13_input_scale, | ||||||
| a2_scale=layer.w2_input_scale, | ||||||
| a2_gscale=1.0 / layer.w2_input_scale, | ||||||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The calculation  
        Suggested change
       
 | ||||||
| per_act_token_quant=False, | ||||||
| ) | ||||||
|  | ||||||
|  | @@ -1159,8 +1163,8 @@ def __init__( | |||||
| moe: FusedMoEConfig, | ||||||
| layer: torch.nn.Module, | ||||||
| ) -> None: | ||||||
| from vllm.model_executor.layers.quantization.utils.nvfp4_moe_support import ( # noqa: E501 | ||||||
| detect_nvfp4_moe_support, | ||||||
| from vllm.model_executor.layers.quantization.utils.nvfp4_moe_support import ( | ||||||
| detect_nvfp4_moe_support, # noqa: E501 | ||||||
| ) | ||||||
|  | ||||||
| super().__init__(moe) | ||||||
|  | @@ -1773,8 +1777,8 @@ def apply( | |||||
| self.allow_flashinfer | ||||||
| and self.flashinfer_moe_backend == FlashinferMoeBackend.CUTLASS | ||||||
| ): | ||||||
| from vllm.model_executor.layers.fused_moe.flashinfer_cutlass_moe import ( # noqa: E501 | ||||||
| flashinfer_cutlass_moe_fp4, | ||||||
| from vllm.model_executor.layers.fused_moe.flashinfer_cutlass_moe import ( | ||||||
| flashinfer_cutlass_moe_fp4, # noqa: E501 | ||||||
| ) | ||||||
|  | ||||||
| assert self.moe_quant_config is not None | ||||||
|  | ||||||
  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.
To prevent potential division-by-zero errors and for consistency with the recommended fix in the main logic, it's safer to add a small epsilon to the denominator here. While
td.a2_scaleis currently 1.0 in this test, this change improves the robustness of the test suite against future modifications.