Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Hugging Face 22 min read Case study hardMaster

No GPU left behind: Unlocking Efficiency with Co-located vLLM in TRL

TRL v0.18.0 can run vLLM co-located with the training job on the same GPUs. vLLM's external_launcher executor puts it inside the torch.distributed process group, replacing the separate HTTP server that left training and inference GPUs idle in turn during GRPO's frequent generation steps. Benchmarks show up to 1.43× throughput for a 1.5B model with larger batches and up to 1.73× for a 7B model with higher tensor parallelism, though extra TP hurts small models. Qwen2.5-Math-72B trained ~1.26× faster on fewer GPUs with matching rewards and Math500 scores, using vLLM level-2 sleep to free memory and DeepSpeed ZeRO-3 with CPU optimizer offload. The write-up also covers debugging a TP seed-determinism regression, a buffer-restore bug after sleep and a remaining shutdown segfault.

Related posts

  • Async GRPO with LoRA across HF Jobs: a bucket, a proxy, and no NCCL

    Hugging Face hardMaster

    TRL v1.14's AsyncGRPOTrainer can train a LoRA adapter and sync only that adapter to vLLM, which lets the trainer and inference replicas run as separate Hugging Face Jobs on separate machines without NCCL. A rank-1 adapter for a 1.5B model is a few megabytes, so it travels through a Storage Bucket mounted at the same path in every Job, and vLLM loads it via /v1/load_lora_adapter. Versioned adapter names and max_staleness+2 adapter slots keep in-flight rollouts on their original policy and stop prefix-cache reuse across weight versions. A small proxy adds the auth header, broadcasts adapter loads, pause and resume to every replica, and routes the G=8 rollouts of each prompt to the replica holding their KV prefix using adapter-seeded chained block hashes. Using the AsyncGRPO metrics to find bottlenecks, five runs cut the same 500-step recipe from 3 h 27 min to 53 min.

  • Fine-tuning Llama 2 70B using PyTorch FSDP

    Hugging Face hardMaster

    Full fine-tuning of Llama 2 70B across two nodes of 8×A100 80GB GPUs with PyTorch FSDP, Hugging Face Accelerate, Transformers and TRL, addressing three obstacles. CPU RAM exhaustion (~2TB if every rank loads the model) is avoided by loading weights only on rank 0 via the meta device and broadcasting with sync_module_states. Slow, NCCL-timeout-prone checkpointing is fixed by saving intermediate checkpoints as SHARDED_STATE_DICT and switching to FULL_STATE_DICT only for the final save. Flash Attention V2 (kernel fusion, tiling, online softmax) plus gradient checkpointing cut VRAM and time; the run finished in ~13.5 hours, with a paged AdamW optimizer needed on a single node.

  • Shipping a Trillion Parameters With a Hub Bucket: Delta Weight Sync in TRL

    Hugging Face hardMaster

    Between consecutive RL optimizer steps, about 99% of bf16 weights stay bit-identical because Adam updates at RL learning rates fall below bf16's rounding threshold (|Δw| < |w|/256). TRL exploits this by detecting changed elements with optimizer pre/post-step hooks, encoding them as sparse safetensors deltas (int32 indices plus bf16 values), with full anchors every N steps, and pushing them to a Xet-backed Hugging Face Bucket that vLLM pulls from. On Qwen3-0.6B the per-step payload drops from 1.2 GB to 20–35 MB, and inference pauses for about a second instead of the full sync time. Because the bucket is the only shared channel, the trainer, vLLM server and environment can run on separate machines or Spaces with no shared cluster or RDMA.

  • Make LLM Fine-tuning 2x faster with Unsloth and 🤗 TRL

    Hugging Face mediumAdept

    Unsloth speeds up QLoRA fine-tuning of Llama and Mistral-family models by rewriting PyTorch modules as Triton kernels with manually derived backpropagation. Because no approximations are made, it claims 0% accuracy loss relative to standard QLoRA. Across 59 benchmark runs on A100 and T4 GPUs, it ran 1.5–3.9x faster than Hugging Face transformers and used up to 74% less VRAM. Code examples show loading pre-quantized 4-bit models with FastLanguageModel, attaching LoRA adapters, and training with TRL's SFTTrainer or DPOTrainer.

  • Fine-tuning 20B LLMs with RLHF on a 24GB consumer GPU

    Hugging Face hardMaster

    Combining trl with peft and bitsandbytes makes RLHF fine-tuning of a 20B-parameter LLM feasible on a single 24GB consumer GPU. The approach loads the active model in 8-bit using LLM.int8(), trains only small LoRA adapters to shrink optimizer state, and obtains reference logits for PPO from the same model by disabling the adapters, so no second model copy is needed. Memory rules of thumb are 4/2/1 GB per billion parameters in fp32/fp16/int8, plus 8 bytes per parameter for AdamW. A gpt-neox-20b model was fine-tuned on IMDB, its adapters were merged, and it was then RL-tuned to generate positive reviews. The main cost is speed, since adapters make forward and backward passes roughly twice as slow.

The quest for software engineering knowledge.

Look:
Layout: