[XPU] support yiyan model w4a8C8/C16+TP4EP4/PD disaggregation+skip layer mix quant #7208
[XPU] support yiyan model w4a8C8/C16+TP4EP4/PD disaggregation+skip layer mix quant #7208zccjjj wants to merge 3 commits intoPaddlePaddle:developfrom
Conversation
|
Thanks for your contribution! |
fastdeploy-bot
left a comment
There was a problem hiding this comment.
🤖 AI Code Review |
2026-04-07 15:23 CST
📋 Review 摘要
PR 概述:为 XPU 平台添加 yiyan 模型支持,包括 w4a8C8/C16 量化、TP4EP4 并行、PD disaggregation 以及 skip layer mix quant 功能
变更范围:主要涉及 model_executor/layers/backends/xpu/、model_executor/layers/quantization/、engine/sched/resource_manager_v1.py 以及多个 MoE 模型文件
影响面 Tag:XPU Quantization Scheduler PD Disaggregation Models
📝 PR 规范检查
PR 描述中的 Motivation 和 Modifications 部分未填写具体内容,建议补充说明本次变更的目的和具体修改点。
描述模板(可直接复制):
## Motivation
为 XPU 平台支持 yiyan 模型的多种量化配置(w4a8C8/C16)和并行策略(TP4EP4),
同时支持 PD disaggregation 场景下的 preallocated blocks 管理和 skip layer mix quant 功能。
## Modifications
1. `resource_manager_v1.py`: 新增 `preallocated_blocks` 属性管理,支持 PD disaggregation 场景
2. `kv_cache.py`: 添加 XPU 平台的 KV Cache C8 量化支持,包括 TP 分片的自定义 weight_loader
3. `attention.py`: 修复 `cache_k_zp`/`cache_v_zp` 获取时的对象引用错误
4. `moe.py`: 添加 `prefix` 参数支持 skip layer mix quant
5. `weight_only.py`: 简化 `is_checkpoint_bf16` 参数,统一为动态量化模式
6. 多个模型文件: 为 FusedMoE 层添加 `prefix` 参数传递问题
| 级别 | 文件 | 概述 |
|---|---|---|
| 🟡 建议 | kv_cache.py:268 |
使用环境变量硬编码控制 C8 模式 |
| 🟡 建议 | kv_cache.py:167 |
scale 计算可能存在除零风险 |
| 🟡 建议 | kv_cache.py:163 |
TP 分片计算未考虑不整除情况 |
总体评价
本 PR 实现了 XPU 平台对 yiyan 模型的多种量化和并行策略支持,代码结构合理。attention.py 中的 bug 修复是正确的(将 getattr(self, ...) 改为 getattr(layer, ...))。建议关注 kv_cache.py 中的环境变量使用方式和边界条件处理。
fastdeploy/model_executor/layers/backends/xpu/quantization/kv_cache.py
Outdated
Show resolved
Hide resolved
fastdeploy/model_executor/layers/backends/xpu/quantization/kv_cache.py
Outdated
Show resolved
Hide resolved
…ixes Squashed from 6 feature commits + 2 compatibility fix commits: - support w4a8(Decode) - support C8 KV cache quantization - support C8+TP4EP4 - bugfix C8 - bugfix pd+C8 - bugfix pd+mtp - fix: make weight_need_transpose conditional and remove hardcoded layer_id - fix: comprehensive compatibility fixes (Iluvatar platform, moe cast bug, mutable default, hardcoded magic number, unconditional XPU import, etc.)
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #7208 +/- ##
==========================================
Coverage ? 73.14%
==========================================
Files ? 376
Lines ? 53044
Branches ? 8285
==========================================
Hits ? 38798
Misses ? 11510
Partials ? 2736
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Motivation
为 XPU 平台支持 yiyan 模型的多种量化配置(w4a8C8/C16)和并行策略(TP4EP4),
同时支持 PD disaggregation 场景下的 preallocated blocks 管理和 skip layer mix quant 功能。
Modifications
resource_manager_v1.py: 新增preallocated_blocks属性管理,支持 PD disaggregation 场景kv_cache.py: 添加 XPU 平台的 KV Cache C8 量化支持,包括 TP 分片的自定义 weight_loaderattention.py: 修复cache_k_zp/cache_v_zp获取时的对象引用错误moe.py: 添加prefix参数支持 skip layer mix quantweight_only.py: 简化is_checkpoint_bf16参数,统一为动态量化模式prefix参数传递Usage or Command
Accuracy Tests
simpleqa_cn_judgeby_g4o_20240806和zebralogic_gen存在明显精度下降,定位发现PD分离模式下存在一个循环生成的case:
curl -X POST "http://0.0.0.0:8188/v1/chat/completions" -H "Content-Type: application/json" -d '{
"messages": [
{"role": "user", "content": "There are 6 houses, numbered 1 to 6 from left to right, as seen from across the street. Each house is occupied by a different person. Each house has a unique attribute for each of the following characteristics:\n - Each person has a unique name:
Bob,Eric,Peter,Carol,Alice,Arnold\n - People have unique favorite music genres:rock,classical,pop,hip hop,jazz,country\n\n## Clues:\n1. Alice is somewhere to the right of the person who loves classical music.\n2. The person who loves pop music is directly left of the person who loves classical music.\n3. Bob is in the fourth house.\n4. The person who loves country music is Bob.\n5. The person who loves hip-hop music is Peter.\n6. Carol is somewhere to the right of the person who loves jazz music.\n7. Peter is directly left of Eric.\n\n\nPlease solve this logic puzzle. Fill in the solution table with columns: House, Name, MusicGenre. Show your reasoning step by step."}]
}'
Checklist
[FDConfig],[APIServer],[Engine],[Scheduler],[PD Disaggregation],[Executor],[Graph Optimization],[Speculative Decoding],[RL],[Models],[Quantization],[Loader],[OP],[KVCache],[DataProcessor],[BugFix],[Docs],[CI],[Optimization],[Feature],[Benchmark],[Others],[XPU],[HPU],[GCU],[DCU],[Iluvatar],[Metax]]pre-commitbefore commit.releasebranch, make sure the PR has been submitted to thedevelopbranch, then cherry-pick it to thereleasebranch with the[Cherry-Pick]PR tag.