Skip to content

[XPU] support yiyan model w4a8C8/C16+TP4EP4/PD disaggregation+skip layer mix quant #7208

Open
zccjjj wants to merge 3 commits intoPaddlePaddle:developfrom
zccjjj:refactor-pr
Open

[XPU] support yiyan model w4a8C8/C16+TP4EP4/PD disaggregation+skip layer mix quant #7208
zccjjj wants to merge 3 commits intoPaddlePaddle:developfrom
zccjjj:refactor-pr

Conversation

@zccjjj
Copy link
Copy Markdown
Contributor

@zccjjj zccjjj commented Apr 7, 2026

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 参数传递

Usage or Command

Accuracy Tests

image

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

  • Add at least a tag in the PR title.
    • Tag list: [[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]]
    • You can add new tags based on the PR content, but the semantics must be clear.
  • Format your code, run pre-commit before commit.
  • Add unit tests. Please write the reason in this PR if no unit tests.
  • Provide accuracy results.
  • If the current PR is submitting to the release branch, make sure the PR has been submitted to the develop branch, then cherry-pick it to the release branch with the [Cherry-Pick] PR tag.

@paddle-bot
Copy link
Copy Markdown

paddle-bot bot commented Apr 7, 2026

Thanks for your contribution!

Copy link
Copy Markdown

@fastdeploy-bot fastdeploy-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 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 模型文件

影响面 TagXPU Quantization Scheduler PD Disaggregation Models

📝 PR 规范检查

PR 描述中的 MotivationModifications 部分未填写具体内容,建议补充说明本次变更的目的和具体修改点。

描述模板(可直接复制):

## 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 中的环境变量使用方式和边界条件处理。

bukejiyu and others added 3 commits April 7, 2026 15:59
…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-commenter
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 64.18919% with 53 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (develop@ae2f9f4). Learn more about missing BASE report.

Files with missing lines Patch % Lines
fastdeploy/model_executor/utils.py 63.07% 17 Missing and 7 partials ⚠️
fastdeploy/model_executor/layers/moe/moe.py 26.08% 13 Missing and 4 partials ⚠️
...el_executor/layers/moe/fused_moe_triton_backend.py 55.55% 1 Missing and 3 partials ⚠️
fastdeploy/engine/sched/resource_manager_v1.py 88.00% 0 Missing and 3 partials ⚠️
...loy/model_executor/layers/quantization/__init__.py 25.00% 2 Missing and 1 partial ⚠️
...l_executor/layers/moe/fused_moe_cutlass_backend.py 88.88% 0 Missing and 1 partial ⚠️
.../model_executor/layers/quantization/weight_only.py 90.90% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             develop    #7208   +/-   ##
==========================================
  Coverage           ?   73.14%           
==========================================
  Files              ?      376           
  Lines              ?    53044           
  Branches           ?     8285           
==========================================
  Hits               ?    38798           
  Misses             ?    11510           
  Partials           ?     2736           
Flag Coverage Δ
GPU 73.14% <64.18%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants