Skip merge/unmerge when colocated vLLM only consumes PEFT LoRA factors

Open
#10,669 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
38/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python, pytorch

Research direction

Read RolloutTrainerMixin._move_adapter_to_vllm() and compare its merge, state-dict export, and unmerge path with the issue’s direct-export experiment. Start by checking how the colocated vLLM path handles plain dense PEFT LoRA and its existing fallback cases. Done means adapter publication avoids changing frozen BF16 base weights while preserving the expected adapter payload; the issue says the revised candidate still needs a run on the Ascend recipe.

Written by the indexing model from the issue text.

Description

enhancement

Bug Description / Bug 描述

In the Hugging Face trainer's colocated vLLM path, RolloutTrainerMixin._move_adapter_to_vllm() temporarily merges PEFT LoRA into the frozen base, reads the adapter state dict and then unmerges. The rollout request contains only the adapter. BF16 addition and subtraction can leave the frozen base with different values even when no training update occurs.

On an Ascend 910B2, with ms-swift 4.6.1, PEFT 0.20.0, vLLM and vLLM-Ascend 0.30.0, and dense Qwen3-8B BF16, the first adapter publish changed 2,112 of 16,777,216 elements in the frozen first-layer q_proj. A local direct-export experiment had zero changed elements in that projection. All 504 published BF16 tensors and all 32 first-rollout outputs matched. A separate Qwen3-1.7B L1 trace showed 392 aten::matmul calls and 196 each of aten::add_ and aten::sub_ in the old publication interval, compared with zero in the direct-export interval.

How to Reproduce / 如何复现

This CPU example uses a real PEFT layer and synthetic weights. The placement call matches what Swift currently does before its merge. The same BF16 change can be reproduced without a model download or vLLM.

import torch
from torch import nn
from peft import LoraConfig, get_peft_model

torch.manual_seed(127)
model = get_peft_model(nn.Sequential(nn.Linear(4, 4, bias=False)).bfloat16(),
                       LoraConfig(r=2, lora_alpha=2, target_modules=["0"]))
layer = model.base_model.model[0]
with torch.no_grad():
    layer.lora_B["default"].weight.normal_()
    before = layer.base_layer.weight.clone()
    layer._move_adapter_to_device_of_base_layer("default")
    model.merge_adapter()
    model.unmerge_adapter()
    print("changed frozen values:", layer.base_layer.weight.ne(before).sum().item())

Additional Information / 补充信息

Related work: #10154 described the same rounding defect and proposed restoring original storage after merging. This proposal is for the adapter-only request and skips the dense computation entirely for plain dense PEFT LoRA. #10360 and #10363 describe a related optimizer dtype issue. Here the dtype/device conversion would run on exported snapshots, leaving the FP32 training Parameters and their AdamW state intact.

A local candidate targets main at 9e4d40cc48c74988f167045db4fdb8b0008acf77. It covers single-rank colocate, one plain default PEFT Linear LoRA adapter, one parameter group and no offload. A small CPU regression checks frozen weights, exact BF16 payloads, fallback and AdamW continuation. The Ascend measurements above used a local direct-export trial. The revised upstream candidate snapshots detached tensors and still needs a run on this NPU recipe.

Dominant language
Python
Stars
16.2k
Forks
1.8k
Avg merge
1d 14h
Merged PRs (30d)
68

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from modelscope/ms-swift

All issues in modelscope/ms-swift

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.