2025-04-15 16:09:36 +08:00
|
|
|
#
|
|
|
|
|
# Copyright (c) 2025 Huawei Technologies Co., Ltd. All Rights Reserved.
|
|
|
|
|
# This file is a part of the vllm-ascend project.
|
|
|
|
|
#
|
|
|
|
|
# This file is mainly Adapted from vllm-project/vllm/vllm/envs.py
|
|
|
|
|
# Copyright 2023 The vLLM team.
|
|
|
|
|
#
|
|
|
|
|
# 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.
|
|
|
|
|
#
|
|
|
|
|
|
2025-04-03 14:52:34 +08:00
|
|
|
import os
|
|
|
|
|
from typing import Any, Callable, Dict
|
|
|
|
|
|
2025-04-15 16:09:36 +08:00
|
|
|
# The begin-* and end* here are used by the documentation generator
|
|
|
|
|
# to extract the used env vars.
|
|
|
|
|
|
|
|
|
|
# begin-env-vars-definition
|
|
|
|
|
|
2025-04-03 14:52:34 +08:00
|
|
|
env_variables: Dict[str, Callable[[], Any]] = {
|
|
|
|
|
# max compile thread num
|
2025-04-12 10:24:53 +08:00
|
|
|
"MAX_JOBS":
|
|
|
|
|
lambda: os.getenv("MAX_JOBS", None),
|
|
|
|
|
"CMAKE_BUILD_TYPE":
|
|
|
|
|
lambda: os.getenv("CMAKE_BUILD_TYPE"),
|
2025-04-03 14:52:34 +08:00
|
|
|
"COMPILE_CUSTOM_KERNELS":
|
2025-04-12 10:24:53 +08:00
|
|
|
lambda: bool(int(os.getenv("COMPILE_CUSTOM_KERNELS", "1"))),
|
2025-05-13 12:52:30 +08:00
|
|
|
"VLLM_ENABLE_MC2":
|
|
|
|
|
lambda: bool(int(os.getenv("VLLM_ENABLE_MC2", '0'))),
|
|
|
|
|
"USING_LCCL_COM":
|
|
|
|
|
lambda: bool(int(os.getenv("USING_LCCL_COM", '0'))),
|
2025-04-12 10:24:53 +08:00
|
|
|
"SOC_VERSION":
|
|
|
|
|
lambda: os.getenv("SOC_VERSION", "ASCEND910B1"),
|
|
|
|
|
# If set, vllm-ascend will print verbose logs during compilation
|
|
|
|
|
"VERBOSE":
|
|
|
|
|
lambda: bool(int(os.getenv('VERBOSE', '0'))),
|
|
|
|
|
"ASCEND_HOME_PATH":
|
|
|
|
|
lambda: os.getenv("ASCEND_HOME_PATH", None),
|
|
|
|
|
"LD_LIBRARY_PATH":
|
|
|
|
|
lambda: os.getenv("LD_LIBRARY_PATH", None),
|
2025-04-15 15:11:35 +08:00
|
|
|
# Used for disaggregated prefilling
|
|
|
|
|
"HCCN_PATH":
|
|
|
|
|
lambda: os.getenv("HCCN_PATH", "/usr/local/Ascend/driver/tools/hccn_tool"),
|
2025-04-17 14:57:52 +08:00
|
|
|
"HCCL_SO_PATH":
|
|
|
|
|
lambda: os.environ.get("HCCL_SO_PATH", None),
|
2025-04-15 15:11:35 +08:00
|
|
|
"PROMPT_DEVICE_ID":
|
|
|
|
|
lambda: os.getenv("PROMPT_DEVICE_ID", None),
|
|
|
|
|
"DECODE_DEVICE_ID":
|
|
|
|
|
lambda: os.getenv("DECODE_DEVICE_ID", None),
|
|
|
|
|
"LLMDATADIST_COMM_PORT":
|
|
|
|
|
lambda: os.getenv("LLMDATADIST_COMM_PORT", "26000"),
|
|
|
|
|
"LLMDATADIST_SYNC_CACHE_WAIT_TIME":
|
2025-04-17 14:57:52 +08:00
|
|
|
lambda: os.getenv("LLMDATADIST_SYNC_CACHE_WAIT_TIME", "5000"),
|
Add sleep mode feature for Ascend NPU (#513)
### What this PR does / why we need it?
This PR adds sleep mode feature for vllm-ascend, when sleeps, we do
mainly two things:
- offload model weights
- discard kv cache
RLHF tools(such as https://github.com/volcengine/verl and
https://github.com/OpenRLHF/OpenRLHF) have a strong need of sleep mode
to accelerate the training process.
This PR may solve #375 and #320 .
### Does this PR introduce _any_ user-facing change?
No existing user interfaces changed.
Users will have two new methods(`sleep()` and `wake_up()`) to use.
### How was this patch tested?
This PR is tested with Qwen/Qwen2.5-0.5B-Instruct.
At first, we have free NPU memory M1.
After `llm = LLM("Qwen/Qwen2.5-0.5B-Instruct", enable_sleep_mode=True)`
executed, we have free NPU memory M2. M2 < M1.
Then we call `llm.sleep(level=1)`, we have free NPU memory M3.
We have M3 > M2, M3 is very close to M1.
Plus, we have the same output tokens before sleep and after wake up,
with the config of `SamplingParams(temperature=0, max_tokens=10)` and
with the same input tokens of course.
This PR is utilizing the CMake procedure of #371 , thanks a lot.
Signed-off-by: Shuqiao Li <celestialli@outlook.com>
2025-04-18 13:11:39 +08:00
|
|
|
"CXX_COMPILER":
|
|
|
|
|
lambda: os.getenv("CXX_COMPILER", None),
|
|
|
|
|
"C_COMPILER":
|
2025-04-28 14:19:06 +08:00
|
|
|
lambda: os.getenv("C_COMPILER", None),
|
|
|
|
|
"VLLM_VERSION":
|
|
|
|
|
lambda: os.getenv("VLLM_VERSION", None),
|
2025-04-03 14:52:34 +08:00
|
|
|
}
|
|
|
|
|
|
2025-04-15 16:09:36 +08:00
|
|
|
# end-env-vars-definition
|
|
|
|
|
|
2025-04-03 14:52:34 +08:00
|
|
|
|
|
|
|
|
def __getattr__(name: str):
|
|
|
|
|
# lazy evaluation of environment variables
|
|
|
|
|
if name in env_variables:
|
|
|
|
|
return env_variables[name]()
|
|
|
|
|
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __dir__():
|
|
|
|
|
return list(env_variables.keys())
|