已开启
matmul_dequant_pipeline #436
liuweiqi创建于 20 天前
matmul_dequant_pipeline #436
已开启
liuweiqi创建于 20 天前
liuweiqi
liuweiqi
20 天前

当前PR是否有AI参与:

[x] 否

__1. AI Agent 平台:
__2. AI 模型:
__3. Prompt上下文 :

参考:openEuler社区《生成式AI工具使用与开源贡献政策》

PR功能描述 / 为什么需要这个合入**:

 进行反量化算子和前序matmul算子的融合,通过流水线的形式进行优化

该PR关联的issue

(格式为fixes #<issue号>, 或者resolves #<issue号>): fixes #

希望检视人员了解:

likedislike
合并受阻
liuweiqiliuweiqi
20 天前 创建了 pull request,commit 98638704
atomgit-bot
atomgit-bot
20 天前 评论:

变更摘要

本 PR 新增了一个将 INT8 Matmul 与反量化(dequant)融合到单个 MIX 内核的流水线算子 fusion_operator_matmul_dequant_pipeline,用于在 AIC 完成矩阵乘 tile 写回 GM 后立即通过 AIC↔AIV 跨核同步信号触发 AIV 执行 FP16→FP32→BF16 的 tile 级反量化,替代原先「先 matmul_dequant 写 FP16、再 dequant 转 BF16」的串行路径。改动涵盖新增内核实现与实例化文件、Python 绑定与 .pyi 声明、XliteOpFusionOperatorMatmulDequantPipeline 启动逻辑、ForwardLinear 中的融合调用分支,以及通过环境变量 XLITE_FUSED_DENSE_W8A8 控制的开关,并补充了对应正确性测试。

主要改动

  • 新增融合内核实现:新增 fusion_operator_matmul_dequant_pipeline.h,定义 FusionMatmulDequantPipeline 类及 FusionOperatorMatmulDequantPipelineRun 入口,通过 FUSION_MATMUL_DQ_* 同步标志实现 AIC 与 AIV 的 ping-pong 跨核同步,AIC 侧沿用 matmul 的 tiling/copy/mmad/fixpipe 结构,AIV 侧执行 FusionDequantTileFp16ToBf16 完成 FP16→FP32→BF16 转换。
  • 新增内核实例化与导出:新增 fusion_operator_matmul_dequant_pipeline_bfloat16_t.cpp,通过宏 FUSION_OPERATOR_MATMUL_DEQUANT_PIPELINE_FUNC_DEFINE 生成 fusion_operator_matmul_dequant_pipeline_bfloat16_t 内核入口。
  • 新增 Python 绑定与类型声明:在 _C.cpp 中新增 FusionOperatorMatmulDequantPipeline 并注册为 fusion_operator_matmul_dequant_pipeline,在 xlite/_C.pyi 中补充对应函数签名与说明。
  • 新增算子启动逻辑:在 op.cpp/op.h 中新增 XliteOpFusionOperatorMatmulDequantPipeline,负责输入形状/数据类型校验、tiling 参数计算与 swizzle 选择,并通过 aclrtlaunch_fusion_operator_matmul_dequant_pipeline_bfloat16_t 启动内核,输出视图在 FP16 与 BF16 间切换。
  • 接入 ForwardLinear 与运行开关:在 model.cppXModel::ForwardLinear 中新增 DYNAMIC_QUANT/STATIC_QUANT 场景下的融合分支;runtime.h/runtime.cpp 新增 enableFusedDenseW8A8 字段并支持通过环境变量 XLITE_FUSED_DENSE_W8A8 开启。
likedislike
openeuler-ci-botopeneuler-ci-bot成员
20 天前 将juntianlinux,sinever,luanjianhai设为审查人
atomgit-bot
atomgit-bot
20 天前 评论:

代码审查

✅ 未发现问题

likedislike
openeuler-ci-botopeneuler-ci-bot成员
20 天前 添加了label:sig/sig-Long
此处折叠了57条消息 查看更多
lulina1lulina1成员
3 天前 设置为草稿状态
lulina1lulina1成员
3 天前 修改标题为 “[WIP] matmul_dequant_pipeline”,原标题为“matmul_dequant_pipeline”
lulina1lulina1成员
2 天前 取消了草稿状态
lulina1lulina1成员
2 天前 修改标题为 “matmul_dequant_pipeline”,原标题为“[WIP] matmul_dequant_pipeline”
ci bot
2 天前 评论:

CI Test Results

1. GVirt/xlite Static Check

Status: Passed

Check Results:

  • C++: Passed
  • Python: Passed
Click to see detailed output
Checking 154 C++ files...
Building project to generate operator header files...
Generating compile_commands.json...
  Checking csrc/_C.cpp
  Checking csrc/ascend.h
  Checking csrc/auto_tuner.cpp
  Checking csrc/auto_tuner.h
  Checking csrc/base.cpp
  Checking csrc/base.h
  Checking csrc/ccl.cpp
  Checking csrc/ccl.h
  Checking csrc/core_assigner.cpp
  Checking csrc/core_assigner.h
  Checking csrc/debug.cpp
  Checking csrc/debug.h
  Checking csrc/kernels/add.h
  Checking csrc/kernels/add_bfloat16_t.cpp
  Checking csrc/kernels/add_bias.h
  Checking csrc/kernels/add_bias_bfloat16_t.cpp
  Checking csrc/kernels/add_bias_float.cpp
  Checking csrc/kernels/add_bias_float16_t.cpp
  Checking csrc/kernels/add_float16_t.cpp
  Checking csrc/kernels/all_gather.cpp
  Checking csrc/kernels/all_reduce.cpp
  Checking csrc/kernels/attention.h
  Checking csrc/kernels/attention_bfloat16_t.cpp
  Checking csrc/kernels/attention_float16_t.cpp
  Checking csrc/kernels/beta_decay.h
  Checking csrc/kernels/beta_decay_bfloat16_t.cpp
  Checking csrc/kernels/beta_decay_float.cpp
  Checking csrc/kernels/beta_decay_float16_t.cpp
  Checking csrc/kernels/cast.h
  Checking csrc/kernels/cast_bfloat16_t_float.cpp
  Checking csrc/kernels/cast_float_bfloat16_t.cpp
  Checking csrc/kernels/cce_stub.h
  Checking csrc/kernels/concat.cpp
  Checking csrc/kernels/config_macro.h
  Checking csrc/kernels/conv1d_and_silu.h
  Checking csrc/kernels/conv1d_and_silu_bfloat16_t.cpp
  Checking csrc/kernels/conv1d_and_silu_float.cpp
  Checking csrc/kernels/conv1d_and_silu_float16_t.cpp
  Checking csrc/kernels/debug.h
  Checking csrc/kernels/dequant.h
  Checking csrc/kernels/dequant_float16_t.cpp
  Checking csrc/kernels/einsum_mht_hdt_mhd.h
  Checking csrc/kernels/einsum_mht_hdt_mhd_bfloat16_t.cpp
  Checking csrc/kernels/einsum_mht_hdt_mhd_float16_t.cpp
  Checking csrc/kernels/einsum_mht_htd_mhd.h
  Checking csrc/kernels/einsum_mht_htd_mhd_bfloat16_t.cpp
  Checking csrc/kernels/einsum_mht_htd_mhd_float16_t.cpp
  Checking csrc/kernels/embed_kernel.h
  Checking csrc/kernels/embed_kernel_bfloat16_t.cpp
  Checking csrc/kernels/embed_kernel_float16_t.cpp
  Checking csrc/kernels/experts_counts_sum.cpp
  Checking csrc/kernels/flash_attention.h
  Checking csrc/kernels/flash_attention_bfloat16_t.cpp
  Checking csrc/kernels/flash_attention_float16_t.cpp
  Checking csrc/kernels/flash_mla_v2.h
  Checking csrc/kernels/flash_mla_v2_bfloat16_t.cpp
  Checking csrc/kernels/fusion_operator_matmul_dequant_pipeline.h
  Checking csrc/kernels/fusion_operator_matmul_dequant_pipeline_bfloat16_t.cpp
  Checking csrc/kernels/gather_sparse_kv_cache.h
  Checking csrc/kernels/gather_sparse_kv_cache_bfloat16_t.cpp
  Checking csrc/kernels/group_matmul.h
  Checking csrc/kernels/group_matmul_bfloat16_t.cpp
  Checking csrc/kernels/group_matmul_float.cpp
  Checking csrc/kernels/group_matmul_float16_t.cpp
  Checking csrc/kernels/group_matmul_int8_t.cpp
  Checking csrc/kernels/indexer_prepare.h
  Checking csrc/kernels/indexer_prepare_bfloat16_t.cpp
  Checking csrc/kernels/indexer_prepare_float16_t.cpp
  Checking csrc/kernels/indexer_scores.h
  Checking csrc/kernels/indexer_scores_bfloat16_t.cpp
  Checking csrc/kernels/indexer_scores_float16_t.cpp
  Checking csrc/kernels/indexer_topk.h
  Checking csrc/kernels/indexer_topk_bfloat16_t.cpp
  Checking csrc/kernels/indexer_topk_float16_t.cpp
  Checking csrc/kernels/kernel_macro.h
  Checking csrc/kernels/kernel_param.h
  Checking csrc/kernels/matmul.h
  Checking csrc/kernels/matmul_bfloat16_t.cpp
  Checking csrc/kernels/matmul_float.cpp
  Checking csrc/kernels/matmul_float16_t.cpp
  Checking csrc/kernels/matmul_int4b_t.cpp
  Checking csrc/kernels/matmul_int8_t.cpp
  Checking csrc/kernels/mla_prepare.h
  Checking csrc/kernels/mla_prepare_bfloat16_t.cpp
  Checking csrc/kernels/mla_prepare_float16_t.cpp
  Checking csrc/kernels/mla_v2.h
  Checking csrc/kernels/mla_v2_bfloat16_t.cpp
  Checking csrc/kernels/mla_v3.h
  Checking csrc/kernels/mla_v3_bfloat16_t.cpp
  Checking csrc/kernels/msd_merge_dequant.h
  Checking csrc/kernels/msd_merge_dequant_int8_t.cpp
  Checking csrc/kernels/muls.h
  Checking csrc/kernels/muls_bfloat16_t.cpp
  Checking csrc/kernels/muls_float16_t.cpp
  Checking csrc/kernels/norm.h
  Checking csrc/kernels/norm_bfloat16_t.cpp
  Checking csrc/kernels/norm_float16_t.cpp
  Checking csrc/kernels/permutation.cpp
  Checking csrc/kernels/qk_rms_norm.h
  Checking csrc/kernels/qk_rms_norm_bfloat16_t.cpp
  Checking csrc/kernels/qk_rms_norm_float16_t.cpp
  Checking csrc/kernels/quant.h
  Checking csrc/kernels/quant_bfloat16_t.cpp
  Checking csrc/kernels/quant_dyn.h
  Checking csrc/kernels/quant_dyn_bfloat16_t.cpp
  Checking csrc/kernels/recurrent_gated_delta_rule.h
  Checking csrc/kernels/recurrent_gated_delta_rule_bfloat16_t.cpp
  Checking csrc/kernels/recurrent_gated_delta_rule_float.cpp
  Checking csrc/kernels/recurrent_gated_delta_rule_float16_t.cpp
  Checking csrc/kernels/reduce_scatter.cpp
  Checking csrc/kernels/reorder_moe.cpp
  Checking csrc/kernels/rope_and_cache.h
  Checking csrc/kernels/rope_and_cache_bfloat16_t.cpp
  Checking csrc/kernels/rope_and_cache_float16_t.cpp
  Checking csrc/kernels/rope_complex_and_cache.h
  Checking csrc/kernels/rope_complex_and_cache_bfloat16_t.cpp
  Checking csrc/kernels/rope_complex_and_cache_float16_t.cpp
  Checking csrc/kernels/sigmoid_gate_mul.h
  Checking csrc/kernels/sigmoid_gate_mul_bfloat16_t.cpp
  Checking csrc/kernels/sigmoid_gate_mul_float16_t.cpp
  Checking csrc/kernels/sigmoid_topk.h
  Checking csrc/kernels/sigmoid_topk_bfloat16_t.cpp
  Checking csrc/kernels/sigmoid_topk_float.cpp
  Checking csrc/kernels/silu_and_mul.h
  Checking csrc/kernels/silu_and_mul_bfloat16_t.cpp
  Checking csrc/kernels/silu_and_mul_float.cpp
  Checking csrc/kernels/silu_and_mul_float16_t.cpp
  Checking csrc/kernels/softmax.cpp
  Checking csrc/kernels/softmax_attn_aiv.h
  Checking csrc/kernels/softmax_topk.h
  Checking csrc/kernels/softmax_topk_bfloat16_t.cpp
  Checking csrc/kernels/softmax_topk_float.cpp
  Checking csrc/kernels/split.cpp
  Checking csrc/kernels/topk.h
  Checking csrc/kernels/topk_bfloat16_t.cpp
  Checking csrc/kernels/topk_float.cpp
  Checking csrc/kernels/transpose_1_2.h
  Checking csrc/kernels/transpose_1_2_bfloat16_t.cpp
  Checking csrc/kernels/transpose_1_2_float16_t.cpp
  Checking csrc/kernels/unpack_activation.h
  Checking csrc/kernels/unpack_activation_int8_t.cpp
  Checking csrc/kernels/unpermutation.h
  Checking csrc/kernels/unpermutation_bfloat16_t.cpp
  Checking csrc/kernels/unpermutation_float.cpp
  Checking csrc/model.cpp
  Checking csrc/model.h
  Checking csrc/op.cpp
  Checking csrc/op.h
  Checking csrc/runtime.cpp
  Checking csrc/runtime.h
  Checking csrc/sock.cpp
  Checking csrc/sock.h
  Checking csrc/swizzle.cpp
  Checking csrc/swizzle.h

✅ All C++ checks passed!
Checking 3 Python files...
  Checking xlite/__init__.py
  Checking xlite/tools/__init__.py
  Checking xlite/tools/fp8_cast_bf16.py
Running flake8...
Running mypy...

✅ All Python checks passed!

============================================================
xlite Static Checker
============================================================

============================================================
Running C++ Static Checks
============================================================


============================================================
Running Python Static Checks
============================================================


============================================================
Summary
============================================================
  CPP       : ✅ PASSED
  PYTHON    : ✅ PASSED

✅ All checks passed!

2. vllm-ascend Static Check

Status: Passed

Click to see detailed output
Success: no issues found in 1 source file

3. UT Test

Status: Passed

Click to see detailed output
Running accuracy test for qwen3_0.6B...
(R0) Euler Xlite Model Inited! [tensor paralled(1), data parallel(1), expert parallel(1)]
Qwen3ModelArgs(max_batch_size=4, max_seq_len=1024, dim=1024, head_dim=128, inter_dim=3072, vocab_size=151936, n_layers=28, n_heads=16, n_kv_heads=8, norm_eps=1e-06, rope_theta=1000000.0, dtype='bfloat16', tie_word_embeddings=True, qkv_bias=False, qk_norm=True, model_type='qwen3')
Memory usage: Model: 1433 MB KV Cache: 448 MB Tensor pool: 104 MB
start to run
Query: Hello, my name is
Completion:  Lina. I'm a 22-year-old student from China. I'm interested in studying in the US. I'm looking for a job in the
Query: The president of the United States is
Completion:  the same as the president of the United Nations. This is because the president of the United States is the same as the president of the United Nations. The president
Query: The capital of France is
Completion:  Paris. The capital of Italy is Rome. The capital of Spain is Madrid. The capital of China is Beijing. The capital of Japan is Tokyo. The capital
Query: The future of AI is
Completion:  not just a technological challenge but a profound transformation of how we live, work, and interact with the world. As we stand at the intersection of artificial intelligence and
generate 146 tokens take 392.36 ms. avg: 372.10 tokens/s @ 11.54 ms bs: 4
The results have been written into the input_file.

========================================
Accuracy Test Results
========================================
✓ Test 0 PASSED
✓ Test 1 PASSED
✓ Test 2 PASSED
✓ Test 3 PASSED

========================================
Summary: 4 passed, 0 failed out of 4 tests
========================================
All accuracy tests PASSED!


This comment was automatically generated by CI bot

likedislike