|
| 1 | +""" |
| 2 | +# Copyright (c) 2025 MetaX-tech Authors. All Rights Reserved. |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | +""" |
| 16 | + |
| 17 | +""" |
| 18 | +maca platform file |
| 19 | +""" |
| 20 | + |
| 21 | +import paddle |
| 22 | +from .base import Platform, _Backend |
| 23 | +from paddlenlp.utils.log import logger |
| 24 | + |
| 25 | + |
| 26 | +class MACAPlatform(Platform): |
| 27 | + """ |
| 28 | + maca platform class |
| 29 | + """ |
| 30 | + device_name = "gpu" |
| 31 | + |
| 32 | + @classmethod |
| 33 | + def available(self): |
| 34 | + """ |
| 35 | + Check whether MACA is available. |
| 36 | + """ |
| 37 | + try: |
| 38 | + assert len(paddle.static.cuda_places()) > 0 |
| 39 | + return True |
| 40 | + except Exception as e: |
| 41 | + logger.warning( |
| 42 | + "You are using GPU version PaddlePaddle, but there is no GPU " |
| 43 | + "detected on your machine. Maybe CUDA devices is not set properly." |
| 44 | + f"\n Original Error is {e}" |
| 45 | + ) |
| 46 | + return False |
| 47 | + |
| 48 | + @classmethod |
| 49 | + def get_attention_backend_cls( |
| 50 | + cls, |
| 51 | + selected_backend |
| 52 | + ): |
| 53 | + """ |
| 54 | + get_attention_backend_cls |
| 55 | + """ |
| 56 | + if selected_backend == _Backend.NATIVE_ATTN: |
| 57 | + logger.info("Using NATIVE ATTN backend.") |
| 58 | + return ("fastdeploy.model_executor.layers.attention.PaddleNativeAttnBackend") |
| 59 | + else: |
| 60 | + logger.warning( |
| 61 | + "Other backends are not supported for now." |
| 62 | + ) |
0 commit comments