[refact] unified soc_version code (#4359)
### What this PR does / why we need it?
Currently, there are two paths to judge the chip type in code,
`get_ascend_soc_version` use `get_soc_version` api in torch_npu, and
`is_310p` `use _build_info.__soc_version__`, which generate when
install. We need to unify the two paths.
We need to unify these codes based on the following points:
1. We need to ensure consistency in chip type judgment between compiling
and running states;
2. In compiling state, we need chip type to complete op's compilation,
but in running state, we only need device
type(910B/910_93/310P/910_95/etc) to make code branch judgement;
3. In compiling state, torch_npu may not have been installed yet, so we
can't use torch_npu's api.
Based on the above points, we have made the following changes:
1. When user set env `SOC_VERSION`, use it; when not set, query
soc_version by `npu-smi`;
2. generate device_type based on soc_version when compiling, and write
`__device_type__` instead of `__soc_version__` in `_build_info.py`;
3. In running state, use `__device_type__` to judge code branch.
### Does this PR introduce _any_ user-facing change?
When not set env `SOC_VERSION`, it will not be `ASCEND910B1` by default,
we will query soc_version by `npu-smi`. And env `SOC_VERSION` must be in
the list `soc_to_device` in `setup.py`.
- vLLM version: v0.11.0
- vLLM main:
2918c1b49c
Signed-off-by: zzzzwwjj <1183291235@qq.com>
This commit is contained in:
@@ -48,7 +48,6 @@ ACL_FORMAT_FRACTAL_ND = 2
|
||||
ACL_FORMAT_FRACTAL_NZ = 29
|
||||
|
||||
_CUSTOM_OP_ENABLED = None
|
||||
_IS_310P = None
|
||||
_SLEEP_MODE_ENABLED = None
|
||||
_CURRENT_STREAM = None
|
||||
_PREFETCH_STREAM = None
|
||||
@@ -121,14 +120,6 @@ def _unregister_print_streams_on_exit():
|
||||
atexit.register(_unregister_print_streams_on_exit)
|
||||
|
||||
|
||||
def is_310p():
|
||||
global _IS_310P
|
||||
if _IS_310P is None:
|
||||
from vllm_ascend import _build_info # type: ignore
|
||||
_IS_310P = _build_info.__soc_version__.lower().startswith("ascend310p")
|
||||
return _IS_310P
|
||||
|
||||
|
||||
def is_enable_nz():
|
||||
return envs_ascend.VLLM_ASCEND_ENABLE_NZ
|
||||
|
||||
@@ -703,32 +694,47 @@ def register_ascend_customop(vllm_config: Optional[VllmConfig] = None):
|
||||
_ASCEND_CUSTOMOP_IS_REIGISTERED = True
|
||||
|
||||
|
||||
# TODO(zzzzwwjj): Currently there is no clear SOC_VERSION policy for A2 and A3 in CANN.
|
||||
# So we get the version dynamically. In the future, we should get the version info from _build_info like 310p does.
|
||||
class AscendSocVersion(Enum):
|
||||
A2 = 0
|
||||
A3 = 1
|
||||
UNDEFINED = 2
|
||||
class AscendDeviceType(Enum):
|
||||
_910B = 0 # A2
|
||||
_910_93 = 1 # A3
|
||||
_310P = 2
|
||||
_910_95 = 3 # A5
|
||||
|
||||
|
||||
_ascend_soc_version = None
|
||||
_ascend_device_type = None
|
||||
|
||||
|
||||
def init_ascend_soc_version():
|
||||
def _init_ascend_device_type():
|
||||
global _ascend_device_type
|
||||
from vllm_ascend import _build_info # type: ignore
|
||||
_ascend_device_type = AscendDeviceType[_build_info.__device_type__]
|
||||
|
||||
|
||||
def check_ascend_device_type():
|
||||
global _ascend_device_type
|
||||
if _ascend_device_type is None:
|
||||
_init_ascend_device_type()
|
||||
|
||||
soc_version = torch_npu.npu.get_soc_version()
|
||||
global _ascend_soc_version
|
||||
if 220 <= soc_version <= 225:
|
||||
_ascend_soc_version = AscendSocVersion.A2
|
||||
cur_device_type = AscendDeviceType._910B
|
||||
elif 250 <= soc_version <= 255:
|
||||
_ascend_soc_version = AscendSocVersion.A3
|
||||
cur_device_type = AscendDeviceType._910_93
|
||||
elif 200 <= soc_version <= 205:
|
||||
cur_device_type = AscendDeviceType._310P
|
||||
elif soc_version == 260:
|
||||
cur_device_type = AscendDeviceType._910_95
|
||||
else:
|
||||
_ascend_soc_version = AscendSocVersion.UNDEFINED
|
||||
raise RuntimeError(f"Can not support soc_version: {soc_version}.")
|
||||
|
||||
assert _ascend_device_type == cur_device_type, f"Current device type: {cur_device_type} does not match the installed version's device type: {_ascend_device_type}, please check your installation package."
|
||||
|
||||
|
||||
def get_ascend_soc_version():
|
||||
global _ascend_soc_version
|
||||
assert _ascend_soc_version is not None
|
||||
return _ascend_soc_version
|
||||
def get_ascend_device_type():
|
||||
global _ascend_device_type
|
||||
if _ascend_device_type is None:
|
||||
_init_ascend_device_type()
|
||||
return _ascend_device_type
|
||||
|
||||
|
||||
def lmhead_tp_enable() -> bool:
|
||||
|
||||
Reference in New Issue
Block a user