Fix memory leak in RL training loop causing OOM at ~220GB#483
Open
Mr-Neutr0n wants to merge 1 commit intomicrosoft:mainfrom
Open
Fix memory leak in RL training loop causing OOM at ~220GB#483Mr-Neutr0n wants to merge 1 commit intomicrosoft:mainfrom
Mr-Neutr0n wants to merge 1 commit intomicrosoft:mainfrom
Conversation
Multiple memory leak sources were identified and fixed: 1. InMemoryLightningStore: Added cleanup_finished_rollouts() method that removes completed rollout data (rollouts, attempts, spans, sequence IDs) and their associated tracking metadata (_completion_events, _start_time_by_rollout, _span_bytes_by_rollout, _running_rollout_ids, _evicted_rollout_span_sets) from all in-memory data structures. 2. AgentModeDaemon.clear_data_and_server(): Now invokes store cleanup after extracting training data, preventing rollout data from accumulating across training steps. 3. AgentLightningTrainer._train_step(): Added explicit deletion of gen_batch after training data extraction, and gc.collect() + torch.cuda.empty_cache() at the end of each training step to release batch tensors. 4. LightningSpanExporter: Added MAX_BUFFER_SIZE (10000) cap on the span buffer to prevent unbounded growth when spans fail to flush due to missing headers or unavailable store. Fixes microsoft#438
Author
|
Friendly bump! Let me know if there's anything I should update or improve to help move this forward. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #438
During RL training, system memory usage grows continuously until ~220GB and crashes. This PR addresses multiple memory leak sources across the store, daemon, trainer, and span exporter:
InMemoryLightningStore: Added
cleanup_finished_rollouts()method that removes completed rollout data (rollouts, attempts, spans, sequence IDs) and their associated tracking metadata (_completion_events,_start_time_by_rollout,_span_bytes_by_rollout,_running_rollout_ids,_evicted_rollout_span_sets) from all in-memory data structures after training data has been extracted.AgentModeDaemon.clear_data_and_server(): Now invokes store cleanup after clearing internal rollout tracking dicts, preventing rollout data from accumulating in the in-memory store across training steps.
AgentLightningTrainer._train_step(): Added explicit
del gen_batchafter training data extraction, andgc.collect()+torch.cuda.empty_cache()at the end of each training step to release batch tensors and GPU cache.LightningSpanExporter: Added
MAX_BUFFER_SIZE(10000) cap on the span buffer to prevent unbounded growth when spans fail to flush due to missing headers or unavailable store.Test plan
htopor/proc/meminfo- memory should stabilize rather than growing linearly