diff --git a/fastdeploy/platforms/__init__.py b/fastdeploy/platforms/__init__.py index 94282a6eca..7047f94ded 100644 --- a/fastdeploy/platforms/__init__.py +++ b/fastdeploy/platforms/__init__.py @@ -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 @@ -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"): diff --git a/fastdeploy/platforms/base.py b/fastdeploy/platforms/base.py index aa7a624cf8..089f67371e 100644 --- a/fastdeploy/platforms/base.py +++ b/fastdeploy/platforms/base.py @@ -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: """ diff --git a/fastdeploy/platforms/maca.py b/fastdeploy/platforms/maca.py new file mode 100644 index 0000000000..9b04313273 --- /dev/null +++ b/fastdeploy/platforms/maca.py @@ -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." + )