Skip to content

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

Hugging Face 13 min read Deep dive hardMaster

🐯 Liger GRPO meets TRL

Liger's chunked loss, extended to GRPO and integrated into TRL's GRPOTrainer, cuts peak training memory by up to 40% with no change in reward curves. It chunks the lm_head input along the batch and computes each chunk's gradients during the forward pass, so full logits never need to be held for backward. Benchmarks on Qwen3-0.6B with gsm8k show savings growing with batch size. FSDP and PEFT support allow 1.5–1.8x larger batch sizes across Qwen3 sizes, and LoRA removes the need for a separate reference model. Setup is a `use_liger_loss=True` flag, with optional vLLM-server generation for faster rollouts.

Related posts

  • 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.

  • TRL v1.0: Post-Training Library Built to Move with the Field

    Hugging Face mediumAdept

    TRL v1.0 turns Hugging Face's post-training codebase, now covering 75+ methods and downloaded 3M times a month, into a library with an explicit stability contract. A semver-governed stable core (SFT, DPO, reward modeling, RLOO, GRPO trainers) sits alongside a fast-moving trl.experimental namespace. Methods are promoted based on the ratio of usage to maintenance cost. Because post-training paradigms keep shifting (PPO to DPO to RLVR/GRPO), the design deliberately avoids shared base classes and generic abstractions and accepts near line-for-line duplication between trainers like RLOO and GRPO, illustrated by the failed Judge abstraction. A comparison against OpenRLHF, veRL, PRIME-RL, Tinker, LLaMA-Factory and others positions TRL as broad, low-infrastructure and stable but lacking native tensor parallelism, with asynchronous GRPO planned next.

  • Fixing Gradient Accumulation

    Hugging Face mediumAdept

    Gradient accumulation in the transformers Trainer did not match full-batch training because the default model loss averaged per-batch cross-entropy instead of summing token losses across all accumulated batches and dividing by the total count of non-padding tokens. The fix switches the causal LM loss to sum reduction normalized by a passed-in num_items. Models inheriting PreTrainedModel also gain a loss_function property configurable via config.loss_type and LOSS_MAPPING, and the Trainer will accept user-supplied loss functions. The fix is available by installing transformers from main.

  • Putting RL back in RLHF

    Hugging Face hardMaster

    RLOO (REINFORCE Leave-One-Out) is now available as a trainer in Hugging Face TRL. It is an online RLHF algorithm that drops PPO's value model. It treats the whole completion as a single action, uses the REINFORCE loss, and computes each sample's baseline as the mean reward of the other kβˆ’1 completions for the same prompt. That cuts vRAM by roughly 50-70% and makes training 2-3x faster than PPO on Pythia 1B and 6.9B, while matching PPO's GPT-4-judged win rate (78.7% for 6.9B on TL;DR) and beating DPO. Code walkthroughs show the advantage computation and that REINFORCE is a special case of the PPO loss. There is a caveat: bf16 numerical mismatches between generation and training logprobs hurt RLOO more than PPO.

  • 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.

The quest for software engineering knowledge.

Look:
Layout: