It has been revealed that TRL supports training LLMs using GRPO, an online learning algorithm recently introduced in the DeepSeekMath paper. In GRPO, the model learns from its own outputs: it generates responses during training, receives feedback, and uses that feedback to improve itself over time.
Sources indicate that this makes generation a critical step in the training loop — and also a major bottleneck. To speed up generation, TRL integrates with vLLM. This combination lets you train powerful models more efficiently in GRPO setup. However, there’s a catch. (Related: Tech Report: One Piece Chapter 1200: Release date & maj...)
Before TRL v0.18.0, vLLM was only supported in server mode, running as a separate process on different GPUs from the training job. It communicated with the training script over HTTP, which made the setup modular and easy to use — but also introduced GPU inefficiencies. (Related: Latest Update: F1 star Max Verstappen played 40 hours o...)
This “ping-pong” between training and generation causes:.
It has been revealed that in online learning methods like GRPO — where generation happens constantly — this inefficiency becomes even more painful. You spend more on hardware, but don't get the performance you'd expect.
So, the key question becomes: Can we share the same GPUs for both training and generation, instead of separating them?
Recent findings suggest that the main problem was that training and inference ran on separate GPUs, leading to idle time and underutilization. The natural solution? Run both on the same GPUs. Instead of having vLLM operate as a standalone server in its own process and devices, what if vLLM could run alongside the training code, within the same distributed process group? This would let us launch a single distributed job where training and inference share the same devices, switching between tasks efficiently without wasting resources.
This approach is what we refer to as colocation. Training and inference are co-located on the same GPUs and coordinated via the same process group, allowing them to take turns smoothly — no extra hardware needed.
Industry observers note that previously, this wasn’t possible in TRL, which relied on vLLM as an external HTTP server. That changed with our PR #3394, which added support for vLLM’s external launcher and true integration into the training process.
Unified Execution: By embedding vLLM in the same process group, both training and inference tasks can share the same GPUs, taking turns instead of waiting on each other. This reduces idle time and boosts overall efficiency.
Skip HTTP Communication: No need for REST API calls or networking — vLLM runs inline with the training loop, avoiding overhead and latency.
Torchrun Compatibility: Works seamlessly with torchrun, so it's easy to scale across nodes with minimal config changes.
TP and DP Support: Compatible with Tensor Parallelism and Data Parallelism, making it suitable for large-scale training runs.
Recent findings suggest that SPMD Execution Pattern: Uses a Single Program, Multiple Data (SPMD) model, where each GPU runs its own instance of the engine in sync. Ideal for distributed multi-GPU, multi-node setups.
Simplified Deployment: You no longer need to maintain a separate server script — vLLM is introduced and controlled directly inside your training job.
Enhanced Throughput: By avoiding idle GPUs and eliminating inter-process communication, the system delivers faster training and generation, especially important in online learning setups like GRPO.
Robust Inter-process Communication: This is more robust because it avoids the complexity of setting up distributed process groups between independent processes, as required in server mode.
Thanks to this feature, co-located training and inference is no longer a hack — it’s now first-class, scalable, and production-ready.
The shift from server TRL to co-located TRL is all about smarter GPU usage. The diagram below indicates the difference:.
According to recent reports, in the server TRL setup, training and inference run on separate GPUs. For example:.
Sources indicate that during training steps, GPU 3 sits idle. During generation steps (inference), GPUs 0–2 are idle while GPU 3 generates outputs.
In contrast, the co-located TRL setup runs both training and vLLM on the same GPUs. Each GPU:.
Training and inference take turns using the GPU’s resources — no need for dedicated devices or separate processes.
Instead of launching vLLM as a server, the trainer now launches vLLM in-process using the external launcher, as shown below:.
Recent findings suggest that co-located vLLM respects the torch.distributed process group and rank structure. This allows vLLM to be initialized alongside training without conflict and makes TP/DP setups work seamlessly:.
Co-located vLLM no longer relies on REST APIs — it runs directly in memory and communicates via native Python calls:.
To use this setup, simply set vllm_mode="colocate" in your GRPO configuration:.
Note: Depending on the model size and the overall GPU memory requirements for training, you may need to adjust the vllm_gpu_memory_utilization parameter in GRPOConfig to avoid underutilization or out-of-memory errors.
To measure the impact of colocation, we ran a series of experiments comparing the traditional server mode (where vLLM runs on a separate GPU as a standalone server) with the latest co-locate mode (where training and inference share the same GPUs).
In server mode, only 7 GPUs are used for training because 1 GPU is fully dedicated to the vLLM inference server.
In co-locate mode, all 8 GPUs are used for training — increasing the effective batch size by default.
To ensure a fair comparison, we normalized throughput in server mode by a factor of 8/7. This adjustment accounts for the greater training capacity in co-locate mode and allows us to compare the two setups under equal training conditions.
When training large models like Qwen2.5-Math-72B, it's important to use the right strategies to make training efficient, scalable, and stable across many GPUs and nodes. In our setup, we combined co-located vLLM with several key optimizations to make this work efficiently.
In a recent development, when using co-located training, managing GPU memory is crucial so that both training and inference can run smoothly on the same devices. To support this, we added vLLM’s sleep() API into the GRPO training loop.
The sleep() function temporarily pauses the vLLM engine and frees up GPU memory. It supports two levels:.
Level 1: Unloads model weights from GPU (keeps them in CPU memory) and clears the KV cache. Useful when the same model will be reused soon.
Level 2: Unloads both model weights and KV cache entirely. Best for scenarios where the model will change or won’t be reused right away.
In GRPO, the model is updated after every step — so we use Level 2 sleep.
This small addition makes a major difference in enabling smooth and scalable co-located training.
To train large models like Qwen2.5-72B, we rely on DeepSpeed ZeRO Stage 3, the same setup used in plain TRL.
It has been revealed that zeRO helps scale large models by distributing memory across GPUs. Stage 3 goes further by partitioning:.
In a recent development, this is essential for models that can’t fit on a single GPU. With ZeRO Stage 3, each GPU handles only a portion of the model.
"offload_optimizer": {"device": "cpu"} Moves optimizer states to CPU to free GPU memory — critical in co-located setups.
"overlap_comm": true Enables communication overlap with computation, speeding up training.
"contiguous_gradients": true Allocates gradients in a single memory block, improving memory access and reducing fragmentation.
These optimizations help train 72B models efficiently, and ensure colocation remains stable under tight memory constraints.
As recommended in TRL, we use Accelerate, a lightweight library that simplifies distributed training. It handles:.
This makes the setup clean, scalable, and easy to maintain.
Even with 4 fewer GPUs, the co-locate setup is ~1.26× faster than plain TRL. This highlights the effectiveness of smarter GPU sharing and memory cleanup using sleep().
Training reward plots for co-locate and plain setups are nearly identical, demonstrating that:.
It has been revealed that we evaluated three models: Base model, Co-locate-trained model, Plain-trained model on the Math500 benchmark. Both trained models outperform the base, and the co-locate model performs on par with the plain-trained model — confirming that colocation does not compromise downstream performance.
Through our work on scaling GRPO training with co-located vLLM, we've faced several critical challenges and learned notable lessons about efficiency, flexibility, and system design when training large models.
It has been revealed that tensor Parallelism Bug in vLLM ≥ 0.8.0. Tensor Parallelism (TP) with external_launcher stopped working in vLLM version 0.8.0 and above. This was tracked under Issue #15895. To identify the breaking point, we followed the approach described in this vLLM developer blog post, which provides wheels for every commit. After bisecting, we identified the breaking commit as cc10281. The root cause was determinism — the newer versions required explicitly setting the random seed. Once the seed was set, the issue went away.
It has been revealed that level 2 Sleep Buffer Bug. Initially, level 2 sleep didn’t work correctly when we tried to reload weights using load_weights. This matter was tracked in Issue #16564. The problem was that model buffers (like running mean/var in BatchNorm) weren’t restored after waking up from sleep. The fix came with PR #16889, which added logic to explicitly restore buffers when waking up from level 2 sleep. We now keep a copy of the original buffers and manually reapply them after loading new weights.
Segmentation Fault on Exit. There’s still an open issue with vLLM sleep causing a segmentation fault at the end of training when closing processes. This was reported in Issue #16993. This crash happens during shutdown but does not break training itself, so we were able to complete all demos and experiments shared in this blog. However, we’re waiting for an official fix before integrating sleep() fully into TRL upstream.
These challenges were not blockers, but they required careful debugging, version control, and a deeper understanding of how vLLM manages memory and parallelism under the hood.
Recent findings suggest that co-located inference dramatically improves GPU utilization. By allowing training and generation to share the same GPUs, we eliminate idle time and reduce hardware requirements — achieving higher throughput even with fewer GPUs.
Sources indicate that vLLM's sleep() feature is essential for large-scale colocation. It enables fine-grained control over memory usage, allowing training to fully reclaim GPU memory between generation steps — a key enabler for models like Qwen2.5-72B.
Industry observers note that deepSpeed ZeRO Stage 3 is essential for training large models. It allows extremely large networks to fit into memory by distributing model weights, gradients, and optimizer states across multiple GPUs. In our experience, enabling contiguous_gradients helped reduce memory fragmentation, while offloading the optimizer to the CPU freed up critical GPU memory — both of which were especially helpful in colocated setups.
Colocation is powerful but comes with trade-offs. It works best when GPU memory is carefully managed, often requiring manual tuning of memory usage parameters like vllm_gpu_memory_utilization. While it offers clear throughput benefits and reduces idle GPU time, colocation may not be ideal for models with tight memory budgets or when memory fragmentation is not well controlled. When done right, though, it unlocks significant efficiency gains.
Recent findings suggest that TP/DP compatibility, Accelerate, and torchrun support make deployment seamless. Despite the complexity of the underlying architecture, the entire system can be launched and scaled with standard distributed tools.
Co-located training maintains model quality. Across multiple benchmarks (Math500, AIME24), co-located and plain setups produced comparable results, validating that performance isn’t sacrificed for efficiency.
This blog post explored how co-locating vLLM with GRPO training unlocks significant efficiency gains when training large language models — including models as large as Qwen2.5-72B.
Traditionally, TRL only supported vLLM in server mode, which required separate processes and GPUs for inference, leading to wasted compute and idle time. With the introduction of vLLM’s external launcher and the colocation PR in TRL PR #3394, we can now run training and inference within the same distributed process group, on the same GPUs, with full support for TP, DP, and Accelerate.
While challenges remain — such as version-specific vLLM bugs and edge cases such as with sleep() — the overall results show that co-located GRPO is a practical, scalable solution for training large models efficiently. We’re excited to continue refining this setup, integrating features like FSDP, and pushing the limits of large model training — making it faster, cheaper, and more accessible for everyone building the next generation of LLMs.
Below is an example to try out GRPO training with co-located vLLM.
Great work on this and thanks for the detailed write up. In our experience this approach has worked really well for larger-scale multi-node training. We've seen up to 3x improvement in training speed training 32b models.
Impressive! Thanks for sharing!
Industry observers note that do the example code train_grpo_colocate.py need to be launched using accelerate? Running it just using python3 train_grpo_colocate.py ends with an exception about missing env vars ("RANK", "LOCAL_RANK"...).
Does vllm_mode="colocate" work with PEFT?
In a recent development, @lhkhiem28 actually we didnt try this, however there is no reason that it wouldnt work since LoRA is relates to model training, whereas our change relates to generation. However, it seems that @ajinkya-tejankar below has tried it and it seems to work.
Industry observers note that great article! Is data parallel support planned for the colocate mode?
DP is supported.For example, if # of GPUS = 8 and vllm_tensor_parallel_size = 2 → groups: [0,1], [2,3], [4,5], [6,7] -> making DP=4.
Is DeepSpeed planned to be the main engine to support multi-gpu and multi-node setups for TRL in the future? I tried FSDP and it doesn't work with a bunch of configurations that work with DeepSpeed. For instance, I couldn't get GRPO + FSDP + LoRA + VLLM colocate to work, but swapping FSDP with DeepSpeed works. Is DeepSpeed more reliable than plain FSDP from PyTorch?
PS: Great blog! Thanks a lot for your efforts :).
According to recent reports, @ajinkya-tejankar in our private experimentation, we have tried to hack in FSDP2 into accelerate, and tested it with collocate. There are a few concerns I believe that remain. 1. TRL's weight loading code only works with FSDP1 I believe. 2. FSDP1 has a NAN problem and I had filed a bug report awhile back https://github.com/vllm-project/vllm/issues/14443.
See the previous discussion here:https://github.com/huggingface/trl/pull/3317#issuecomment-2842576427.
Thank you so much for the great article.Your article was tremendously helpful for training GRPO in colocate mode.
By the way, have you ever trained a model using LoRA?You mentioned training a 72B model, but I don’t have access to 32 GPUs, so full finetuning isn’t an option for me.
When training a model with the combination of DeepSpeed ZeRO-3 + vLLM colocate + LoRA + GRPO, and configuring modules_to_save=["embed_tokens", "lm_head"] in the LoRA config (as shown below), I encounter the error at the bottom.I’d appreciate any solutions or tips you used to train the 72B model.
The versions of the libraries I used are:.
AttributeError: 'Linear' object has no attribute 'ds_grads_remaining'.
The full error log is as follows:.
I noticed that having vLLM sleep didn't make it in to TRL, what's the reason for that?
Recent findings suggest that the reason is noted in the "segmentation fault" discussion under https://huggingface.co/blog/vllm-colocate#challenges. Basically, we are waiting for a fix of the bug (https://github.com/vllm-project/vllm/challenges/16993) before integrating sleep() fully into TRL upstream.
It has been revealed that how did you distribute the weights in your Qwen 72B experiment? Did you just have it running w/ TP=8 on a single node, or did each node have it's own copy of Qwen 72B?
Yes, we set TP=8, meaning each node has a copy of the shard of the 72B model.
Industry observers note that great article!I am using VLLM Co-located in a Slurm cluster for GRPO and I get an TCP exception:TCP client failed to connect/validate to host 10.0.1.163:35345 though I thought it runs inline with the training loop. Is this normal? :D.
Recent findings suggest that this is not normal. make sure you set vllm_mode="colocate".
This is great; should the docs be updated?
It has been revealed that it's working nicely. But, I got error when I tried qLoRA with load_in_4bit: true.
Industry observers note that does it support qLoRA, or not yet? I found the following in the TRL/GRPO document, so I thought qLoRA is supported. Thanks a lot.
could you please release the training scripts and deepspeed configuration of 70B model?
In a recent development, here are all the config used. But note that this was a while ago, so parameter names may have changed.
Thanks for sharing the post! I wonder if you can provide the transformers, trl, vllm, deepspeed, accelerate versions to launch the code?
Thanks for sharing the post! I wonder if you can provide the transformers, trl, vllm, deepspeed, accelerate versions to launch the code?