groundy
Infrastructure & Runtime

Fine-Tuning a 20B LLM With RLHF on a 24GB GPU: What Fits

TRL's 20B RLHF on 24GB guide is a documented premise, not a verified fit here; PPO memory, QLoRA's SFT evidence, DPO, and AsyncGRPO guide the choice.

Published Updated 7 references
On this page9 sections

On a 24GB GPU, start with algorithm choice rather than adapter rank. DPO removes the separate reward-model stage and reinforcement-learning loop used in conventional RLHF, while TRL describes GRPO as more memory-efficient than PPO. If you choose TRL’s stable AsyncGRPOTrainer for faster generation, its documented example places the vLLM server and trainer on different GPUs. Those distinctions change the hardware plan before LoRA tuning begins.

They do not certify an end-to-end 20B training run on one 24GB card. The useful approach is to separate the documented model requirements and QLoRA measurements from the configuration choices that still need a local test.

Where does the “20B on 24GB” claim come from?

TRL’s documentation lists a guide titled “Fine-tuning 20B LLMs with RLHF on a 24GB consumer GPU,” published March 9, 2023. The same listing dates “StackLLaMA: A hands-on guide to train LLaMA with RLHF” to April 5, 2023, and the more general “Illustrating Reinforcement Learning from Human Feedback” post to December 9, 2022. These are three distinct entries, not three descriptions of the same result.

The listing supports the 20B guide’s title, subject, and date. By itself, it does not establish the guide’s quantization method, adapter configuration, trainer, component-level memory budget, or reproducibility. Those details should not be inferred from the headline.

The listing also dates the TRL v1 announcement to March 31, 2026. Current TRL documentation and its repository provide trainers for SFT, GRPO, DPO, reward modeling, and other post-training methods. For hardware planning, the relevant fact is that these choices are available now; the sources do not establish that v1 first consolidated or added all of them.

What does RLHF actually load into VRAM?

RLHF trains a reward model and a reinforcement-learning policy, both commonly initialized from a pretrained autoregressive language model. The reward model replaces the language model’s final layer with a regression head and produces a scalar score. The policy generates text.

That does not make two identical 20B models mandatory. Same-size weight duplication applies if you choose a 20B reward model alongside a 20B policy. The reward model can be a different size, and device placement is an implementation decision. Residency and execution also need to be distinguished: having two models allocated on a card is not the same claim as both performing forward passes simultaneously.

The sourced PPO loop is sequential at the algorithmic level: sample a prompt, generate a response from the policy, calculate its reward with the reward model, store the resulting triple, and then update the policy. Autoregressive generation itself takes multiple forward passes. PPO also maintains a value estimator that updates concurrently with the policy during training, adding another component to the implementation’s memory plan.

A careful budget therefore considers:

  • Policy base weights: QLoRA stores a frozen base in 4-bit and backpropagates through it into LoRA adapters.
  • Adapters and their optimizer states: these are much smaller than full-model training states, but their size depends on rank and target modules.
  • Activation gradients: these can exceed the adapter weights by a wide margin and respond to batch and sequence settings.
  • Reward model: its size, precision, and device determine whether it duplicates a substantial weight allocation.
  • PPO value estimator and update-time state: the cited algorithm establishes the estimator’s role, not a universal GB figure for it.

Adapters are small, but activation gradients are not negligible

A LoRA overview gives a typical trainable-parameter range of 0.5–5%; on a 20B model, that corresponds arithmetically to 100 million to 1 billion parameters. It is a broad range, not a recommended adapter size.

QLoRA’s own memory example is more instructive. For a 7B LLaMA model trained on FLAN v2 with batch size 1 and LoRA weights equal to 0.2% of the original weights, the paper reports 26MB of LoRA parameters, 567MB of LoRA input gradients, and 5,048MB for the 4-bit base model. With gradient checkpointing, it reports input gradients averaging 18MB per sequence. The authors conclude that aggressively reducing LoRA parameters yields only minor memory benefits in that setting.

This is why “the adapter is only a few million parameters” is not a safe general claim, and why lowering rank should not be the automatic response to every OOM. The adapter allocation may not be the component driving the peak.

What does the 24GB evidence actually show?

QLoRA demonstrates fine-tuning a 65B model on one 48GB GPU, reducing average memory requirements from more than 780GB for regular 16-bit fine-tuning to less than 48GB. Its three central techniques are 4-bit NormalFloat (NF4), double quantization of quantization constants, and paged optimizers.

The training scope matters. The paper explicitly uses cross-entropy supervised fine-tuning without reinforcement learning, including for datasets containing human judgments. Its results support quantized adapter training; they are not measurements of 20B PPO, reward scoring, or RLHF rollout memory.

Appendix G supplies the paper’s most relevant 24GB example. Its memory-footprint discussion uses batch size 1, sequence length 512, and gradient checkpointing. The input-gradient estimate covers adapters and base-model weights but not attention. The authors say the 33B model does not quite fit into 24GB and that paged optimizers are needed to train it. They also warn that a larger batch or longer sequence can make activation gradients consume considerable memory.

That example does not establish batch size 1 or 512 tokens as limits for 20B RLHF. Starting with batch size 1 and conservative sequence and generation lengths is a reasonable untested configuration heuristic for this setup, not a reported threshold. Measure each stage, then change one variable at a time.

Paged optimizers address a specific spike

QLoRA’s paged optimizers use NVIDIA unified memory for optimizer states. States can be evicted to CPU RAM when the GPU runs out of memory and paged back for the optimizer update. The paper connects this mechanism to gradient-checkpointing memory spikes when processing long-sequence mini-batches.

