Skip to content
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

support ascend 310P #3085

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
22 changes: 22 additions & 0 deletions lmdeploy/pytorch/backends/dlinfer/ascend/op_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
import itertools
import os
import re
from functools import lru_cache
from pathlib import Path
from typing import Dict, Tuple

import torch
import torch_npu

from lmdeploy.pytorch.config import BackendConfig, CacheConfig, ModelConfig
from lmdeploy.utils import get_logger
Expand All @@ -15,6 +17,24 @@
logger = get_logger('lmdeploy')


class SocVersion:
Ascend310P: str = 'Ascend310P'
Ascend910B: str = 'Ascend910B'

@classmethod
@lru_cache(maxsize=1)
def device_name(cls) -> str:
return torch_npu.npu.get_device_name()[:10]

@classmethod
def is_Ascend310P(cls) -> bool:
return cls.device_name() == cls.Ascend310P

@classmethod
def is_Ascend910B(cls) -> bool:
return cls.device_name() == cls.Ascend910B


class AscendKVQuantMeta:
has_set_value: bool = False
quant_meta: Dict = {}
Expand Down Expand Up @@ -183,6 +203,8 @@ def get_total_slots():
if not step_context.is_decoding:
if is_unpaged_prefill:
attention_mask = [mask.half() for mask in attention_mask]
if SocVersion.is_Ascend310P():
attention_mask = [torch.cat([mask.unsqueeze(0) for mask in attention_mask])]
else:
attention_mask = [
torch.cat([mask.half() * cls.half_negative_inf for mask in attention_mask]).unsqueeze(1)
Expand Down