Skip to content

issue/1569 - 为 NVIDIA 后端增加可复用的 GGUF 线性层与 BlockFP8 支持 - #1570

Open
xindongliu594 wants to merge 4 commits into
InfiniTensor:InfiniLM-v0.2.9cfrom
xindongliu594:issue/1569/gguf-routeb-v029c
Open

xindongliu594 wants to merge 4 commits into
InfiniTensor:InfiniLM-v0.2.9cfrom
xindongliu594:issue/1569/gguf-routeb-v029c

Conversation

@xindongliu594

Copy link
Copy Markdown

关联 Issue

Closes #1569

概要

  • 为 NVIDIA 后端增加可复用的 GGUF linear_gguf 算子,支持 Q8_0Q4_KQ5_KQ6_K
  • 增加当前 InfiniLM Route B 所需的可复用 BlockFP8 线性算子。
  • 补齐 C ABI、InfiniCore C++ API、Python binding、算子注册、shape/dtype/workspace 校验与官方测试入口。
  • 为 decode/small batch 提供 register-resident GEMV,为 prefill 提供分块解量化 + cuBLAS GEMM,并加入已验证的 Q6_K prefill 解量化优化。
  • 不修改现有 dense GEMM、attention、scheduler 或非 GGUF 默认执行路径。

动机

InfiniLM 的 Qwen3.5 / Qwen3-Next GGUF Route B 需要直接执行 GGML block-quantized 权重。若把解量化和矩阵计算分别写入模型代码,会造成重复实现,也无法被其他 GGUF 模型复用。

本 PR 将能力下沉为通用算子:InfiniCore 负责 block layout、校验、workspace 和 NVIDIA kernel;InfiniLM 只负责模型权重映射、融合关系和少量模型特有重排。

主要变更

  • linear_gguf
    • 支持 Q8_0 / Q4_K / Q5_K / Q6_K block layout;
    • small-M register GEMV;
    • large-M tile dequantization + cuBLAS GEMM;
    • BF16/FP32 输出、workspace 查询与非法类型/布局拒绝。
  • block_fp8_linear
    • 增加 NVIDIA SM120 实现、C/C++/Python API 和 workspace 校验;
    • 修正 activation scale layout,使其与生成器的 row-major 布局一致。
  • 工程与测试
    • 将新算子加入公共头文件、构建系统和 scripts/python_test.py
    • 增加 test/infiniop/linear_gguf.pytest/infiniop/block_fp8_linear.py
    • 补充 llama.cpp/ggml 数值公式来源、固定参考提交及 MIT 许可证归属。

测试结果

项目 环境 结果
完整构建与链接 RTX 5090 / CUDA 13.0 / SM120 PASS,CORE_LINK_BUILT
ldd -r 与隔离 Python import 同上 PASS,无缺失库或未解析符号
linear_gguf 官方测试 4 种量化 × M=1/8/17 PASS,12 个正例 + 2 个负例
block_fp8_linear 官方测试 3 组形状 + workspace 负例 PASS
MHA varlen NVIDIA 回归 FP16/BF16、paged prefill、GQA、Dense MLA PASS,22/22,exit 0
Qwen3.5 27B GGUF 整模型烟雾测试 InfiniLM v0.2.9c PASS,exit 0
最终归属补丁后的格式与算子复测 commit c3440e6d PASS,全部 exit 0

最终测试截图

性能影响

同一 RTX 5090、同一 Qwen3.5/Qwen3-Next 27B Q6_K GGUF、相同配置与 warmup,三次测量取中位数:

场景 原 correctness-first 路径 本 PR 变化
64-token prefill TTFT 6088.06 ms 926.65 ms 约 6.57x
256-token prefill TTFT 6254.61 ms 1282.13 ms 约 4.88x
512-token prefill TTFT 8545.82 ms 3699.01 ms 约 2.31x
128-token decode throughput 6.10 tok/s 6.46 tok/s 基本持平;decode kernel 未修改

测试按“新实现后旧实现”顺序执行,并非随机交替试验;decode 的约 6% 差异不归因于本 PR。当前性能仍低于 llama.cpp,本 PR 不宣称达到 llama.cpp 水平。

兼容性与范围

  • 仅为新增 GGUF/BlockFP8 路径增加实现与注册,现有算子默认行为不变。
  • 当前 GGUF kernel 仅实现 NVIDIA 后端;其他平台会返回不支持,不会静默降级为错误结果。
  • FlashAttention 构建与整模型测试仅作为兼容性验证,不改变默认 attention 分派。

Review 建议

建议重点检查:

  1. GGML block layout、padding 与 BF16 round-to-nearest-even;
  2. Q6_K prefill tile 解量化和 cuBLAS math-mode 恢复;
  3. BlockFP8 activation scale layout;
  4. C ABI / C++ API / Python binding 的一致性;
  5. llama.cpp/ggml MIT 归属与许可证文件。
infinicore_pr_test_evidence

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.

1 participant