forked from vllm-project/vllm
    
        
        - 
                Notifications
    You must be signed in to change notification settings 
- Fork 50
[FEAT] Add support for AITER bpreshuffle block scale gemm #717
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
          
     Closed
      
      
            tjtanaavllm
  wants to merge
  3
  commits into
  llama_fp8_03122025
from
llama_fp8_03122025_bpreshuffleblockscale
  
      
      
   
      
    
  
     Closed
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            3 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
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # SPDX-FileCopyrightText: Copyright contributors to the vLLM project | ||
| from enum import IntEnum | ||
| from typing import Optional | ||
|  | ||
| import torch | ||
|  | @@ -8,6 +9,16 @@ | |
| from vllm.utils import direct_register_custom_op | ||
|  | ||
|  | ||
| class AITEROpMode(IntEnum): | ||
| NO_AITER = 0 | ||
| AITER = 1 | ||
| SWIZZLE_AITER = 2 | ||
|  | ||
|  | ||
| def use_swizzle(n: int, k: int, layout: tuple[int, int]) -> bool: | ||
| return n % layout[0] == 0 and k % (layout[1] * 2) == 0 | ||
|  | ||
|  | ||
| def use_swizzle_gemm(n: int, k: int, dtype: torch.dtype) -> bool: | ||
|  | ||
| multiple_of: int = 64 | ||
|  | @@ -84,4 +95,37 @@ def rocm_aiter_tuned_gemm( | |
| out_dtype=out_dtype, | ||
| scale_a=scale_a, | ||
| scale_b=scale_b, | ||
| ) | ||
| ) | ||
|  | ||
| @staticmethod | ||
| def gemm_a8w8_blockscale( | ||
| A: torch.Tensor, | ||
| B: torch.Tensor, | ||
| As: torch.Tensor, | ||
| Bs: torch.Tensor, | ||
| block_size: list[int], | ||
| output_dtype: torch.dtype = torch.float16, | ||
| ) -> torch.Tensor: | ||
| import aiter as rocm_aiter | ||
|  | ||
| return rocm_aiter.gemm_a8w8_blockscale(A, | ||
| B, | ||
| As, | ||
| Bs, | ||
| dtype=output_dtype) | ||
|  | ||
| @staticmethod | ||
| def gemm_a8w8_blockscale_bpreshuffle( | ||
| A: torch.Tensor, | ||
| B: torch.Tensor, | ||
| As: torch.Tensor, | ||
| Bs: torch.Tensor, | ||
| block_size: list[int], | ||
| 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. same here, the block_size parameter | ||
| output_dtype: torch.dtype = torch.float16, | ||
| ) -> torch.Tensor: | ||
| import aiter as rocm_aiter | ||
| return rocm_aiter.gemm_a8w8_blockscale_bpreshuffle(A, | ||
| B, | ||
| As, | ||
| Bs, | ||
| dtype=output_dtype) | ||
  
    
      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 | 
|---|---|---|
|  | @@ -11,6 +11,7 @@ | |
| import vllm.envs as envs | ||
| import vllm.model_executor.layers.fused_moe.modular_kernel as mk | ||
| from vllm import _custom_ops as ops | ||
| from vllm._aiter_ops import AITEROpMode | ||
| from vllm.distributed import get_tensor_model_parallel_world_size | ||
| from vllm.logger import init_logger | ||
| from vllm.model_executor.layers.fused_moe import ( | ||
|  | @@ -232,10 +233,10 @@ def __init__(self, quant_config: Fp8Config): | |
|  | ||
| # AITER is only supported on ROCm and only for FP8_FNUZ | ||
| # and at the moment are MI300 series | ||
| self.use_aiter_and_is_supported = (current_platform.is_rocm() | ||
| and envs.VLLM_ROCM_USE_AITER | ||
| and envs.VLLM_ROCM_USE_AITER_LINEAR | ||
| and current_platform.is_fp8_fnuz()) | ||
| self.use_aiter_and_is_supported: int = int( | ||
| current_platform.is_rocm() and envs.VLLM_ROCM_USE_AITER | ||
| and envs.VLLM_ROCM_USE_AITER_LINEAR | ||
| and current_platform.is_fp8_fnuz()) | ||
| 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. what about mi355 ? | ||
|  | ||
| self.block_quant = self.quant_config.weight_block_size is not None | ||
| self.act_q_static = self.quant_config.activation_scheme == "static" | ||
|  | @@ -387,6 +388,17 @@ def process_weights_after_loading(self, layer: Module) -> None: | |
|  | ||
| weight = self._maybe_pad_weight(weight) | ||
|  | ||
| if self.use_aiter_and_is_supported: | ||
| from vllm._aiter_ops import use_swizzle | ||
| layout = (16, 16) | ||
| if use_swizzle(*weight.shape, layout): | ||
| self.use_aiter_and_is_supported = \ | ||
| AITEROpMode.SWIZZLE_AITER.value | ||
| if (self.use_aiter_and_is_supported == \ | ||
| AITEROpMode.SWIZZLE_AITER.value): | ||
| from aiter.ops.shuffle import shuffle_weight | ||
| weight = shuffle_weight(weight, layout=(16, 16)) | ||
|  | ||
| # Torch.compile cannot use Parameter subclasses. | ||
| layer.weight = Parameter(weight, requires_grad=False) | ||
| layer.weight_scale_inv = Parameter(weight_scale_inv, | ||
|  | ||
  
    
      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
    
  
  
    
              
  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.
why we have this parameter if block_size is not used?