| 362 | } |
| 363 | |
| 364 | static int prepare_imatrix(const std::string & imatrix_file, |
| 365 | std::vector<std::string> & imatrix_dataset, |
| 366 | const std::vector<std::string> & included_weights, |
| 367 | const std::vector<std::string> & excluded_weights, |
| 368 | std::unordered_map<std::string, std::vector<float>> & imatrix_data) { |
| 369 | int m_last_call = -1; |
| 370 | if (!imatrix_file.empty()) { |
| 371 | m_last_call = load_imatrix(imatrix_file, imatrix_dataset, imatrix_data); |
| 372 | } |
| 373 | if (imatrix_data.empty()) { |
| 374 | return m_last_call; |
| 375 | } |
| 376 | if (!excluded_weights.empty()) { |
| 377 | for (const auto & name : excluded_weights) { |
| 378 | for (auto it = imatrix_data.begin(); it != imatrix_data.end();) { |
| 379 | auto pos = it->first.find(name); |
| 380 | if (pos != std::string::npos) { |
| 381 | it = imatrix_data.erase(it); |
| 382 | } else { |
| 383 | ++it; |
| 384 | } |
| 385 | } |
| 386 | } |
| 387 | } |
| 388 | if (!included_weights.empty()) { |
| 389 | std::unordered_map<std::string, std::vector<float>> tmp; |
| 390 | for (const auto & name : included_weights) { |
| 391 | for (auto & e : imatrix_data) { |
| 392 | auto pos = e.first.find(name); |
| 393 | if (pos != std::string::npos) { |
| 394 | tmp.emplace(std::move(e)); |
| 395 | } |
| 396 | } |
| 397 | } |
| 398 | imatrix_data = std::move(tmp); |
| 399 | } |
| 400 | if (!imatrix_data.empty()) { |
| 401 | printf("%s: have %d importance matrix entries\n", __func__, int(imatrix_data.size())); |
| 402 | } |
| 403 | return m_last_call; |
| 404 | } |
| 405 | |
| 406 | static ggml_type parse_ggml_type(const char * arg) { |
| 407 | for (int i = 0; i < GGML_TYPE_COUNT; ++i) { |