#7423·trl

Merged-LoRA export changes frozen base weights

Author: ingambeCreated Sep 28, 2026Updated Sep 28, 2026

On the LoRA and vLLM generation path, weight sync merges the adapter into the frozen base weights and then unmerges it by subtracting a rounded delta. Due to floating points imprecision, the base weights is modified. The drift repeats at every synchronization. Also reported in a bigger issue ticket in #6688, this ticket is a focused one with reproduction code. Will be used for a companion PR.

Code Flow:

sync_weights() iterates over the training model's weights. _iter_named_params() merges adapters into that model, yields the merged tensors, then unmerges.

python
original = W
W = round_to_weight_dtype(W + adapter_delta)  # Merge for inference export.
transfer_to_vllm(W)
W = round_to_weight_dtype(W - adapter_delta)  # Unmerge; rounding is not reversible.
# W can differ from original.

The same issue applies to OnlineDPOTrainer and AsyncGRPOTrainer. Under ZeRO-3 the merge acts on gathered copies rather than the shards, so the shards do not drift (AFAIK, not reproduced).

Reproduction

python
import torch
from accelerate import Accelerator
from peft import LoraConfig, get_peft_model
from trl.distributed import DistributedBackend
from trl.generation.vllm_generation import VLLMGeneration

model = get_peft_model(
    torch.nn.Sequential(torch.nn.Linear(1, 1, bias=False)),
    LoraConfig(r=1, lora_alpha=1, target_modules=["0"]),
)
layer = model.base_model.model[0]
with torch.no_grad():
    layer.base_layer.weight.fill_(0.1)
    layer.lora_A["default"].weight.fill_(0.2)
    layer.lora_B["default"].weight.fill_(0.2)
before = layer.base_layer.weight.detach().clone()

exporter = object.__new__(VLLMGeneration)  # Isolate the real exporter; no inference server needed.
exporter.model = model
exporter._dist = DistributedBackend(Accelerator(cpu=True))
for _ in exporter._iter_named_params():
    pass
print("before:", before.item())
print("after:", layer.base_layer.weight.item())
print("unchanged:", torch.equal(before, layer.base_layer.weight))

Observed:

before: 0.10000000149011612
after: 0.09999999403953552
unchanged: False

Expected:

before: 0.10000000149011612
after: 0.10000000149011612
unchanged: True

Checklist

  • Searched existing fork and relevant upstream issues; related reports are linked where applicable.
  • Included system information.
  • Included a complete, minimal reproduction and exact observed output.
  • Code is provided in copyable code blocks.
  • Traceback requirement reviewed; no unhandled traceback in this reproduction.

System Info

  • Platform: Linux-6.18.44-fc-v37-x86_64-with-glibc2.39
  • Python version: 3.12.3
  • TRL version: 1.15.0.dev0
  • PyTorch version: 2.14.0
  • accelerator(s): cpu
  • Transformers version: 5.17.0
  • Accelerate version: 1.15.0
  • Accelerate config: not found
  • Datasets version: 5.0.1
  • HF Hub version: 1.33.0
  • bitsandbytes version: not installed
  • DeepSpeed version: not installed
  • Liger-Kernel version: not installed
  • PEFT version: 0.21.0
  • vLLM version: not installed

Checklist

  • I have checked that my issue isn't already filed (see open issues)
  • I have included my system information
  • Any code provided is minimal, complete, and reproducible (more on MREs)
  • Any code provided is properly formatted in code blocks, (no screenshot, more on code blocks)
  • Any traceback provided is complete