Helper function to parse tensor buffer override strings
| 243 | |
| 244 | // Helper function to parse tensor buffer override strings |
| 245 | static void parse_tensor_buffer_overrides(const std::string & value, std::vector<llama_model_tensor_buft_override> & overrides) { |
| 246 | std::map<std::string, ggml_backend_buffer_type_t> buft_list; |
| 247 | for (size_t i = 0; i < ggml_backend_dev_count(); ++i) { |
| 248 | auto * dev = ggml_backend_dev_get(i); |
| 249 | auto * buft = ggml_backend_dev_buffer_type(dev); |
| 250 | if (buft) { |
| 251 | buft_list[ggml_backend_buft_name(buft)] = buft; |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | for (const auto & override : string_split<std::string>(value, ',')) { |
| 256 | std::string::size_type pos = override.find('='); |
| 257 | if (pos == std::string::npos) { |
| 258 | throw std::invalid_argument("invalid value"); |
| 259 | } |
| 260 | std::string tensor_name = override.substr(0, pos); |
| 261 | std::string buffer_type = override.substr(pos + 1); |
| 262 | |
| 263 | if (buft_list.find(buffer_type) == buft_list.end()) { |
| 264 | printf("Available buffer types:\n"); |
| 265 | for (const auto & it : buft_list) { |
| 266 | printf(" %s\n", ggml_backend_buft_name(it.second)); |
| 267 | } |
| 268 | throw std::invalid_argument("unknown buffer type"); |
| 269 | } |
| 270 | // keep strings alive and avoid leaking memory by storing them in a static vector |
| 271 | static std::list<std::string> buft_overrides; |
| 272 | buft_overrides.push_back(tensor_name); |
| 273 | overrides.push_back({buft_overrides.back().c_str(), buft_list.at(buffer_type)}); |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | static std::string clean_file_name(const std::string & fname) { |
| 278 | std::string clean_fname = fname; |
no test coverage detected