Skip to content

feature/mdbf: gemlite対応とHessian/scale_bits修正 - #28

Merged
aki916f merged 6 commits into
FujitsuResearch:feature/mdbffrom
fujisawa-yoshihiko:feature/mdbf
Jul 4, 2026
Merged

feature/mdbf: gemlite対応とHessian/scale_bits修正#28
aki916f merged 6 commits into
FujitsuResearch:feature/mdbffrom
fujisawa-yoshihiko:feature/mdbf

Conversation

@fujisawa-yoshihiko

Copy link
Copy Markdown
Contributor

Summary

MDBF量子化レイヤーに GemLite による1-bit推論高速化を追加し、OSVD初期化のHessian定義と rank_from_bpw() のBPW計算を修正しました。

1. GemLite推論対応 (42b0a62)

  • MDBFLinear / MultipathMDBFLinear に、±1符号行列(A_sign, B_sign)向けの GemLite 1-bit matmul を追加
  • DBF実装(dbf/dbf_layer.py)と同様の設計で、利用可能な場合は符号行列の matmul を GemLite カーネルに委譲
  • auto モードuse_gemlite=None)では l == 1 のときのみ有効化(l > 1 では rank-l 振幅を外側で適用するため GemLite 経路が遅くなる)
  • use_gemlite=True で強制有効化可能
  • GemLite 利用時は冗長な GPU packed-sign バッファを解放し、メモリ使用量を削減
  • MDBF.create_linear_module() から use_gemlite を渡せるように変更

2. OSVD Hessian 定義の修正 (a9b46df)

  • lowrank_osvd() において W @ H^{1/2} の計算で固有ベクトルの転置 @ eig_vecs.T が欠落していた問題を修正
  • 修正前: W_tilde = W @ Q @ diag(√λ)
  • 修正後: W_tilde = W @ Q @ diag(√λ) @ Q^T(論文の定義に一致)

3. BPW → rank 換算の修正 (a9b46df)

  • rank_from_bpw()scale_bits=0 がハードコードされていた問題を修正
  • scale_bits を引数化し、デフォルトを 16 に変更(FP16 envelope パラメータを BPW に含める)
  • 論文の式 b = P * [r(n+m) + 16l(n+m+2r)] / (nm) に整合

変更ファイル

ファイル 変更内容
onecomp/quantizer/mdbf/mdbf_layer.py GemLite 推論パス追加
onecomp/quantizer/mdbf/_mdbf.py use_gemlite 引数の伝播
onecomp/quantizer/mdbf/initialize.py OSVD Hessian 修正
onecomp/quantizer/mdbf/utils.py rank_from_bpw()scale_bits 修正

検証

TinyLlama-1.1B / Llama-2-7B において、1 bpw(l=8, P=1, act_init=osvd)設定で修正前後を比較:

モデル 条件 PPL (wikitext2)
TinyLlama 修正前(実BPW≈1.19) 39.34
TinyLlama 修正後(実BPW≈1.00) 40.17
TinyLlama Hessianのみ修正(同BPW≈1.19) 39.21 ← 改善
Llama-2-7B 修正前(実BPW≈1.09) 20.66
Llama-2-7B 修正後(実BPW≈1.00) 20.54 ← 改善
  • scale_bits 修正により target BPW と実際の BPW が一致するようになった
  • 同一 BPW 条件では Hessian 修正が PPL をわずかに改善(TinyLlama)
  • Llama-2-7B では修正後(正しい 1.0 bpw)の方が性能が向上

Test plan

  • 既存 MDBF ユニットテストが通ること
  • GemLite 未インストール環境で従来どおり dense 推論にフォールバックすること
  • GemLite 有効時(l=1)に推論結果が dense パスと一致すること
  • rank_from_bpw()scale_bits=16 で論文式の BPW を返すこと
  • OSVD 初期化(act_init="osvd")が activation-aware モードで動作すること

- Fixed a discrepancy in the definition of Hessian
- Added `scale_bits` as an argument to `rank_from_bpw()`; the default is 16
P: int = 2,
min_rank: int = 1,
rounding: Literal["floor", "ceil", "round"] = "floor",
scale_bits: int = 16,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

docstringにscale_bitsの追記をお願いします。

@aki916f

aki916f commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

ご対応ありがとうございます!gemliteの部分は特に問題ないと思います。
testplanで書かれているテストについて、未pushであれば追加いただけないでしょうか。
また、changelog.mdに修正内容を簡単に英語で追記いただけないでしょうか。

…ixes

Document the scale_bits argument added to rank_from_bpw() and record
the GemLite inference path, OSVD Hessian fix, and rank_from_bpw fix
in CHANGELOG.md (PR review feedback).
…tests

- test_mdbflinear_falls_back_to_dense_when_gemlite_unavailable: verify
  MDBFLinear falls back to the dense path (bit-identical) when GemLite
  support is unavailable, even if use_gemlite=True is forced.
- test_rank_from_bpw_matches_paper_formula: verify rank_from_bpw()
  round-trips with bpw_from_rank() at scale_bits=16 and that
  scale_bits=0 admits a higher rank for the same budget.
- test_lowrank_osvd_beats_plain_svd_in_hessian_error: regression test
  for the lowrank_osvd() Hessian fix (a9b46df) exercising the
  production function directly against a non-diagonal Hessian.
- test_osvd_hessian_bug.py: proof-of-concept numerically demonstrating
  that the previous H^{1/2} formulation inflated the Hessian-weighted
  reconstruction error for non-diagonal Hessians.

PR review feedback (test plan coverage).
@aki916f

aki916f commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

@fujisawa-yoshihiko
早速対応ありがとうございます!申し訳ないのですが、OSSなのでスクリプト中の日本語を英語に翻訳いただけないでしょうか。

…English

Translate the Japanese module docstring, function/class docstrings, and
inline comments in the OSVD Hessian proof-of-concept test to English.
No logic changes (test still passes).
…ory)

The OSVD tests described the pre-fix "buggy" lowrank_osvd (Q^T missing)
and asserted facts about "the current implementation" that no longer hold
after the fix. Reframe them as a self-contained property/regression check:
the full H^{1/2}=Q diag(sqrt(λ)) Q^T whitening is optimal for the H-weighted
objective, and a variant dropping the trailing Q^T is strictly worse for a
non-diagonal H. Rename the _osvd_buggy helper / test methods accordingly.
No logic changes (tests still pass).

@aki916f aki916f left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@aki916f
aki916f merged commit c16b8b2 into FujitsuResearch:feature/mdbf Jul 4, 2026
@fujisawa-yoshihiko fujisawa-yoshihiko mentioned this pull request Jul 29, 2026
5 tasks
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.

2 participants