[Kernel] GGUF MoE kernel (#14613)
Signed-off-by: SzymonOzog <szymon.ozog@aleph-alpha.com>
This commit is contained in:
@@ -448,6 +448,23 @@ if hasattr(torch.ops._C, "ggml_dequantize"):
|
||||
batch = X.size(0)
|
||||
return torch.empty((batch, row), dtype=X.dtype, device=W.device)
|
||||
|
||||
@register_fake("_C::ggml_moe_a8")
|
||||
def _ggml_moe_a8_fake(
|
||||
X: torch.Tensor,
|
||||
W: torch.Tensor,
|
||||
sorted_token_ids: torch.Tensor,
|
||||
expert_ids: torch.Tensor,
|
||||
num_tokens_post_padded: torch.Tensor,
|
||||
quant_type: int,
|
||||
row: torch.SymInt,
|
||||
top_k: torch.SymInt,
|
||||
tokens: torch.SymInt,
|
||||
) -> torch.Tensor:
|
||||
tokens = X.size(0)
|
||||
return torch.empty((tokens * top_k, row),
|
||||
dtype=torch.float16,
|
||||
device=W.device)
|
||||
|
||||
|
||||
# cutlass
|
||||
def cutlass_scaled_fp4_mm(a: torch.Tensor, b: torch.Tensor,
|
||||
@@ -1034,6 +1051,26 @@ def ggml_mul_mat_a8(
|
||||
return torch.ops._C.ggml_mul_mat_a8(W, X, quant_type, row)
|
||||
|
||||
|
||||
def ggml_moe_a8(
|
||||
X: torch.Tensor,
|
||||
W: torch.Tensor,
|
||||
sorted_token_ids: torch.Tensor,
|
||||
expert_ids: torch.Tensor,
|
||||
num_tokens_post_padded: torch.Tensor,
|
||||
quant_type: int,
|
||||
row: int,
|
||||
top_k: int,
|
||||
tokens: int,
|
||||
) -> torch.Tensor:
|
||||
return torch.ops._C.ggml_moe_a8(X, W, sorted_token_ids, expert_ids,
|
||||
num_tokens_post_padded, quant_type, row,
|
||||
top_k, tokens)
|
||||
|
||||
|
||||
def ggml_moe_get_block_size(quant_type: int) -> int:
|
||||
return torch.ops._C.ggml_moe_get_block_size(quant_type)
|
||||
|
||||
|
||||
# mamba
|
||||
def causal_conv1d_fwd(x: torch.Tensor, weight: torch.Tensor,
|
||||
bias_: Optional[torch.Tensor],
|
||||
|
||||
Reference in New Issue
Block a user