[RL] Call torch.cuda.empty_cache() for in-place pause mode to avoid OOM (#24854)

Co-authored-by: Byron Hsu <byron@periodiclabs.ai>
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Byron Hsu
2026-05-09 23:36:52 -07:00
committed by GitHub
co-authored by Byron Hsu Cursor
parent 44efc23a9a
commit cfd3fd00d0
2 changed files with 15 additions and 1 deletions
+6 -1
View File
@@ -1378,7 +1378,12 @@ class PauseGenerationReqInput(BaseReq):
@dataclass
class ContinueGenerationReqInput(BaseReq):
pass
# Call torch.cuda.empty_cache() before un-pausing. Returns blocks
# cached by the PyTorch allocator (left over from transient allocs
# during post-weight-update processing) back to the driver before
# inference resumes, with no race against active streams. Set to
# False to skip the empty_cache call.
torch_empty_cache: bool = True
@dataclass
+9
View File
@@ -3646,6 +3646,15 @@ class Scheduler(
self.chunked_req = None
def continue_generation(self, recv_req: ContinueGenerationReqInput):
if recv_req.torch_empty_cache:
before_mb = torch.cuda.memory_reserved() / (1024 * 1024)
torch.cuda.empty_cache()
after_mb = torch.cuda.memory_reserved() / (1024 * 1024)
logger.info(
f"[continue_generation] torch.cuda.empty_cache() called: "
f"reserved {before_mb:.1f} MB -> {after_mb:.1f} MB "
f"(freed {before_mb - after_mb:.1f} MB)"
)
self._engine_paused = False
def load_lora_adapter(