It does not establish paged optimizers as a remedy for generation-rollout OOMs. The authors provide no hard paged-optimizer measurements because paging was rare in their experiments, although they report the same training speed as regular optimizers for 65B models on 48GB GPUs at batch size 16.

When is the reward model the important extra cost?

If you select a reward model with the same 20B parameter class as the policy and place both on the GPU, its base weights can be the largest additional model allocation. Freezing a reward model avoids training its weights, but freezing alone does not eliminate storage for those weights.

Quantizing the reward model is a separate choice from quantizing the policy. QLoRA’s supervised adapter results do not measure whether a 4-bit reward model preserves preference-scoring quality. Quantization noise could alter scores or preference ordering, and those scores feed subsequent PPO updates. That is a plausible risk requiring validation, not a reported degradation result for this configuration.

Before a long run, compare reward scores and pairwise orderings against a higher-precision reward model on a representative sample. A memory saving is not useful if the scoring behavior you intended to optimize has changed in a way that matters for the task.

What can you say about throughput and CPU offload?

No cited source here measures end-to-end 20B PPO throughput on a 24GB GPU. QLoRA reports memory savings without degrading runtime relative to its 16-bit fine-tuning baseline, but that result belongs to its supervised training setup. It cannot tell you how often throughput, rather than memory, will become the practical limit for an RLHF run.

Autoregressive rollout generation, reward scoring, backpropagation, and optimizer updates should be timed separately. Otherwise, a slow run can be misdiagnosed as a generation problem when the cost sits elsewhere.

Moving the reward model to CPU is an experiment that may free GPU memory, not a demonstrated way to make policy generation faster. It can add host-to-device transfers and slower reward scoring. Measure total samples or tokens per unit time and complete optimizer-step time before deciding whether the trade is worthwhile.

QLoRA also assumes access to model weights. GeeksforGeeks’s QLoRA overview describes its use with open-weight families such as LLaMA, Mistral, and Falcon, whose weights can be quantized and adapted directly.

When should you skip PPO entirely?

If a static preference dataset is acceptable, DPO is the cleaner first option to evaluate. DPO defines a preference loss directly on the policy, eliminating the separate reward-model stage and reinforcement-learning loop. That removes the reward-model allocation associated with conventional RLHF, although it does not by itself supply a total 20B memory measurement or guarantee a 24GB fit.

The quality tradeoff remains task-dependent. The same overview reports comparable and sometimes superior results for DPO, but also datasets where RLHF beat DPO, including benchmarks attempting to measure truthfulness. Memory savings justify testing DPO first; they do not settle which method produces the better model for your data.

GRPO preserves on-policy generation but can use programmatic rewards. TRL’s GRPO example passes accuracy_reward through reward_funcs, and the repository describes GRPO as more memory-efficient than PPO and as the algorithm used to train DeepSeek-R1. This supports rule-based or programmatic scoring in that configuration; it does not establish that reward computation runs on the CPU.

AsyncGRPOTrainer is now stable. It overlaps generation with training: a vLLM server streams rollouts while the trainer updates the model. The documented setup starts that server on GPU 0 and runs training on GPU 1. Budget that recipe as a two-GPU configuration, not a way to make the documented example fit on one 24GB card.

A conservative starting checklist

This is a test plan, not a validated 20B RLHF recipe:

  1. Choose the algorithm first. If static preferences are acceptable, evaluate DPO before engineering a PPO memory workaround. Validate quality on the target task.
  2. Write down every model component. For PPO, record the policy, reward model, and value-estimator implementation, including parameter size, precision, and device. Do not assume same-size duplication unless you have configured it.
  3. Use QLoRA within its supported scope. NF4, double quantization, frozen 4-bit base weights, and higher-precision adapters have strong supervised fine-tuning evidence. Their application to your complete RLHF run still needs testing.
  4. Treat batch size 1 and short sequence or generation limits as initial heuristics. Log peak memory during generation, reward scoring, backward computation, and optimizer updates. Increase one dimension at a time rather than trusting a universal token threshold.
  5. Test gradient checkpointing and paged optimizers for their documented roles. Checkpointing trades recomputation for lower activation storage. Paged optimizers manage optimizer-state spikes associated with gradient checkpointing; neither is a blanket rollout guarantee.
  6. Benchmark any CPU offload. Include transfer and reward-scoring costs in the result.
  7. Count AsyncGRPO’s GPUs. The documented server-and-trainer example uses two.

I would try DPO first when its offline preference setup fits the problem. If PPO’s online generation and reward loop are necessary, I would treat 20B on 24GB as an instrumented experiment, not a promised configuration. The supported conclusion is narrower and more useful: QLoRA explains how quantized adapter training reduces memory, PPO’s extra components must be budgeted explicitly, and TRL’s documented AsyncGRPO speed recipe shifts generation onto another GPU. What fits on your card remains something to measure.

References

Follow the links in the article for context. The supporting material is collected here for further reading.

  1. Reinforcement learning from human feedback - Wikipediaen.wikipedia.orgAccessed
  2. Reinforcement learning from Human Feedback - GeeksforGeeksgeeksforgeeks.orgAccessed
  3. Fine-Tuning using LoRA and QLoRA - GeeksforGeeksgeeksforgeeks.orgAccessed
  4. QLoRA (Quantized Low-Rank Adapter) - GeeksforGeeksgeeksforgeeks.orgAccessed

Join the discussion

Share a useful perspective or ask a question about this article.

Discussion guidelinesComments privacy