Repository navigation
[fsdp] fix: set _set_allocator_settings to True to avoid fsdp2 oom - #3020
Conversation
Co-authored-by: Lu Hongyu <luhongyu.4869@bytedance.com>"
There was a problem hiding this comment.
Code Review
This pull request addresses a probabilistic out-of-memory (OOM) error with FSDP2 by dynamically toggling the expandable_segments setting in PyTorch's CUDA memory allocator. The changes correctly disable this setting for sglang and vllm during rollout and re-enable it for FSDP2 training.
My review focuses on the use of the private PyTorch function _set_allocator_settings. While this seems to be the only way to achieve the desired dynamic behavior, it introduces a maintainability risk as private APIs can change without notice. I've suggested wrapping these calls in try-except blocks to make the code more robust against future PyTorch updates and improve the comments to clarify why this approach is taken.
|
@chenhaiq could you add @narutolhy as a co-author? He contributed the OOM scripts. |
sure. |
I guess we can skip CI. How can we add @narutolhy as a co-author? |
I have updated commit message with all co-authors. Please merge it. |
…erl-project#3020) ### What does this PR do? Enable expandable_segments to avoid the increasing memory fragmentation caused by temporary variables during the training process of fsdp2, which may trigger probabilistic out-of-memory (OOM) errors. Since both sglang and vllm can not work with expandable_segments:True, it has to be turn off during rollout. ### Test Without this fix, memory reserved could be very high after compute_log_prob or update_actor. ``` (WorkerDict pid=339320) [2025-08-11 17:43:01] dp actor After compute_log_prob, memory allocated (GB): 5.53, memory reserved (GB): 73.59, device memory used/total (GB): 77.47/79.15 ``` With this fix, it stays low during training. ``` (WorkerDict pid=396879) [2025-08-12 07:39:42] dp actor After compute_log_prob, memory allocated (GB): 4.95, memory reserved (GB): 14.20, device memory used/total (GB): 17.72/79.15 ``` --------- Co-authored-by: narutolhy <luhongyu.4869@bytedance.com>" Co-authored-by: Chi Zhang <zhangchi.usc1992@bytedance.com>
…erl-project#3020) ### What does this PR do? Enable expandable_segments to avoid the increasing memory fragmentation caused by temporary variables during the training process of fsdp2, which may trigger probabilistic out-of-memory (OOM) errors. Since both sglang and vllm can not work with expandable_segments:True, it has to be turn off during rollout. ### Test Without this fix, memory reserved could be very high after compute_log_prob or update_actor. ``` (WorkerDict pid=339320) [2025-08-11 17:43:01] dp actor After compute_log_prob, memory allocated (GB): 5.53, memory reserved (GB): 73.59, device memory used/total (GB): 77.47/79.15 ``` With this fix, it stays low during training. ``` (WorkerDict pid=396879) [2025-08-12 07:39:42] dp actor After compute_log_prob, memory allocated (GB): 4.95, memory reserved (GB): 14.20, device memory used/total (GB): 17.72/79.15 ``` --------- Co-authored-by: narutolhy <luhongyu.4869@bytedance.com>" Co-authored-by: Chi Zhang <zhangchi.usc1992@bytedance.com>
…erl-project#3020) ### What does this PR do? Enable expandable_segments to avoid the increasing memory fragmentation caused by temporary variables during the training process of fsdp2, which may trigger probabilistic out-of-memory (OOM) errors. Since both sglang and vllm can not work with expandable_segments:True, it has to be turn off during rollout. ### Test Without this fix, memory reserved could be very high after compute_log_prob or update_actor. ``` (WorkerDict pid=339320) [2025-08-11 17:43:01] dp actor After compute_log_prob, memory allocated (GB): 5.53, memory reserved (GB): 73.59, device memory used/total (GB): 77.47/79.15 ``` With this fix, it stays low during training. ``` (WorkerDict pid=396879) [2025-08-12 07:39:42] dp actor After compute_log_prob, memory allocated (GB): 4.95, memory reserved (GB): 14.20, device memory used/total (GB): 17.72/79.15 ``` --------- Co-authored-by: narutolhy <luhongyu.4869@bytedance.com>" Co-authored-by: Chi Zhang <zhangchi.usc1992@bytedance.com>
|
Wonder why SGLang can't use expandable segments? |
Torch memory savor can not use it. So we turn on in several stages. |
…erl-project#3020) ### What does this PR do? Enable expandable_segments to avoid the increasing memory fragmentation caused by temporary variables during the training process of fsdp2, which may trigger probabilistic out-of-memory (OOM) errors. Since both sglang and vllm can not work with expandable_segments:True, it has to be turn off during rollout. ### Test Without this fix, memory reserved could be very high after compute_log_prob or update_actor. ``` (WorkerDict pid=339320) [2025-08-11 17:43:01] dp actor After compute_log_prob, memory allocated (GB): 5.53, memory reserved (GB): 73.59, device memory used/total (GB): 77.47/79.15 ``` With this fix, it stays low during training. ``` (WorkerDict pid=396879) [2025-08-12 07:39:42] dp actor After compute_log_prob, memory allocated (GB): 4.95, memory reserved (GB): 14.20, device memory used/total (GB): 17.72/79.15 ``` --------- Co-authored-by: narutolhy <luhongyu.4869@bytedance.com>" Co-authored-by: Chi Zhang <zhangchi.usc1992@bytedance.com>
…erl-project#3020) ### What does this PR do? Enable expandable_segments to avoid the increasing memory fragmentation caused by temporary variables during the training process of fsdp2, which may trigger probabilistic out-of-memory (OOM) errors. Since both sglang and vllm can not work with expandable_segments:True, it has to be turn off during rollout. ### Test Without this fix, memory reserved could be very high after compute_log_prob or update_actor. ``` (WorkerDict pid=339320) [2025-08-11 17:43:01] dp actor After compute_log_prob, memory allocated (GB): 5.53, memory reserved (GB): 73.59, device memory used/total (GB): 77.47/79.15 ``` With this fix, it stays low during training. ``` (WorkerDict pid=396879) [2025-08-12 07:39:42] dp actor After compute_log_prob, memory allocated (GB): 4.95, memory reserved (GB): 14.20, device memory used/total (GB): 17.72/79.15 ``` --------- Co-authored-by: narutolhy <luhongyu.4869@bytedance.com>" Co-authored-by: Chi Zhang <zhangchi.usc1992@bytedance.com>
…erl-project#3020) ### What does this PR do? Enable expandable_segments to avoid the increasing memory fragmentation caused by temporary variables during the training process of fsdp2, which may trigger probabilistic out-of-memory (OOM) errors. Since both sglang and vllm can not work with expandable_segments:True, it has to be turn off during rollout. ### Test Without this fix, memory reserved could be very high after compute_log_prob or update_actor. ``` (WorkerDict pid=339320) [2025-08-11 17:43:01] dp actor After compute_log_prob, memory allocated (GB): 5.53, memory reserved (GB): 73.59, device memory used/total (GB): 77.47/79.15 ``` With this fix, it stays low during training. ``` (WorkerDict pid=396879) [2025-08-12 07:39:42] dp actor After compute_log_prob, memory allocated (GB): 4.95, memory reserved (GB): 14.20, device memory used/total (GB): 17.72/79.15 ``` --------- Co-authored-by: narutolhy <luhongyu.4869@bytedance.com>" Co-authored-by: Chi Zhang <zhangchi.usc1992@bytedance.com>
…erl-project#3020) ### What does this PR do? Enable expandable_segments to avoid the increasing memory fragmentation caused by temporary variables during the training process of fsdp2, which may trigger probabilistic out-of-memory (OOM) errors. Since both sglang and vllm can not work with expandable_segments:True, it has to be turn off during rollout. ### Test Without this fix, memory reserved could be very high after compute_log_prob or update_actor. ``` (WorkerDict pid=339320) [2025-08-11 17:43:01] dp actor After compute_log_prob, memory allocated (GB): 5.53, memory reserved (GB): 73.59, device memory used/total (GB): 77.47/79.15 ``` With this fix, it stays low during training. ``` (WorkerDict pid=396879) [2025-08-12 07:39:42] dp actor After compute_log_prob, memory allocated (GB): 4.95, memory reserved (GB): 14.20, device memory used/total (GB): 17.72/79.15 ``` --------- Co-authored-by: narutolhy <luhongyu.4869@bytedance.com>" Co-authored-by: Chi Zhang <zhangchi.usc1992@bytedance.com>
…erl-project#3020) ### What does this PR do? Enable expandable_segments to avoid the increasing memory fragmentation caused by temporary variables during the training process of fsdp2, which may trigger probabilistic out-of-memory (OOM) errors. Since both sglang and vllm can not work with expandable_segments:True, it has to be turn off during rollout. ### Test Without this fix, memory reserved could be very high after compute_log_prob or update_actor. ``` (WorkerDict pid=339320) [2025-08-11 17:43:01] dp actor After compute_log_prob, memory allocated (GB): 5.53, memory reserved (GB): 73.59, device memory used/total (GB): 77.47/79.15 ``` With this fix, it stays low during training. ``` (WorkerDict pid=396879) [2025-08-12 07:39:42] dp actor After compute_log_prob, memory allocated (GB): 4.95, memory reserved (GB): 14.20, device memory used/total (GB): 17.72/79.15 ``` --------- Co-authored-by: narutolhy <luhongyu.4869@bytedance.com>" Co-authored-by: Chi Zhang <zhangchi.usc1992@bytedance.com>

