Skip to content
Merged
Show file tree
Hide file tree
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: 13 additions & 9 deletions fastdeploy/cache_manager/cache_transfer_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,24 +540,28 @@ def _init_gpu_cache(self):
logger.info("GPU KV cache is initialized")

def _clear_gpu_cache(self):

if self.create_cache_tensor:

This comment was marked as outdated.

logger.debug("Waiting for gpu runner to unlink cuda ipc")
while self.cache_ready_signal.value[self.rank] != 0:
time.sleep(0.1)
logger.debug("Stop waiting! gpu runner has unlinked cuda ipc")
self.gpu_cache_kvs.clear()
self.gpu_cache_k_tensors.clear()
self.gpu_cache_v_tensors.clear()
if hasattr(self, "gpu_cache_scales_k_tensors"):
self.gpu_cache_scales_k_tensors.clear()
if hasattr(self, "gpu_cache_scales_v_tensors"):
self.gpu_cache_scales_v_tensors.clear()
paddle.set_flags({"FLAGS_selected_gpus": f"{self.device}"})
paddle.device.cuda.empty_cache()
else:
for name, tensor in self.gpu_cache_kvs.items():
unset_data_ipc(tensor, name, True, False)
logger.debug("Successfully unlinked gpu caches cuda ipc")

self.gpu_cache_kvs.clear()
self.gpu_cache_k_tensors.clear()
self.gpu_cache_v_tensors.clear()
if hasattr(self, "gpu_cache_scales_k_tensors"):
self.gpu_cache_scales_k_tensors.clear()
if hasattr(self, "gpu_cache_scales_v_tensors"):
self.gpu_cache_scales_v_tensors.clear()
paddle.set_flags({"FLAGS_selected_gpus": f"{self.device}"})
paddle.device.cuda.empty_cache()
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ 疑问create_cache_tensor=True 时:

  • _clear_gpu_cache(transfer manager 侧)等待 cache_ready_signal.value[rank] == 0,日志为 "Waiting for gpu runner to unlink"
  • gpu_model_runner.clear_cache(GPU runner 侧)同样等待 cache_ready_signal.value[local_rank] == 0,日志为 "Waiting for cache transfer manager to unlink"

两侧均声称在等待对方,但此分支下均未将 signal 置 0。请确认:

  1. create_cache_tensor=True 时 signal 的初始值是否始终为 0(即等待为空操作)?
  2. 若 signal 在 IPC 建立阶段被置为非零,谁负责将其清零?是否存在两侧互相等待的死锁风险?


if not self.create_cache_tensor:
self.cache_ready_signal.value[self.rank] = 0

while np.sum(self.cache_ready_signal.value) != 0:
Expand Down
15 changes: 11 additions & 4 deletions fastdeploy/worker/gpu_model_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -3010,10 +3010,17 @@ def clear_cache(self, profile=False):
)
local_rank = self.local_rank % self.parallel_config.tensor_parallel_size

if not create_cache_tensor:
for name, tensor in self.cache_kvs_map.items():
unset_data_ipc(tensor, name, True, False)
self.cache_ready_signal.value[local_rank] = 0
if not profile:

This comment was marked as outdated.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 建议 gpu_model_runner.py 属于 GPU 通用路径,architecture.md §A6 指出此类变更通常需同步到其他硬件 ModelRunner。

clear_cache 中原有的 if not create_cache_tensor: 条件反转 Bug,是否在 xpu_model_runner.pydcu_model_runner.pygcu_model_runner.pyhpu_model_runner.pyiluvatar_model_runner.pymetax_model_runner.py 中也存在相同问题?若存在,建议一并修复,避免其他硬件 CI 在 RL 场景下出现类似的 CPU cache 清理异常。

if create_cache_tensor:
if self.fd_config.cache_config.num_cpu_blocks > 0:
logger.info("Waiting for cache transfer manager to unlink cuda ipc")
while self.cache_ready_signal.value[local_rank] != 0:
time.sleep(0.1)
logger.info("Stop waiting! cache transfer manager has unlinked cuda ipc")
else:
for name, tensor in self.cache_kvs_map.items():
unset_data_ipc(tensor, name, True, False)
self.cache_ready_signal.value[local_rank] = 0

self.cache_kvs_map.clear()
self.share_inputs.pop("caches", None)
Expand Down
Loading