| 732 | } |
| 733 | |
| 734 | const struct ggml_tensor * llama_model_loader::check_tensor_dims(const std::string & name, const std::vector<int64_t> & ne, bool required) const { |
| 735 | const struct ggml_tensor * cur = get_tensor_meta(name.c_str()); |
| 736 | |
| 737 | if (cur == NULL) { |
| 738 | if (!required) { |
| 739 | return NULL; |
| 740 | } |
| 741 | throw std::runtime_error(format("%s: tensor '%s' not found", __func__, name.c_str())); |
| 742 | } |
| 743 | |
| 744 | { |
| 745 | bool is_ok = true; |
| 746 | for (size_t i = 0; i < GGML_MAX_DIMS; ++i) { |
| 747 | // -- PowerInfer |
| 748 | // Bypass unknown dimension, which may make model update more convenient in the future. |
| 749 | if (i < ne.size() && ne[i] == -1) { continue; } |
| 750 | // -- PowerInfer end |
| 751 | |
| 752 | if ((i < ne.size() && ne[i] != cur->ne[i]) || (i >= ne.size() && cur->ne[i] != 1)) { |
| 753 | is_ok = false; |
| 754 | break; |
| 755 | } |
| 756 | } |
| 757 | if (!is_ok) { |
| 758 | throw std::runtime_error( |
| 759 | format("%s: tensor '%s' has wrong shape; expected %s, got %s", |
| 760 | __func__, name.c_str(), |
| 761 | llama_format_tensor_shape(ne).c_str(), |
| 762 | llama_format_tensor_shape(cur).c_str())); |
| 763 | } |
| 764 | } |
| 765 | |
| 766 | return cur; |
| 767 | } |
| 768 | |
| 769 | struct ggml_tensor * llama_model_loader::create_tensor(struct ggml_context * ctx, const std::string & name, const std::initializer_list<int64_t> & ne, int flags) { |
| 770 | const struct ggml_tensor * cur = check_tensor_dims(name, ne, !(flags & TENSOR_NOT_REQUIRED)); |
nothing calls this directly
no test coverage detected