llama_model * model = nullptr;
if (!params.hf_repo.empty() && !params.hf_file.empty()) {
- model = common_load_model_from_hf(params.hf_repo.c_str(), params.hf_file.c_str(), params.model.c_str(), params.hf_token.c_str(), mparams);
+ model = common_load_model_from_hf(params.hf_repo, params.hf_file, params.model, params.hf_token, mparams);
} else if (!params.model_url.empty()) {
- model = common_load_model_from_url(params.model_url.c_str(), params.model.c_str(), params.hf_token.c_str(), mparams);
+ model = common_load_model_from_url(params.model_url, params.model, params.hf_token, mparams);
} else {
model = llama_load_model_from_file(params.model.c_str(), mparams);
}
}
struct llama_model * common_load_model_from_url(
- const char * model_url,
- const char * path_model,
- const char * hf_token,
+ const std::string & model_url,
+ const std::string & local_path,
+ const std::string & hf_token,
const struct llama_model_params & params) {
// Basic validation of the model_url
- if (!model_url || strlen(model_url) == 0) {
+ if (model_url.empty()) {
LOG_ERR("%s: invalid model_url\n", __func__);
return NULL;
}
- if (!common_download_file(model_url, path_model, hf_token)) {
+ if (!common_download_file(model_url, local_path, hf_token)) {
return NULL;
}
/*.no_alloc = */ true,
/*.ctx = */ NULL,
};
- auto * ctx_gguf = gguf_init_from_file(path_model, gguf_params);
+ auto * ctx_gguf = gguf_init_from_file(local_path.c_str(), gguf_params);
if (!ctx_gguf) {
- LOG_ERR("\n%s: failed to load input GGUF from %s\n", __func__, path_model);
+ LOG_ERR("\n%s: failed to load input GGUF from %s\n", __func__, local_path.c_str());
return NULL;
}
// Verify the first split file format
// and extract split URL and PATH prefixes
{
- if (!llama_split_prefix(split_prefix, sizeof(split_prefix), path_model, 0, n_split)) {
- LOG_ERR("\n%s: unexpected model file name: %s n_split=%d\n", __func__, path_model, n_split);
+ if (!llama_split_prefix(split_prefix, sizeof(split_prefix), local_path.c_str(), 0, n_split)) {
+ LOG_ERR("\n%s: unexpected model file name: %s n_split=%d\n", __func__, local_path.c_str(), n_split);
return NULL;
}
- if (!llama_split_prefix(split_url_prefix, sizeof(split_url_prefix), model_url, 0, n_split)) {
- LOG_ERR("\n%s: unexpected model url: %s n_split=%d\n", __func__, model_url, n_split);
+ if (!llama_split_prefix(split_url_prefix, sizeof(split_url_prefix), model_url.c_str(), 0, n_split)) {
+ LOG_ERR("\n%s: unexpected model url: %s n_split=%d\n", __func__, model_url.c_str(), n_split);
return NULL;
}
}
}
}
- return llama_load_model_from_file(path_model, params);
+ return llama_load_model_from_file(local_path.c_str(), params);
}
struct llama_model * common_load_model_from_hf(
- const char * repo,
- const char * model,
- const char * path_model,
- const char * hf_token,
+ const std::string & repo,
+ const std::string & remote_path,
+ const std::string & local_path,
+ const std::string & hf_token,
const struct llama_model_params & params) {
// construct hugging face model url:
//
std::string model_url = "https://huggingface.co/";
model_url += repo;
model_url += "/resolve/main/";
- model_url += model;
+ model_url += remote_path;
- return common_load_model_from_url(model_url.c_str(), path_model, hf_token, params);
+ return common_load_model_from_url(model_url, local_path, hf_token, params);
}
#else
struct llama_model * common_load_model_from_url(
- const char * /*model_url*/,
- const char * /*path_model*/,
- const char * /*hf_token*/,
+ const std::string & /*model_url*/,
+ const std::string & /*local_path*/,
+ const std::string & /*hf_token*/,
const struct llama_model_params & /*params*/) {
LOG_WRN("%s: llama.cpp built without libcurl, downloading from an url not supported.\n", __func__);
return nullptr;
}
struct llama_model * common_load_model_from_hf(
- const char * /*repo*/,
- const char * /*model*/,
- const char * /*path_model*/,
- const char * /*hf_token*/,
+ const std::string & /*repo*/,
+ const std::string & /*remote_path*/,
+ const std::string & /*local_path*/,
+ const std::string & /*hf_token*/,
const struct llama_model_params & /*params*/) {
LOG_WRN("%s: llama.cpp built without libcurl, downloading from Hugging Face not supported.\n", __func__);
return nullptr;
struct llama_context_params common_context_params_to_llama(const common_params & params);
struct ggml_threadpool_params ggml_threadpool_params_from_cpu_params(const cpu_params & params);
-struct llama_model * common_load_model_from_url(const char * model_url, const char * path_model, const char * hf_token, const struct llama_model_params & params);
-struct llama_model * common_load_model_from_hf(const char * repo, const char * file, const char * path_model, const char * hf_token, const struct llama_model_params & params);
+struct llama_model * common_load_model_from_url(
+ const std::string & model_url,
+ const std::string & local_path,
+ const std::string & hf_token,
+ const struct llama_model_params & params);
+struct llama_model * common_load_model_from_hf(
+ const std::string & repo,
+ const std::string & remote_path,
+ const std::string & local_path,
+ const std::string & hf_token,
+ const struct llama_model_params & params);
// clear LoRA adapters from context, then apply new list of adapters
void common_lora_adapters_apply(struct llama_context * ctx, std::vector<common_lora_adapter_container> & lora_adapters);