Repository navigation
deepseek4: expert_used_count の override をハッシュルーティング層と両立させる - #13
Merged
Merged
Conversation
ハッシュ層のトークン→expert 表 (ffn_gate_tid2eid) の幅は GGUF 固定で、 expert_used_count を override すると形状検証がロードで落ちる。表の実幅で ロードし、ハッシュ層の build_moe_ffn には表の幅を渡すことで、routed 層だけ 使用 expert 数を減らせるようにする。override なしの動作は変わらない
ishikawa
commented
Aug 2, 2026
| const ggml_tensor * tid2eid_meta = ml->get_tensor_meta(tn(LLM_TENSOR_FFN_GATE_TID2EID, "weight", i).str().c_str()); | ||
| const int64_t n_hash_used = tid2eid_meta ? tid2eid_meta->ne[0] : n_expert_used; | ||
| layer.ffn_gate_tid2eid = create_tensor(tn(LLM_TENSOR_FFN_GATE_TID2EID, "weight", i), {n_hash_used, n_vocab}, 0); | ||
| } else { |
Owner
Author
There was a problem hiding this comment.
表の幅は override 後の n_expert_used とは無関係なので、テンソルメタの実寸でロードします。meta が取れない異常系は従来どおり n_expert_used に落として形状検証に任せます
| @@ -1154,7 +1163,7 @@ llama_model_deepseek4::graph::graph(const llama_model & model, const llm_graph_p | |||
| layer.ffn_gate_exps, | |||
Owner
Author
There was a problem hiding this comment.
build_moe_ffn は selected_experts を渡した場合も n_expert_used 引数で weights を reshape するため、ハッシュ層には表の実幅を渡す必要があります
- build_moe_ffn の最終集約が hparams.n_expert_used 固定で、ハッシュ層の 実計算幅 (表幅) と食い違うと一部の expert 出力が合算されない (Codex 指摘)。 warmup 時のみ hparams 幅に抑制し、通常時は引数幅で集約する - metadata-only ロード経路で表幅が読めない場合に警告を出す (Codex 指摘) - n_expert_used_layer を int64_t にする (Gemini 指摘)
Owner
Author
|
3 視点レビューの結果と対応です。
修正後の検証: override なし bit 一致 / used=5 で run 間決定論・出力一貫を確認。 |
ishikawa
added a commit
that referenced
this pull request
Aug 9, 2026
#13 (c40b49c) で追加した「--override-kv deepseek4.expert_used_count でハッシュルーティング層 (blk.0-2) の実 expert 数を保つ」対応を廃止する。 local-llm#93 で used=5 への削減は品質リスクに見合わないとして本番 (既定の used=6) に戻すことが決定済みで、本番起動構成は override を 使わない。現行 K128/K144 GGUF は `ffn_gate_tid2eid` の幅が常に `expert_used_count` と一致する (GGUFReader で実測確認済み) ため、 override なしではこの revert によるロード・生成挙動の変化はない。 override を使った使い捨ての計測・較正セッションで必要になった場合は このコミット (および直前の 4aa7f3c revert) を履歴から復元する。 コンフリクト解消: src/models/deepseek4.cpp は #13 直後に追加された `flags` 引数 (nextn/mtp 対応、本 revert と無関係) を維持しつつ、 tid2eid テンソル幅の決定ロジックのみ #13 以前の `n_expert_used` 直読 みに戻した。 This reverts commit c40b49c.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
deepseek v4 flash の decode 高速化の一環です。
--override-kv deepseek4.expert_used_count=int:Nで routed 層の使用 expert 数を減らせるようにします (実測 N=5 で +21%、N=4 で +34%)。