What does this PR do?
Enable expandable_segments to avoid the increasing memory fragmentation caused by temporary variables during the training process of fsdp2, which may trigger probabilistic out-of-memory (OOM) errors.
Since both sglang and vllm can not work with expandable_segments:True, it has to be turn off during rollout.
Checklist Before Starting
[{modules}] {type}: {description}(This will be checked by the CI){modules}includefsdp,megatron,sglang,vllm,rollout,trainer,ci,training_utils,recipe,hardware,deployment,ray,worker,single_controller,misc,perf,model,algo,env,tool,ckpt,doc,data,like[megatron, fsdp, doc]{type}is infeat,fix,refactor,chore,test[BREAKING]to the beginning of the title.[BREAKING][fsdp, megatron] feat: dynamic batchingTest
Without this fix, memory reserved could be very high after compute_log_prob or update_actor.
With this fix, it stays low during training.
API and Usage Example
# Add code snippet or script demonstrating how to use thisDesign & Code Changes
Checklist Before Submitting
Important
Please check all the following items before requesting a review, otherwise the reviewer might deprioritize this PR for review.
pre-commit install && pre-commit run --all-files --show-diff-on-failure --color=alwaysci-requestchannel in theverlSlack workspace. (If not accessible, please try the Feishu group (飞书群).)Co-authored-by: Lu Hongyu luhongyu.4869@bytedance.com"