[Feature] Enable LoRA adapter injection for BAGEL (#2490)
Signed-off-by: Zhengyuan Su <su.zhengyuan@u.nus.edu> Signed-off-by: Claude <noreply@anthropic.com> Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
1 parent
328de586aa
commit
486d77d797
6 files changed
+392
-31
No files matched your search
@@ -929,17 +929,31 @@ class Qwen2MoTForCausalLM(Qwen2PreTrainedModel):
|
||||
(".qkv_proj", ".q_proj", "q"),
|
||||
(".qkv_proj", ".k_proj", "k"),
|
||||
(".qkv_proj", ".v_proj", "v"),
|
||||
# MLP gate/up projections — the DiT uses separate
|
||||
# ColumnParallelLinear layers (no fused gate_up_proj), but
|
||||
# these entries are needed so that DiffusionLoRAManager can
|
||||
# derive the packed→sublayer mapping for LoRA checkpoints
|
||||
# that store weights under fused gate_up_proj keys.
|
||||
# The weight loader gracefully falls through to the
|
||||
# non-stacked path when the fused parameter doesn't exist.
|
||||
(".gate_up_proj", ".gate_proj", 0),
|
||||
(".gate_up_proj", ".up_proj", 1),
|
||||
]
|
||||
self.stacked_params_mapping = stacked_params_mapping
|
||||
params_dict = dict(self.named_parameters())
|
||||
loaded_params: set[str] = set()
|
||||
|
||||
for name, loaded_weight in weights:
|
||||
original_name = name
|
||||
for param_name, weight_name, shard_id in stacked_params_mapping:
|
||||
if weight_name not in name:
|
||||
continue
|
||||
name = name.replace(weight_name, param_name)
|
||||
param = params_dict.get(name)
|
||||
if param is None:
|
||||
# Fused param doesn't exist (e.g. gate_up_proj on DiT);
|
||||
# restore original name and fall through to non-stacked path.
|
||||
name = original_name
|
||||
break
|
||||
weight_loader = getattr(param, "weight_loader", default_weight_loader)
|
||||
weight_loader(param, loaded_weight, shard_id)
|
||||
|
||||
Reference in new issue
Block a user