[Bugfix]: Fix glm46 awq marlin moe wna16 compatibility (#30210)
Signed-off-by: baonudesifeizhai <baonudesifeizhai@gmail.com>
This commit is contained in:
@@ -895,6 +895,48 @@ def get_moe_configs(
|
||||
return None
|
||||
|
||||
|
||||
def _ensure_block_size_k_divisible(
|
||||
size_k: int, block_size_k: int, group_size: int
|
||||
) -> int:
|
||||
"""Ensure block_size_k is a divisor of size_k and divisible by group_size.
|
||||
|
||||
This ensures BLOCK_SIZE_K compatibility with MoeWNA16 CUDA kernel which
|
||||
requires size_k % BLOCK_SIZE_K == 0 and BLOCK_SIZE_K % group_size == 0.
|
||||
|
||||
Args:
|
||||
size_k: The size_k dimension that must be divisible by result.
|
||||
block_size_k: Preferred block size (will be adjusted if needed).
|
||||
group_size: The result must be divisible by this.
|
||||
|
||||
Returns:
|
||||
A valid BLOCK_SIZE_K that divides size_k and is divisible by group_size.
|
||||
"""
|
||||
# Fast path: already valid
|
||||
if size_k % block_size_k == 0 and block_size_k % group_size == 0:
|
||||
return block_size_k
|
||||
|
||||
# Find the largest value that:
|
||||
# 1. Divides size_k (size_k % candidate == 0)
|
||||
# 2. Is divisible by group_size (candidate % group_size == 0)
|
||||
# 3. Is <= block_size_k (prefer smaller values close to block_size_k)
|
||||
#
|
||||
# Strategy: Search from min(block_size_k, size_k) down to group_size,
|
||||
# stepping by group_size to ensure divisibility by group_size
|
||||
max_search = min(block_size_k, size_k)
|
||||
start = (max_search // group_size) * group_size
|
||||
for candidate in range(start, group_size - 1, -group_size):
|
||||
if size_k % candidate == 0:
|
||||
return candidate
|
||||
|
||||
# Fallback: if group_size divides size_k, use it
|
||||
# This should always be true with correct group_size configuration
|
||||
if size_k % group_size == 0:
|
||||
return group_size
|
||||
|
||||
# This should not happen with correct group_size, but ensure divisibility
|
||||
return size_k
|
||||
|
||||
|
||||
def get_moe_wna16_block_config(
|
||||
config: dict[str, int],
|
||||
use_moe_wna16_cuda: bool,
|
||||
@@ -960,6 +1002,9 @@ def get_moe_wna16_block_config(
|
||||
# at the same time.
|
||||
block_size_n = 1024
|
||||
|
||||
# Ensure BLOCK_SIZE_K is a divisor of size_k for CUDA kernel compatibility
|
||||
block_size_k = _ensure_block_size_k_divisible(size_k, block_size_k, group_size)
|
||||
|
||||
return {"BLOCK_SIZE_N": block_size_n, "BLOCK_SIZE_K": block_size_k}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user