执行摘要
删除 vLLM rollout 中未使用的 get_device_uuid
get_device_uuid 写入的 self.device_uuid 在 ServerAdapter.__init__ 后未被任何代码读取,属于死代码。PR body 简洁说明 'Delete the useless code',目的是清理未使用的函数和属性。
该 PR 简单直接,无需精读。可作为代码清理的范例参考。
只有一条来自 wuxibin89 的 Approved 审核,无其他讨论。
get_device_uuid 写入的 self.device_uuid 在 ServerAdapter.__init__ 后未被任何代码读取,属于死代码。PR body 简洁说明 'Delete the useless code',目的是清理未使用的函数和属性。
该 PR 简单直接,无需精读。可作为代码清理的范例参考。
只有一条来自 wuxibin89 的 Approved 审核,无其他讨论。
get_device_uuid:在 verl/workers/rollout/vllm_rollout/utils.py 中移除了整个 get_device_uuid 函数(约 16 行)。同时删除了该函数依赖的 from verl.plugin.platform import get_platform 导入。verl/workers/rollout/vllm_rollout/vllm_rollout.py 中移除了 from verl.utils.device import get_device_id 和 from verl.workers.rollout.vllm_rollout.utils import get_device_uuid 导入,并删除了 __init__ 中的 self.device_uuid = get_device_uuid(get_device_id()) 语句。| 文件 | 模块 | 状态 | 重要度 |
|---|---|---|---|
verl/workers/rollout/vllm_rollout/utils.py |
Rollout | modified | 6.06 |
verl/workers/rollout/vllm_rollout/vllm_rollout.py |
Rollout | modified | 4.43 |
verl/workers/rollout/vllm_rollout/utils.py
dependency-wiring
删除了一整个未使用的函数 `get_device_uuid` 及其相关导入,是本次 PR 的核心变更。
def set_death_signal():
"""Kill the current process when the parent process exits."""
if platform.system() != "Linux":
return
libc = ctypes.CDLL("libc.so.6")
libc.prctl(1, signal.SIGKILL)
if os.getppid() == 1:
os.kill(os.getpid(), signal.SIGKILL)
# 以下 get_device_uuid 函数已被删除,因为其调用者已被清理。
# def get_device_uuid(device_id: int) -> str:
# from vllm.platforms import current_platform
# if is_npu_available:
# if os.getenv("ASCEND_RT_VISIBLE_DEVICES") is not None:
# npu_visible_devices = os.environ["ASCEND_RT_VISIBLE_DEVICES"].split(",")
# assert device_id < len(npu_visible_devices)
# return "NPU-" + npu_visible_devices[device_id]
# else:
# return f"NPU-{device_id}"
# else:
# try:
# return current_platform.get_device_uuid(device_id)
# except Exception:
# return get_platform().get_device_uuid(device_id=device_id)
def get_vllm_max_lora_rank(lora_rank: int):
"""
For vLLM, automatically adjusts the `max_lora_rank` to the nearest allowed value.
"""
assert lora_rank > 0, f"lora_rank must be greater than 0, get {lora_rank}"
...
verl/workers/rollout/vllm_rollout/vllm_rollout.py
dependency-wiring
移除了对已删除函数 `get_device_uuid` 的导入和调用,以及 `get_device_id` 的导入,完成了死代码清理的收尾。
from verl.utils.device import is_support_ipc # 移除了 get_device_id 的导入
from verl.workers.config import HFModelConfig, RolloutConfig
from verl.workers.rollout.base import BaseRollout
from verl.workers.rollout.vllm_rollout.bucketed_weight_transfer import BucketedWeightSender
# 已删除 : from verl.workers.rollout.vllm_rollout.utils import get_device_uuid
# 在 __init__ 方法中,以下行已被删除:
# self.device_uuid = get_device_uuid(get_device_id())
# CUDA IPC handle 的构造现在直接使用 replica_rank 和本地 rank,不再依赖 device_uuid。
# 注释保留了原来解释为何不使用 GPU UUID 的理由:
# CheckpointEngineWorker and vLLM worker may see different GPU UUIDs
# when CUDA_VISIBLE_DEVICES differs between processes (common on ROCm/AMD).
当前评论区没有形成足够清晰的争议点或结论,后续有更多讨论时会体现在这里。
风险极低。变更仅移除未被引用的代码和导入,不会影响运行时行为。但若未来有外部代码(如插件或扩展)依赖 get_device_uuid 的导出,可能会遇到导入错误,不过该函数在模块私有范围内,且未被 __all__ 导出。
当前没有检测到明确关联的 Issue 链接,后续同步到相关引用后会出现在这里。
参与讨论