| 282 | } |
| 283 | |
| 284 | static bool common_params_handle_remote_preset(common_params & params, llama_example ex) { |
| 285 | GGML_ASSERT(!params.model.hf_repo.empty()); |
| 286 | |
| 287 | // the returned hf_repo is without tag |
| 288 | auto [hf_repo, hf_tag] = common_download_split_repo_tag(params.model.hf_repo); |
| 289 | |
| 290 | // "latest" tag (default if not specified) is translated to "default" preset |
| 291 | if (hf_tag == "latest") { |
| 292 | hf_tag = "default"; |
| 293 | } |
| 294 | |
| 295 | std::string model_endpoint = common_get_model_endpoint(); |
| 296 | auto preset_url = model_endpoint + hf_repo + "/resolve/main/preset.ini"; |
| 297 | |
| 298 | // prepare local path for caching |
| 299 | auto preset_fname = clean_file_name(hf_repo + "_preset.ini"); |
| 300 | auto preset_path = fs_get_cache_file(preset_fname); |
| 301 | common_download_opts opts; |
| 302 | opts.bearer_token = params.hf_token; |
| 303 | opts.offline = params.offline; |
| 304 | const int status = common_download_file_single(preset_url, preset_path, opts); |
| 305 | const bool has_preset = status >= 200 && status < 400; |
| 306 | |
| 307 | // remote preset is optional, so we don't error out if not found |
| 308 | if (has_preset) { |
| 309 | LOG_INF("applying remote preset from %s\n", preset_url.c_str()); |
| 310 | common_preset_context ctx(ex, /* only_remote_allowed */ true); |
| 311 | common_preset global; |
| 312 | auto remote_presets = ctx.load_from_ini(preset_path, global); |
| 313 | remote_presets = ctx.cascade(global, remote_presets); |
| 314 | if (remote_presets.find(hf_tag) != remote_presets.end()) { |
| 315 | common_preset preset = remote_presets.at(hf_tag); |
| 316 | LOG_INF("\n%s", preset.to_ini().c_str()); // to_ini already added trailing newline |
| 317 | preset.apply_to_params(params); |
| 318 | } else { |
| 319 | throw std::runtime_error("Remote preset.ini does not contain [" + std::string(hf_tag) + "] section"); |
| 320 | } |
| 321 | } else { |
| 322 | LOG_INF("%s", "no remote preset found, skipping\n"); |
| 323 | } |
| 324 | |
| 325 | return has_preset; |
| 326 | } |
| 327 | |
| 328 | struct handle_model_result { |
| 329 | bool found_mmproj = false; |
no test coverage detected