url: save -mu download to new cache location
This commit is contained in:
parent
7027b27d76
commit
59f7e0d475
1 changed files with 11 additions and 8 deletions
|
@ -191,6 +191,15 @@ int32_t cpu_get_num_math() {
|
||||||
// CLI argument parsing
|
// CLI argument parsing
|
||||||
//
|
//
|
||||||
|
|
||||||
|
static std::string get_cached_file(const std::string & path) {
|
||||||
|
std::string cache_directory = fs_get_cache_directory();
|
||||||
|
const bool success = fs_create_directory_with_parents(cache_directory);
|
||||||
|
if (!success) {
|
||||||
|
throw std::runtime_error("failed to create cache directory: " + cache_directory);
|
||||||
|
}
|
||||||
|
return cache_directory + string_split(path, '/').back();
|
||||||
|
}
|
||||||
|
|
||||||
void gpt_params_handle_model_default(gpt_params & params) {
|
void gpt_params_handle_model_default(gpt_params & params) {
|
||||||
if (!params.hf_repo.empty()) {
|
if (!params.hf_repo.empty()) {
|
||||||
// short-hand to avoid specifying --hf-file -> default it to --model
|
// short-hand to avoid specifying --hf-file -> default it to --model
|
||||||
|
@ -200,19 +209,13 @@ void gpt_params_handle_model_default(gpt_params & params) {
|
||||||
}
|
}
|
||||||
params.hf_file = params.model;
|
params.hf_file = params.model;
|
||||||
} else if (params.model.empty()) {
|
} else if (params.model.empty()) {
|
||||||
std::string cache_directory = fs_get_cache_directory();
|
params.model = get_cached_file(params.hf_file);
|
||||||
const bool success = fs_create_directory_with_parents(cache_directory);
|
|
||||||
if (!success) {
|
|
||||||
throw std::runtime_error("failed to create cache directory: " + cache_directory);
|
|
||||||
}
|
|
||||||
params.model = cache_directory + string_split(params.hf_file, '/').back();
|
|
||||||
}
|
}
|
||||||
} else if (!params.model_url.empty()) {
|
} else if (!params.model_url.empty()) {
|
||||||
if (params.model.empty()) {
|
if (params.model.empty()) {
|
||||||
auto f = string_split(params.model_url, '#').front();
|
auto f = string_split(params.model_url, '#').front();
|
||||||
f = string_split(f, '?').front();
|
f = string_split(f, '?').front();
|
||||||
f = string_split(f, '/').back();
|
params.model = get_cached_file(f);
|
||||||
params.model = "models/" + f;
|
|
||||||
}
|
}
|
||||||
} else if (params.model.empty()) {
|
} else if (params.model.empty()) {
|
||||||
params.model = DEFAULT_MODEL_PATH;
|
params.model = DEFAULT_MODEL_PATH;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue