-
Notifications
You must be signed in to change notification settings - Fork 17.3k
model: add Qwen3-Omni Thinker support (qwen3omnimoe) #18420
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1144,6 +1144,18 @@ void llama_model::load_hparams(llama_model_loader & ml) { | |
| default: type = LLM_TYPE_UNKNOWN; | ||
| } | ||
| } break; | ||
| case LLM_ARCH_QWEN3OMNIMOE: | ||
| { | ||
| // Qwen3-Omni Thinker: Qwen3MOE with M-RoPE and shared experts | ||
| ml.get_key_or_arr(LLM_KV_ROPE_DIMENSION_SECTIONS, hparams.rope_sections, 4, true); | ||
| ml.get_key(LLM_KV_EXPERT_FEED_FORWARD_LENGTH, hparams.n_ff_exp, false); | ||
| ml.get_key(LLM_KV_EXPERT_SHARED_FEED_FORWARD_LENGTH, hparams.n_ff_shexp, false); | ||
| ml.get_key(LLM_KV_ATTENTION_LAYERNORM_RMS_EPS, hparams.f_norm_rms_eps); | ||
| switch (hparams.n_layer) { | ||
| case 48: type = LLM_TYPE_30B; break; | ||
| default: type = LLM_TYPE_UNKNOWN; | ||
| } | ||
| } break; | ||
| case LLM_ARCH_PHI2: | ||
| { | ||
| ml.get_key(LLM_KV_ATTENTION_LAYERNORM_EPS, hparams.f_norm_eps); | ||
|
|
@@ -3642,6 +3654,55 @@ bool llama_model::load_tensors(llama_model_loader & ml) { | |
| layer.ffn_up_exps = create_tensor(tn(LLM_TENSOR_FFN_UP_EXPS, "weight", i), { n_embd, n_ff_exp, n_expert}, 0); | ||
| } | ||
| } break; | ||
| case LLM_ARCH_QWEN3OMNIMOE: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this is only Qwen3VLMoe with shared experts added and you are adding shared experts support to |
||
| { | ||
| // Qwen3-Omni Thinker: Qwen3MOE with M-RoPE and shared experts | ||
| tok_embd = create_tensor(tn(LLM_TENSOR_TOKEN_EMBD, "weight"), {n_embd, n_vocab}, 0); | ||
|
|
||
| output_norm = create_tensor(tn(LLM_TENSOR_OUTPUT_NORM, "weight"), {n_embd}, 0); | ||
| output = create_tensor(tn(LLM_TENSOR_OUTPUT, "weight"), {n_embd, n_vocab}, TENSOR_NOT_REQUIRED); | ||
| if (output == NULL) { | ||
| output = create_tensor(tn(LLM_TENSOR_TOKEN_EMBD, "weight"), {n_embd, n_vocab}, TENSOR_DUPLICATED); | ||
| } | ||
|
|
||
| for (int i = 0; i < n_layer; ++i) { | ||
| auto & layer = layers[i]; | ||
|
|
||
| layer.attn_norm = create_tensor(tn(LLM_TENSOR_ATTN_NORM, "weight", i), {n_embd}, 0); | ||
|
|
||
| layer.wq = create_tensor(tn(LLM_TENSOR_ATTN_Q, "weight", i), {n_embd, n_embd_head_k * n_head}, 0); | ||
| layer.wk = create_tensor(tn(LLM_TENSOR_ATTN_K, "weight", i), {n_embd, n_embd_gqa}, 0); | ||
| layer.wv = create_tensor(tn(LLM_TENSOR_ATTN_V, "weight", i), {n_embd, n_embd_gqa}, 0); | ||
| layer.wo = create_tensor(tn(LLM_TENSOR_ATTN_OUT, "weight", i), {n_embd_head_k * n_head, n_embd}, 0); | ||
|
|
||
| layer.attn_k_norm = create_tensor(tn(LLM_TENSOR_ATTN_K_NORM, "weight", i), {n_embd_head_k}, 0); | ||
| layer.attn_q_norm = create_tensor(tn(LLM_TENSOR_ATTN_Q_NORM, "weight", i), {n_embd_head_k}, 0); | ||
|
|
||
| layer.ffn_norm = create_tensor(tn(LLM_TENSOR_FFN_NORM, "weight", i), {n_embd}, 0); | ||
|
|
||
| layer.ffn_gate_inp = create_tensor(tn(LLM_TENSOR_FFN_GATE_INP, "weight", i), {n_embd, n_expert}, 0); | ||
|
|
||
| if (n_expert == 0) { | ||
| throw std::runtime_error("n_expert must be > 0 for QWEN3OMNIMOE"); | ||
| } | ||
| if (n_expert_used == 0) { | ||
| throw std::runtime_error("n_expert_used must be > 0 for QWEN3OMNIMOE"); | ||
| } | ||
|
|
||
| // MoE experts | ||
| const int64_t n_ff_exp = hparams.n_ff_exp ? hparams.n_ff_exp : n_ff / n_expert_used; | ||
| layer.ffn_gate_exps = create_tensor(tn(LLM_TENSOR_FFN_GATE_EXPS, "weight", i), { n_embd, n_ff_exp, n_expert}, 0); | ||
| layer.ffn_down_exps = create_tensor(tn(LLM_TENSOR_FFN_DOWN_EXPS, "weight", i), {n_ff_exp, n_embd, n_expert}, 0); | ||
| layer.ffn_up_exps = create_tensor(tn(LLM_TENSOR_FFN_UP_EXPS, "weight", i), { n_embd, n_ff_exp, n_expert}, 0); | ||
|
|
||
| // Shared expert (optional) | ||
| if (hparams.n_ff_shexp > 0) { | ||
| layer.ffn_gate_shexp = create_tensor(tn(LLM_TENSOR_FFN_GATE_SHEXP, "weight", i), {n_embd, hparams.n_ff_shexp}, 0); | ||
| layer.ffn_down_shexp = create_tensor(tn(LLM_TENSOR_FFN_DOWN_SHEXP, "weight", i), {hparams.n_ff_shexp, n_embd}, 0); | ||
| layer.ffn_up_shexp = create_tensor(tn(LLM_TENSOR_FFN_UP_SHEXP, "weight", i), {n_embd, hparams.n_ff_shexp}, 0); | ||
| } | ||
| } | ||
| } break; | ||
| case LLM_ARCH_PHI2: | ||
| { | ||
| tok_embd = create_tensor(tn(LLM_TENSOR_TOKEN_EMBD, "weight"), {n_embd, n_vocab}, 0); | ||
|
|
@@ -7510,6 +7571,11 @@ ggml_cgraph * llama_model::build_graph(const llm_graph_params & params) const { | |
| { | ||
| llm = std::make_unique<llm_build_qwen3vlmoe>(*this, params); | ||
| } break; | ||
| case LLM_ARCH_QWEN3OMNIMOE: | ||
| { | ||
| // Reuse Qwen3VLMOE builder - supports M-RoPE and shared experts | ||
| llm = std::make_unique<llm_build_qwen3vlmoe>(*this, params); | ||
| } break; | ||
| case LLM_ARCH_PHI2: | ||
| { | ||
| llm = std::make_unique<llm_build_phi2>(*this, params); | ||
|
|
@@ -8081,6 +8147,7 @@ llama_rope_type llama_model_rope_type(const llama_model * model) { | |
| return LLAMA_ROPE_TYPE_MROPE; | ||
| case LLM_ARCH_QWEN3VL: | ||
| case LLM_ARCH_QWEN3VLMOE: | ||
| case LLM_ARCH_QWEN3OMNIMOE: | ||
| return LLAMA_ROPE_TYPE_IMROPE; | ||
|
|
||
| case LLM_ARCH_GLM4: | ||
|
|
||
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment is incorrect, it's because they for some reason are explicitly set to
nullinconfig.json.