Skip to content

feat(nvidia): 为 v0.2.9c 增加可复用的 GGUF Route B 支持 - #589

Open
xindongliu594 wants to merge 7 commits into
InfiniTensor:InfiniLM-v0.2.9cfrom
xindongliu594:feat/gguf-routeb-v029c
Open

xindongliu594 wants to merge 7 commits into
InfiniTensor:InfiniLM-v0.2.9cfrom
xindongliu594:feat/gguf-routeb-v029c

Conversation

@xindongliu594

Copy link
Copy Markdown

Summary

  • 为 NVIDIA 后端增加可复用的 GGUF Route B 权重加载与线性层执行支持,覆盖 Q8_0Q4_KQ5_KQ6_K
  • 完成 Qwen3.5 / Qwen3-Next GGUF 推理适配,包括 fused projection、分片权重和 value-head 重排。
  • csrc/layers/quantization/gguf.* 中实现公共 GGUF 量化配置、布局检查和执行逻辑。
  • 扩展 csrc/layers/linear/*csrc/layers/mlp/* 和 Qwen 模型代码,使 GGUF 能力可被其他模型复用。
  • 增加 scripts/gguf_mapping.pyscripts/gguf_to_infinilm.pyscripts/gguf_transforms.pytest/scripts/test_gguf_routeb.py
  • 增加 GGUF_ROUTE_B_QWEN38.md,记录架构、转换方式、支持范围和当前限制。
  • 清理一次性研究脚本、机器相关路径、中文代码注释、重复运行时日志与隐藏诊断开关。

Motivation

InfiniLM 当前不能直接加载并执行 Qwen3.5 27B 等模型的 GGUF 量化权重。若在各模型代码中分别实现解量化和矩阵计算,会产生大量重复逻辑,也不利于继续适配其他 GGUF 模型。

本 PR 将 GGUF 支持拆分为可复用层次:

  1. InfiniCore 提供通用 linear_gguf 与 BlockFP8 线性算子;
  2. InfiniLM 提供公共 GGUF 量化配置和线性层;
  3. 模型层只描述权重名称、融合关系和特殊排列规则;
  4. 转换工具负责 GGUF tensor 到 InfiniLM checkpoint 的映射。

相关依赖:

N/A — 当前没有对应的 InfiniLM issue,因此不填写 Closes #...

Type of Change

  • feat — new feature / new model
  • fix — bug fix
  • perf — performance improvement (no behavioral change)
  • refactor — code restructuring without behavior change
  • test — adding or fixing tests only
  • docs — documentation only
  • build / ci — build system or CI configuration
  • chore — tooling, formatting, or other non-code changes
  • Breaking change

Test Results of Involved Models on Supported Platforms (Please attach screenshots)

测试环境:

项目 配置
GPU NVIDIA GeForce RTX 5090
CUDA CUDA 13.0
模型 Qwen3.5 / Qwen3-Next 27B GGUF
权重 GGUF block-quantized weights
目标分支 InfiniLM-v0.2.9c
InfiniLM 提交 4822f86e
InfiniCore 提交 c3440e6d

已通过:

  • scripts/format.py --ref upstream/InfiniLM-v0.2.9c --check
  • git diff --check、Python compileall
  • test/scripts/test_gguf_routeb.py -v:5/5;
  • clean build、install、隔离 import;
  • examples/test_infer.py:Qwen3.5 27B GGUF 单请求测试,exit 0;
  • examples/bench.py:64 input / 8 output 离线性能入口,exit 0;
  • InfiniCore linear_gguf、BlockFP8、MHA varlen 与整模型联调测试。

未勾选项:

  • v0.2.9c 分支尚未重新运行 test/bench/test_benchmark.py sanity 测试;
  • v0.2.9c 分支尚未重新运行 inference server + scripts/test_perf.py service 测试;
  • GitHub CI 尚未由 maintainer 触发。

测试截图

Benchmark / Performance Impact

GGUF prefill 解量化优化

同一 RTX 5090、相同模型/配置/warmup,三次测量取中位数:

场景 优化前 TTFT 优化后 TTFT 变化
64-token prefill 6088.06 ms 926.65 ms 约 6.57x
256-token prefill 6254.61 ms 1282.13 ms 约 4.88x
512-token prefill 8545.82 ms 3699.01 ms 约 2.31x

可选 FlashAttention 联调结果

FlashAttention 是框架已有的可选后端,本 PR 不改变默认分派。相对 paged-attention 预热基线:

阶段 paged-attention FlashAttention 变化
64-token prefill TTFT 911.05 ms 925.58 ms +1.6%,基本持平
256-token prefill TTFT 1271.95 ms 927.59 ms -27.1%,约 1.37x
512-token prefill TTFT 3589.60 ms 993.14 ms -72.3%,约 3.61x
128-token decode ITL 161.76 ms 167.80 ms +3.7%,略慢
128-token decode throughput 6.18 tok/s 5.96 tok/s -3.6%

因此当前仍保留 paged-attention 默认路径;不宣称全阶段提速或达到 llama.cpp 水平。

Notes for Reviewers

  • 本 PR 依赖 InfiniCore 的 linear_gguf / BlockFP8 API;请先审查关联的 InfiniCore PR。
  • GGUF 公共层负责量化布局与执行,Qwen 模型层只保留模型特有 mapping、fusion 与重排。
  • Qwen3.5/GDN 路径当前关闭 prefix caching;其他模型维持原行为。
  • 当前只支持 NVIDIA GGUF 执行路径;其他平台不在本 PR 支持范围。
  • 已删除研究诊断、tensor dump、机器绝对路径与重复日志。

CI / ChatOps

CI 尚未触发。PR 创建后将从 Actions → CI 选择本分支手动运行;若外部 fork 无权限,则请求 maintainer 评论 /retest/test


Checklist

Title, Branch, and Commits

  • PR title follows Conventional Commits (e.g. feat(nvidia): …, fix(cuda/gemm): …).
  • Branch name follows <type>/xxx-yyyy-zzzz where <type> matches the PR title's Conventional Commits type and words are joined with hyphens (see CONTRIBUTING.md §Branches).
  • Each commit message follows Conventional Commits.
  • Small PR is a single squashable commit; or, for a large PR, every commit is meaningful, well-formed, and independently reviewable (see CONTRIBUTING.md §Pull Requests).
  • N/A — 此 PR 的 base 是 InfiniLM-v0.2.9c 而非 main;分支直接基于该 base,且没有 merge commits。
  • No fixup! / squash! / wip commits remain.
  • N/A — 本 PR 使用当前 Conventional Commits 格式,不是 legacy issue-format PR。

Scope and Design

  • Changes are minimal — nothing unrelated to the stated motivation was added (CONTRIBUTING.md §Code/General).
  • No dead code, commented-out blocks, debug prints, printf/std::cout/print(...) left behind, or TODO without an owner and issue link.
  • No unrelated formatting churn that would obscure the diff.
  • Public API changes (if any) are intentional, documented, and reflected in affected callers/tests.

General Code Hygiene (applies to all languages)

  • The code is self-explanatory; comments were added only where the why is non-obvious (CONTRIBUTING.md §Code/General).
  • Every modified or added file ends with a single trailing newline (CONTRIBUTING.md §Code/General).
  • No trailing whitespace, tab/space mixing, or stray BOMs.
  • Identifiers in comments and error messages are wrapped in backticks (e.g. the `seqlens_k` tensor) (CONTRIBUTING.md §Code/General).
  • All comments and error messages are in English (CONTRIBUTING.md §Code/General).
  • Comments and error messages are complete sentences — capitalized first letter, terminal punctuation — unless the language/framework convention says otherwise (CONTRIBUTING.md §Code/General; §Python).

C++ Specific (if C++ files changed)

  • Code follows the Google C++ Style Guide strictly.
  • Error and warning message wording follows the LLVM Coding Standards (CONTRIBUTING.md §C++).
  • Constructor initializer list order matches member declaration order (CONTRIBUTING.md §C++).
  • No raw new/delete; RAII / smart pointers / existing allocators are used.
  • Changed files are formatted by scripts/format.py.
  • No changes/reference to csrc/models/llama_legacy/.

Python Specific (if Python files changed)

  • Code is PEP 8 compliant.
  • Comments are complete English sentences, starting with a capital letter and ending with punctuation; Markdown backticks are used for code references (CONTRIBUTING.md §Python).
  • Docstrings (if any) follow PEP 257 (CONTRIBUTING.md §Python).
  • Changed files are formatted by scripts/format.py.
  • No changes/reference to python/infinilm/auto_config.py.

Testing

  • 本 PR 当前支持的平台仅为 NVIDIA,已在 RTX 5090 / CUDA 13.0 上完成测试;无其他声称支持但无法测试的平台。
  • Passed single request test (examples/test_infer.py).
  • Passed offline performance test (examples/bench.py).
  • v0.2.9c 分支尚未重新运行 sanity test (test/bench/test_benchmark.py);当前先提交以启动 review/CI,不将该项标记为完成。
  • v0.2.9c 分支尚未重新运行 service test (python/infinilm/server/inference_server.py + scripts/test_perf.py);当前先提交以启动 review/CI,不将该项标记为完成。

Build, CI, and Tooling

  • The project builds cleanly from an independent worktree on NVIDIA; build、install 与隔离 import 均通过。
  • CI 尚未触发;PR 创建后按模板说明手动触发或请求 maintainer /retest

Documentation

  • GGUF_ROUTE_B_QWEN38.md 已记录架构、转换、运行参数、支持范围和限制。
  • N/A — 本 PR 没有 user-visible breaking change。

Security and Safety

  • No secrets, access tokens, internal URLs, customer data, or personal hardware identifiers have been committed.
  • Third-party GGML/llama.cpp 来源已在 InfiniCore 依赖 PR 中固定版本、注明 MIT 许可证并附许可证文本;InfiniLM 不复制其源码。
  • No unsafe pointer arithmetic, uninitialized reads, or missing bounds checks were introduced; packed row、type、shape 与 workspace 均有显式校验和负例测试。

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