|
3 | 3 | #include "spdlog/spdlog.h" |
4 | 4 | #include <future> |
5 | 5 | #include <stdexcept> |
| 6 | +#include <unordered_set> |
6 | 7 |
|
7 | 8 | namespace infinilm::engine { |
8 | 9 |
|
@@ -32,7 +33,12 @@ InferEngine::InferEngine( |
32 | 33 |
|
33 | 34 | // Load model config if model_path is provided, model_path must be valid, and config.json exists |
34 | 35 | this->model_config_ = infinilm::config::ConfigFactory::createConfig(config_str); |
35 | | - auto infinilm_config = std::make_shared<infinilm::global_state::InfinilmConfig>(attention_backend, this->model_config_, use_mla); |
| 36 | + auto infinilm_config = std::make_shared<infinilm::global_state::InfinilmConfig>( |
| 37 | + attention_backend, |
| 38 | + this->model_config_, |
| 39 | + use_mla, |
| 40 | + distributed_config.moe_ep_backend, |
| 41 | + distributed_config.moe_ep_size); |
36 | 42 |
|
37 | 43 | // Only support offline int8 kv cache quantization in this version |
38 | 44 | if (kv_cache_dtype.has_value()) { |
@@ -67,19 +73,19 @@ void InferEngine::load_param(const std::string &name, const infinicore::Tensor & |
67 | 73 | } |
68 | 74 | } |
69 | 75 |
|
70 | | -void InferEngine::load_params(const std::unordered_map<std::string, infinicore::Tensor> ¶ms) { |
| 76 | +void InferEngine::load_params(const std::unordered_map<std::string, infinicore::Tensor> ¶ms, bool strict) { |
71 | 77 | if (workers_.size() <= 1 || weight_load_mode_ == "sync") { |
72 | 78 | for (auto &worker : workers_) { |
73 | | - worker->load_params(params); |
| 79 | + worker->load_params(params, strict); |
74 | 80 | } |
75 | 81 | return; |
76 | 82 | } |
77 | 83 |
|
78 | 84 | std::vector<std::future<void>> futures; |
79 | 85 | futures.reserve(workers_.size()); |
80 | 86 | for (auto &worker : workers_) { |
81 | | - futures.emplace_back(std::async(std::launch::async, [&worker, ¶ms] { |
82 | | - worker->load_params(params); |
| 87 | + futures.emplace_back(std::async(std::launch::async, [&worker, ¶ms, strict] { |
| 88 | + worker->load_params(params, strict); |
83 | 89 | })); |
84 | 90 | } |
85 | 91 | for (auto &future : futures) { |
@@ -118,7 +124,17 @@ std::vector<std::string> InferEngine::state_dict_keys() { |
118 | 124 | if (0 == workers_.size()) { |
119 | 125 | throw std::runtime_error(" Model object not found. "); |
120 | 126 | } |
121 | | - return workers_.front()->state_dict_keys(); |
| 127 | + std::vector<std::string> ordered_keys; |
| 128 | + std::unordered_set<std::string> seen_keys; |
| 129 | + for (auto &worker : workers_) { |
| 130 | + for (const auto &key : worker->state_dict_keys()) { |
| 131 | + // Preserve first-seen worker order while removing duplicate TP keys. |
| 132 | + if (seen_keys.emplace(key).second) { |
| 133 | + ordered_keys.push_back(key); |
| 134 | + } |
| 135 | + } |
| 136 | + } |
| 137 | + return ordered_keys; |
122 | 138 | } |
123 | 139 |
|
124 | 140 | //------------------------------------------------------ |
|
0 commit comments