peft icon indicating copy to clipboard operation
peft copied to clipboard

MoE recipe in the LoRA docs gives adapters that vLLM serves with the wrong expert scaling

Open surajsharan opened this issue 2 months ago • 6 comments

System Info

  • peft main (9146289a) and 0.21.2, transformers 5.10.2 (PEFT side)
  • vLLM 0.30.0 and main (58b3298), transformers 5.18.0 (vLLM side)
  • torch 2.12.0 / 2.13.0 (cu130), Python 3.13, Linux (WSL2), RTX 3090 and RTX 3080

Who can help?

@BenjaminBossan @kashif

Reproduction

The "MoE expert parameters and vLLM" section of the LoRA docs (docs/source/package_reference/lora.md) targets the experts with target_parameters, lowers their rank with rank_pattern={"experts.gate_up_proj": r // num_experts, ...}, and says the model can then be served with vLLM.

vLLM does not read rank_pattern or alpha_pattern (vllm-project/vllm#59799). It applies a single lora_alpha / r to every LoRA weight, while PEFT scales the experts by lora_alpha / (r // num_experts), so in vLLM the expert updates are r / effective_r times too small, without a warning.

OLMoE-1B-7B (64 experts) with the docs recipe as written (r=16, lora_alpha=32, q_proj/v_proj plus both expert parameters, so effective_r=1: experts scaled 16x in PEFT, 1x in vLLM), LoRA trained for 200 steps on wikitext-2, perplexity on the wikitext-2 test split:

perplexity
base model, PEFT / vLLM 13.09 / 13.08
adapter in PEFT 10.06
same adapter in vLLM 0.30.0 11.28
same adapter in vLLM 0.30.0, expert scaling folded into lora_B 10.06
same adapter in vLLM with vllm-project/vllm#59801 10.06

This affects any rank_pattern / alpha_pattern that changes alpha / r for a module, dense models included; the MoE recipe is where the docs point users at it and where the factor is largest.

For MoE models that vLLM does not flag as is_3d_moe_weight (OLMoE, Qwen3-MoE, Mixtral and others; GPT-OSS is flagged), a target_parameters adapter also kills the vLLM engine with a bare AssertionError, unless the engine is started with enable_mixed_moe_lora_format=True and the request passes LoRARequest(..., is_3d_lora_weight=True). The docs mention neither.

On the PEFT side, the same recipe prints a misleading warning on main. Reproducer (CPU only):

import warnings
from transformers import AutoModelForCausalLM, Qwen3MoeConfig
from peft import LoraConfig, get_peft_model

cfg = Qwen3MoeConfig(vocab_size=128, hidden_size=64, intermediate_size=128, moe_intermediate_size=32,
                     num_hidden_layers=1, num_attention_heads=2, num_key_value_heads=1, head_dim=32,
                     num_experts=4, num_experts_per_tok=2)
config = LoraConfig(r=8, target_modules=[], target_parameters=["mlp.experts.gate_up_proj", "mlp.experts.down_proj"],
                    rank_pattern={"experts.gate_up_proj": 2})
with warnings.catch_warnings(record=True) as w:
    warnings.simplefilter("always")
    model = get_peft_model(AutoModelForCausalLM.from_config(cfg), config)
print([str(x.message) for x in w if "rank_pattern" in str(x.message)])
# ["The following rank_pattern keys did not match any targeted module and were ignored: ['experts.gate_up_proj']."]
print(model.base_model.model.model.layers[0].mlp.experts.base_layer.lora_A["default"].weight.shape)
# torch.Size([8, 64]) -> rank 2 x 4 experts, so the key was applied

The check added in #3588 only compares pattern keys against targeted_module_names, not targeted_parameter_names.

The reproduction scripts for the vLLM numbers (tiny models and OLMoE) are available if useful. I used an AI assistant to help run the experiments.

Expected behavior

  • The MoE section of the LoRA docs should say that vLLM versions without vllm-project/vllm#59801 apply a single lora_alpha / r, and give the workaround for them: multiply each lora_B whose module has a pattern by (alpha_m / r_m) / (lora_alpha / r) and remove both patterns from adapter_config.json. Training is unchanged, so existing adapters can be converted. It should also name the two vLLM options needed to load target_parameters adapters on non-3D MoE models.
  • PEFT should not warn that rank_pattern / alpha_pattern keys were ignored when they match a targeted parameter. The fix is to also match against targeted_parameter_names in the #3588 check.

I'd like to provide the PR for both (the docs change, and the one-line fix with a test, which I have ready). If you think the conversion is worth a function rather than a docs snippet, for example next to save_as_lora, I can add that too.

surajsharan avatar Oct 02 '26 17:10 surajsharan

Thanks for reporting. I agree, let's update the docs but make the wording forward looking, i.e. mention that it's an issue at the time of writing and may be fixed in the future (you can link the PR, but it's possible it will be fixed in another one, so don't make that authoritative).

About the warning: I agree that targeted_parameter_names needs to be considered too. Please provide a separate PR for that, and please include a test.

/peft-triage approved

BenjaminBossan avatar Oct 05 '26 09:10 BenjaminBossan

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

github-actions[bot] avatar Nov 02 '26 15:11 github-actions[bot]

Hi @BenjaminBossan, I'd like to take the docs part of this since #3892 was closed without merging. Plan: add a forward-looking caveat to the "MoE expert parameters and vLLM" section in docs/source/package_reference/lora.md noting that, at the time of writing, vLLM ignores rank_pattern/alpha_pattern (linking vllm-project/vllm#59801), and recommend keeping r/alpha uniform for experts when serving with vLLM. I'll run make quality before opening the PR. Could you approve with /peft-triage approved shupandee if that works?

shupandee avatar Nov 03 '26 10:11 shupandee

@shupandee My understanding is that it's no longer necessary according to this comment. If I'm misunderstanding, please LMK what exactly is still not working.

BenjaminBossan avatar Nov 04 '26 01:11 BenjaminBossan

Thanks for clarifying, @BenjaminBossan. That makes sense, since the vLLM fix covers it, so I'll drop this one. Appreciate your time!

shupandee avatar Nov 04 '26 04:11 shupandee

All right. I'm closing this issue then. If there is still a gap, please LMK and I can re-open.

BenjaminBossan avatar Nov 04 '26 23:11 BenjaminBossan