-
Notifications
You must be signed in to change notification settings - Fork 80
feat: add Qwen3.6 MoE model support #521
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
Open
qinyiqun
wants to merge
9
commits into
InfiniTensor:main
Choose a base branch
from
qinyiqun:qw36
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8b6f1d2
feat(qwen3.6): support dense and MoE models
qinyiqun 09664dc
fix(graph): support Qwen3.5 hybrid position metadata
qinyiqun ebcf0d1
refactor: share hybrid decoder and MoE blocks
qinyiqun 082245f
fix(graph): make hybrid metadata config-driven
qinyiqun 34f76b4
refactor(qwen3.5): share model wrappers and reset caches
qinyiqun 2c91d30
refactor(cache): centralize hybrid cache allocation
qinyiqun cce29c0
refactor(config): share hybrid model defaults
qinyiqun ce8761d
refactor(qwen3-next): reuse text causal LM template
qinyiqun a33beaf
refactor(qwen3.5): align shared MoE with model family
qinyiqun 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| #pragma once | ||
|
|
||
| #include "../backends/attention_backends.hpp" | ||
| #include "../config/model_config.hpp" | ||
| #include "kv_cache.hpp" | ||
| #include "mamba_cache.hpp" | ||
|
|
||
| #include <cstddef> | ||
| #include <memory> | ||
| #include <vector> | ||
|
|
||
| namespace infinilm::cache { | ||
|
|
||
| struct HybridCacheTensors { | ||
| std::vector<infinicore::Tensor> kv_cache_tensors; | ||
| std::vector<infinicore::Tensor> conv_state_tensors; | ||
| std::vector<infinicore::Tensor> ssm_state_tensors; | ||
| size_t mamba_state_pool_size{0}; | ||
| }; | ||
|
|
||
| HybridCacheTensors allocate_hybrid_cache_tensors( | ||
| const CacheConfig *cache_config, | ||
| const std::shared_ptr<infinilm::config::ModelConfig> &model_config, | ||
| const backends::AttentionBackend &attention_backend); | ||
|
|
||
| } // namespace infinilm::cache |
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 |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| #include "hybrid_model_config.hpp" | ||
|
|
||
| #include <stdexcept> | ||
| #include <string> | ||
| #include <utility> | ||
| #include <vector> | ||
|
|
||
| namespace infinilm::config { | ||
|
|
||
| void prepare_hybrid_model_config( | ||
| const std::shared_ptr<ModelConfig> &model_config) { | ||
| if (model_config == nullptr) { | ||
| throw std::runtime_error( | ||
| "prepare_hybrid_model_config: model_config is null"); | ||
| } | ||
|
|
||
| auto &config_json = model_config->get_config_json(); | ||
| const size_t num_hidden_layers = model_config->get<size_t>("num_hidden_layers"); | ||
|
|
||
| if (!config_json.contains("layer_types")) { | ||
| const size_t full_attention_interval = model_config->get<size_t>("full_attention_interval"); | ||
| if (full_attention_interval == 0) { | ||
| throw std::runtime_error( | ||
| "prepare_hybrid_model_config: full_attention_interval must be positive"); | ||
| } | ||
|
|
||
| std::vector<std::string> layer_types; | ||
| layer_types.reserve(num_hidden_layers); | ||
| for (size_t layer_idx = 0; layer_idx < num_hidden_layers; ++layer_idx) { | ||
| layer_types.push_back( | ||
| (layer_idx + 1) % full_attention_interval == 0 | ||
| ? "full_attention" | ||
| : "linear_attention"); | ||
| } | ||
| config_json["layer_types"] = std::move(layer_types); | ||
| } | ||
|
|
||
| const auto &layer_types = config_json["layer_types"]; | ||
| if (!layer_types.is_array() | ||
| || layer_types.size() != num_hidden_layers) { | ||
| throw std::runtime_error( | ||
| "prepare_hybrid_model_config: layer_types size must match num_hidden_layers"); | ||
| } | ||
| for (size_t layer_idx = 0; layer_idx < num_hidden_layers; ++layer_idx) { | ||
| if (!layer_types[layer_idx].is_string()) { | ||
| throw std::runtime_error( | ||
| "prepare_hybrid_model_config: layer_types entries must be strings"); | ||
| } | ||
| const auto &layer_type = layer_types[layer_idx].get_ref<const std::string &>(); | ||
| if (layer_type != "full_attention" | ||
| && layer_type != "linear_attention") { | ||
| throw std::runtime_error( | ||
| "prepare_hybrid_model_config: unsupported layer_type '" | ||
| + layer_type + "' at layer " + std::to_string(layer_idx)); | ||
| } | ||
| } | ||
|
|
||
| if (!config_json.contains("attention_bias")) { | ||
| config_json["attention_bias"] = false; | ||
| } | ||
| } | ||
|
|
||
| } // namespace infinilm::config |
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 |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| #pragma once | ||
|
|
||
| #include "model_config.hpp" | ||
|
|
||
| #include <memory> | ||
|
|
||
| namespace infinilm::config { | ||
|
|
||
| void prepare_hybrid_model_config( | ||
| const std::shared_ptr<ModelConfig> &model_config); | ||
|
|
||
| } // namespace infinilm::config | ||
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
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.
这个是检查config.json中的值的函数,被qwen3_next和3_5掉用的,放在这个位置不好吧。
感觉不能属于这个config文件夹中。
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.
这个config应该可以算是一个通用的config,供所有类似架构的模型使用,放在这里应该并无不妥