RFC: DeepSeek-V4.1 LoRA 训练与 vLLM-Ascend Rollout/推理端到端适配
Mantenedores costumam responder em até 2 dias
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 5/5
- Tempo estimado
- Mais de uma semana
- Facilidade para iniciantes
- 25/100
- Tipo de issue
- Funcionalidade
- Clareza
- Razoavelmente clara
- Status de atividade
- Ativa
- Domínio
- backend, machine-learning
Direção de pesquisa
Start by reading src/twinkle/patch/vllm_lora_weights.py, src/twinkle/patch/vllm_moe_loader.py, and the sampler and Transformers sync paths named in the issue; compare their behavior with the listed vLLM-Ascend LoRA contracts. The Phase 1 work spans several bridges and needs CPU contract tests plus a DeepSeek-V4.1 cookbook. Done means the listed patch, synchronization, and configuration gaps are covered; the RFC leaves design choices for maintainers to confirm.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
背景
Twinkle 当前已具备 DeepSeek-V4 的 DeepseekV4Template、dsv4_sas_li NPU 稀疏算子以及 cookbook/transformers/ep_fsdp2_lora_deepseek_v4.py / ep_fsdp2_multi_lora_deepseek_v4.py(EP + FSDP2 + 3D target_parameters LoRA SFT)基础能力。
随着 DeepSeek-V4.1 架构演进(顶层采用多模态 VL Wrapper AscendDeepseekV41ForCausalLM 挂载 language_model + 冻结 vision./aligner.,语言主干采用 DSA-V4.1 投影 wq_a/wq_b/wkv/wo_a/wo_b 与 2D 路由专家/W4A8 MoE),我们在 Ascend NPU 推理侧已打通 vLLM-Ascend 的 DeepSeek-V4.1 语言主干注意力、共享专家与路由 MoE(含非量化 / W8A8 / per-channel W4A8、2D 与 3D 混合 MoE LoRA 格式、FULL_DECODE_ONLY ACLGraph 与动态热更新)LoRA 推理能力。
本 RFC 旨在梳理并补齐 Twinkle 训练侧(Transformers FSDP2 + EP 单/多 LoRA)⇄ 权重同步(HCCL/SHM/磁盘)⇄ vLLM-Ascend Rollout/推理侧 的端到端适配断点,使 DeepSeek-V4.1 的 SFT、Multi-LoRA 与 RL(GRPO 等)LoRA 训练-推理闭环可在 Ascend NPU 上稳定落地。
现状审计与 5 处核心断点
对照 Twinkle 当前 main 与 vLLM / vLLM-Ascend DeepSeek-V4.1 LoRA 加载契约,定位到 5 处明确断点:
1. src/twinkle/patch/vllm_lora_weights.py 与新版 vLLM / vLLM-Ascend 混合 MoE LoRA 契约漂移
VLLMLoraWeights monkey-patch 了 LRUCacheWorkerLoRAManager._load_adapter,当前实现存在 5 项缺失:
expected_lora_modules构造未保留"experts"(缺少if module == "experts": expected_lora_modules.append(module)),导致 3D 融合 MoE LoRA 键*.experts.lora_{A,B}校验失败;- 仅调用
hf_to_vllm_mapper.get_unstacked_mapper(),未兼容新版WeightsMapper.get_rename_mapper(),导致 DeepSeek-V4.1 依赖的 HF→vLLM 键重映射(.attn.→.self_attn.、.ffn.→.mlp.、.w1/.w2/.w3→.gate_proj/.down_proj/.up_proj及language_model.前缀重根)无法按预期生效; - 漏传模型声明的
skip_prefixes = getattr(model, "lora_skip_prefixes", None)(DeepSeek-V4.1 用于跳过冻结的vision./aligner.前缀)以及moe_ep_spec/unsupported_lora_modules; TensorLoRARequest缺少is_3d_lora_weight字段,且patched_load_adapter加载后未回写lora.is_3d_lora_weight = lora_request.is_3d_lora_weight、未调用_adapter_manager._validate_moe_lora_format(lora);PEFTHelper.from_dict未补充vllm_max_position_embeddings。
直接后果:Twinkle 通过
target_parameters=['mlp.experts.gate_up_proj', 'mlp.experts.down_proj']训练产出的 3D 融合 MoE LoRA(*.mlp.experts.base_layer.lora_{A,B}+*.mlp.experts.lora_{A,B})在推送给 2D 路由专家模型 DeepSeek-V4.1(is_3d_moe_weight = False)时,无法触发enable_mixed_moe_lora_format下的 3D→2D 转换。
2. src/twinkle/patch/vllm_moe_loader.py 未覆盖 DeepSeek-V4 / V4.1 及 VL Wrapper 嵌套层
SUPPORTED_MOE_MODELS目前仅包含DeepseekV2ForCausalLM/DeepseekV3ForCausalLM等模型,缺失 DeepSeek-V4 / DeepSeek-V4.1(含AscendDeepseekV41ForCausalLM/AscendDeepseekV41LLMForCausalLM);- 当顶层为多模态封装(
model.language_model指向*LLMForCausalLM,真实层表在inner_model.model.layers)时,仅对Qwen3MoeLLMForCausalLM做了硬编码解包,DeepSeek-V4.1 走inner_model.layers会抛出AttributeError。
3. src/twinkle/sampler/vllm_sampler/{vllm_worker_extension,vllm_engine}.py 缺少 3D MoE LoRA 透传与 Ascend 启动护栏
- 在线同步路径(
TwinkleWorkerExtension._load_weights):构造TensorLoRARequest时未根据peft_config.get('target_parameters')或 3D 张量 /.experts.base_layer.键自动标记is_3d_lora_weight=True; - 磁盘加载路径(
VLLMEngine._load_lora):构造LoRARequest时未检查adapter_config.json的target_parameters(或权重格式)以自动设置is_3d_lora_weight=True; - Ascend 引擎启动配置(
VLLMEngine._create_engine):缺少对 DeepSeek-V4.1 Ascend LoRA 关键运行契约的透传校验与明确报错提示(详见下节契约表)。
4. src/twinkle/model/transformers/{transformers,multi_lora_transformers}.py LoRA 在线同步缺少 EP AllGather 与 Multi-LoRA target_parameters
TransformersModel.save()已通过_get_adapter_state_dict_for_save()调用NativeFSDPStrategy.get_adapter_state_dict()(内含 EP AllGather)及MultiLora.get_state_dict()(内含TargetParameterLoraManager的 3D 专家权重);- 但
TransformersModel.send_weights(base_sync_done=True, merge_and_sync=False)仍直接调用get_peft_model_state_dict(model, adapter_name=adapter_name):- 在
ep_size > 1下未沿专家维做 EP AllGather,发送的 3D 专家权重仅为本地分片,触发推理侧 shape mismatch; - 在
MultiLoraTransformersModel场景下完全遗漏TargetParameterLoraManager管理的 3D 路由专家 LoRA 权重;
- 在
MultiLora.patch与现有 V4 cookbook 默认仅排除o_a_proj,未涵盖 DeepSeek-V4.1 冻结的视觉/对齐模块(vision、aligner)及受推理侧拓扑约束时可选排除的wo_a。
5. DeepSeek-V4.1 SFT / Multi-LoRA / RL-Rollout 配方与配套边界缺失
cookbook/transformers/尚无 DeepSeek-V4.1 LoRA SFT / Multi-LoRA 及配合vllm-ascend的 GRPO LoRA Rollout 配方;src/twinkle/kernel/ops/dsv4_sas_li/目前绑定transformers.models.deepseek_v4.modeling_deepseek_v4,需要明确 V4.1 在纯 Transformers 路径与定制 NPU 稀疏算子之间的阶段边界。
与 vLLM-Ascend DeepSeek-V4.1 LoRA 推理侧的契约对齐
为确保 Twinkle 产出的 adapter(无论离线磁盘加载还是 RL HCCL/SHM 热同步)与 vLLM-Ascend 推理侧 100% 兼容,训练与 Sampler 侧需共同遵循以下契约:
| 维度 | vLLM-Ascend DeepSeek-V4.1 LoRA 契约 | Twinkle 侧适配动作 |
|---|---|---|
| 目标投影集合 | 语言主干 wq_a / wq_b / wkv / wo_a / wo_b、gate_proj / up_proj / down_proj(含 shared_experts 与路由 experts);vision. 与 aligner. 冻结跳过 |
预设排除 vision、aligner;vllm_lora_weights.py 透传 lora_skip_prefixes 与 get_rename_mapper() |
| MoE LoRA 格式 | 2D 逐专家键(默认)或 3D 融合键(experts.base_layer + experts,需 enable_mixed_moe_lora_format=True 且 is_3d_lora_weight=True) |
自动识别 target_parameters / 3D 张量并透传 is_3d_lora_weight=True;文档与 cookbook 明确开启 enable_mixed_moe_lora_format=True |
| Rank 集合 | --max-lora-rank 需属于 {8, 16, 32, 64} 且 >= r |
配置与 cookbook 校验 rank 范围 |
| 并行拓扑约束 | 路由专家 MoE LoRA 需 data_parallel_size=1(支持 TP 与 TP+EP);EP 下需 additional_config={"enable_fused_mc2": 0}(不支持 MC2/Fused MC2/EPLB);W4A8 TP=8 需开启 EP |
VLLMEngine 在 Ascend NPU + LoRA 场景透传并给出明确前置告警/校验 |
wo_a 拓扑约束 |
wo_a LoRA 要求 n_local_groups == 1、关闭细粒度 o_proj TP 且关闭 --fully-sharded-loras;不满足时推理侧会拒载含 wo_a 的 adapter |
Cookbook 提供 exclude_wo_a 开关,不满足单组约束或开启 fully_sharded_loras 时在训练侧直接排除 wo_a |
| 图模式捕获 | FULL_DECODE_ONLY ACLGraph 需 VLLM_USE_BREAKABLE_CUDAGRAPH=1(默认 "0"),否则退回 --enforce-eager |
Sampler 配方与护栏明确提示/支持配置 |
分阶段实施计划
Phase 1(核心桥接与 CPU 契约闭环 — 首批 PR)
- W1(vLLM LoRA / MoE Patch 对齐):升级
src/twinkle/patch/vllm_lora_weights.py与src/twinkle/patch/vllm_moe_loader.py,补齐"experts"、get_rename_mapper()、skip_prefixes、moe_ep_spec、unsupported_lora_modules、is_3d_lora_weight回写与_validate_moe_lora_format校验,以及 DeepSeek-V4/V4.1 VL Wrapper 通用解包(保持旧版 vLLM 向后兼容)。 - W2(Sampler 3D LoRA 自动探测与 Ascend 护栏):更新
vllm_worker_extension.py与vllm_engine.py,统一在线TensorLoRARequest与磁盘LoRARequest的is_3d_lora_weight自动推断与透传,补充 Ascend MoE LoRA 启动约束检查辅助逻辑。 - W3(EP-aware & Multi-LoRA
send_weights修复 + DSv4.1 Cookbook):修复TransformersModel/MultiLoraTransformersModelLoRA-onlysend_weights在 EP /target_parameters场景下的权重收集与同步;新增 DeepSeek-V4.1 EP+FSDP2 LoRA SFT / Multi-LoRA Cookbook(含与 vLLM-Ascend 推理对齐的 exclude/rank/3D 配置)。 - W4(离线 CPU 契约单测):新增聚焦单测覆盖上述全部 4 处桥接逻辑(含未修复失败 → 修复通过回归验证),无 GPU/NPU 依赖即可在 CI 运行。
Phase 2(Ascend A3 多卡实测与算子/RL 扩展)
- W5(A3 实机端到端验证):在 Ascend A3 8/16 卡环境打通 DeepSeek-V4.1 EP+FSDP2 LoRA SFT 与 GRPO + vLLM-Ascend LoRA(2D/3D)在线权重同步,验证 base vs zero-adapter vs trained-adapter 输出一致性与无 unmatched key 告警。
- W6(NPU 稀疏算子与多模态模板按需扩展):视上游
transformers中 DeepSeek-V4.1 建模实现定型情况,评估dsv4_sas_li稀疏注意力内核及多模态图像 span 在DeepseekV4Template中的复用或扩展。
不在 Phase 1 范围内
- 视觉塔(
vision.)与对齐层(aligner.)的 LoRA 训练(当前与 vLLM-Ascend 推理侧保持一致,默认冻结); - 修改外部
vllm/vllm-ascend源码或引入新的 C++/ACLNN 算子编译依赖; data_parallel_size > 1下的路由专家 MoE LoRA 热加载(受限于推理侧跨 DP 专家驻留约束)。
希望维护者确认的问题
- 3D MoE LoRA 自动推断策略:在
VLLMEngine._load_lora与TwinkleWorkerExtension._load_weights中,通过peft_config['target_parameters'](含experts)或 3D 权重张量自动设置is_3d_lora_weight=True(同时允许显式覆盖),是否符合 Twinkle 的设计预期? - LoRA-only
send_weights复用策略:让TransformersModel.send_weights(base_sync_done=True, merge_and_sync=False)与MultiLoraTransformersModel复用_get_adapter_state_dict_for_save()的 EP AllGather 与TargetParameterLoraManager导出逻辑,还是希望单独抽取_get_adapter_state_dict_for_sync()? - Cookbook 组织方式:DeepSeek-V4.1 的 EP+FSDP2 LoRA 配方是否建议在
cookbook/transformers/下独立新增ep_fsdp2_lora_deepseek_v41.py(与现有ep_fsdp2_lora_deepseek_v4.py并列),避免影响现有 V4 用户脚本? - Ascend LoRA 启动校验级别:当检测到 Ascend NPU + LoRA 配置存在潜在冲突(如未传
enable_mixed_moe_lora_format却加载 3D MoE LoRA,或 EP 下未关闭enable_fused_mc2)时,更倾向于发出明确WARNING并在明确非法组合(如DP > 1+ routed-expert target)上 fail-fast,还是完全交由底层 vLLM-Ascend 报错?
- Linguagem predominante
- Python
- Estrelas
- 270
- Forks
- 68
- Merge médio
- 2d 16h
- PRs com merge (30d)
- 38
Preparar o ambiente
- Inclui um Dockerfile ou arquivo Docker Compose
- Tem um modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de modelscope/twinkle
-
bug
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 22/100
modelscope/twinkle#411 · 1 comentário ·
Mantenedores costumam responder em até 2 dias
-
bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 55/100
modelscope/twinkle#410 ·
Mantenedores costumam responder em até 2 dias
-
bug
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 55/100
modelscope/twinkle#408 ·
Mantenedores costumam responder em até 2 dias
-
bug
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 66/100
modelscope/twinkle#407 ·
Mantenedores costumam responder em até 2 dias
-
魔搭托管的 Twinkle API 持续超时Abertabug
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 15/100
modelscope/twinkle#319 · 5 comentários ·
Mantenedores costumam responder em até 2 dias
Todas as issues de modelscope/twinkle
Issues semelhantes
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
Mantenedores costumam responder em até 1 dia
-
AIR-Bench Foundation reads the first letter of the word after "answer" as the model's choiceTalvez já em andamento @beartester34 assumiu hoje. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 84/100
modelscope/evalscope#2330 ·
Mantenedores costumam responder em até 1 dia
-
Distribution plot crashes when a numeric feature is constant in the train or test setTalvez já em andamento @adembilge assumiu hoje. Abertabug good first issue
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
MAIF/shapash#847 · 1 comentário ·
Mantenedores costumam responder em até 10 dias
-
Dificuldade 1/5 1-3 horas Facilidade para iniciantes 85/100
Mantenedores costumam responder em até 2 dias
-
namespace team:operations
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 60/100
EclipseFdn/open-vsx.org#16738 ·
Mantenedores costumam responder em até 1 dia