Skip to content

Add maca platform #2648

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
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions fastdeploy/platforms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from .xpu import XPUPlatform
from .npu import NPUPlatform
from .dcu import DCUPlatform
from .maca import MACAPlatform
from .base import _Backend

_current_platform = None
Expand All @@ -34,6 +35,8 @@ def __getattr__(name: str):
if _current_platform is None:
if paddle.is_compiled_with_cuda():
_current_platform = CUDAPlatform()
elif paddle.is_compiled_with_custom_device("metax_gpu"):
_current_platform = MACAPlatform()
elif paddle.is_compiled_with_xpu():
_current_platform = XPUPlatform()
elif paddle.is_compiled_with_custom_device("npu"):
Expand Down
6 changes: 6 additions & 0 deletions fastdeploy/platforms/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ def is_cuda(self) -> bool:
whether platform is cuda
"""
return paddle.is_compiled_with_cuda()

def is_maca(self) -> bool:
"""
whether platform is maca
"""
return paddle.is_compiled_with_custom_device("metax_gpu")

def is_npu(self) -> bool:
"""
Expand Down
62 changes: 62 additions & 0 deletions fastdeploy/platforms/maca.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
"""
# Copyright (c) 2025 MetaX-tech Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""

"""
maca platform file
"""

import paddle
from .base import Platform, _Backend
from paddlenlp.utils.log import logger


class MACAPlatform(Platform):
"""
maca platform class
"""
device_name = "gpu"

@classmethod
def available(self):
"""
Check whether MACA is available.
"""
try:
assert len(paddle.static.cuda_places()) > 0
return True
except Exception as e:
logger.warning(
"You are using GPU version PaddlePaddle, but there is no GPU "
"detected on your machine. Maybe CUDA devices is not set properly."
f"\n Original Error is {e}"
)
return False

@classmethod
def get_attention_backend_cls(
cls,
selected_backend
):
"""
get_attention_backend_cls
"""
if selected_backend == _Backend.NATIVE_ATTN:
logger.info("Using NATIVE ATTN backend.")
return ("fastdeploy.model_executor.layers.attention.PaddleNativeAttnBackend")
else:
logger.warning(
"Other backends are not supported for now."
)
Loading