Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 7 additions & 14 deletions vllm_fl/dispatch/backends/vendor/metax/impl/activation.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,12 @@
# SPDX-License-Identifier: Apache-2.0
# 2026 - Modified by MetaX Integrated Circuits (Shanghai) Co., Ltd. All Rights Reserved.
import torch
from vllm.model_executor.layers.activation import (
SiluAndMul,
GeluAndMul,
)
import torch.nn.functional as F


def silu_and_mul_maca(obj, x: torch.Tensor) -> torch.Tensor:
"""
SiLU activation followed by element-wise multiplication using CUDA.

Uses vLLM's optimized CUDA kernel when available.
SiLU activation followed by element-wise multiplication.

Args:
obj: The calling obj (for interface consistency)
Expand All @@ -34,15 +29,13 @@ def silu_and_mul_maca(obj, x: torch.Tensor) -> torch.Tensor:
Returns:
Output tensor of shape [..., d]
"""
act_fn = SiluAndMul()
return act_fn.forward_cuda(x)
d = x.shape[-1] // 2
return F.silu(x[..., :d]) * x[..., d:]


def gelu_and_mul_maca(obj, x: torch.Tensor) -> torch.Tensor:
"""
GELU activation followed by element-wise multiplication using CUDA.

Uses vLLM's optimized CUDA kernel when available.
GELU activation followed by element-wise multiplication.

Args:
obj: The calling obj (for interface consistency)
Expand All @@ -51,5 +44,5 @@ def gelu_and_mul_maca(obj, x: torch.Tensor) -> torch.Tensor:
Returns:
Output tensor of shape [..., d]
"""
act_fn = GeluAndMul()
return act_fn.forward_cuda(x)
d = x.shape[-1] // 2
return F.gelu(x[..., :d], approximate="none") * x[..., d:]
Loading