-
Notifications
You must be signed in to change notification settings - Fork 749
[BugFix] [RL] Fix cpu cache for rl #7764
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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: | ||
| 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() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❓ 疑问 当
两侧均声称在等待对方,但此分支下均未将 signal 置 0。请确认:
|
||
|
|
||
| if not self.create_cache_tensor: | ||
| self.cache_ready_signal.value[self.rank] = 0 | ||
|
|
||
| while np.sum(self.cache_ready_signal.value) != 0: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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.
Sorry, something went wrong. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 建议
|
||
| 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) | ||
|
|
||
This comment was marked as outdated.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.