CoolFace
Modelpublic

Felipe97/llama-cpp-compiled

sourceHugging Faceupdated 2d agoView on Hugging Face
0likes1.1kdownloads
download.cpp72 linesDownload Raw Back to app
1#include "arg.h"2#include "common.h"3#include "download.h"4#include "log.h"5 6#include <cstdio>7#include <filesystem>8 9static void print_usage(int /*argc*/, char ** argv) {10    printf(11        "\nexamples:\n"12        "  %s -hf ggml-org/gemma-3-4b-it-qat-GGUF\n"13        "  %s -hf ggml-org/gemma-3-4b-it-qat-GGUF:Q4_K_M\n"14        "  %s -hf ggml-org/models -hff model.gguf\n"15        "  %s -mu https://example.com/model.gguf -m model.gguf\n"16        "\n",17        argv[0], argv[0], argv[0], argv[0]18    );19}20 21int llama_download(int argc, char ** argv);22 23int llama_download(int argc, char ** argv) {24    common_init();25 26    common_params params;27    params.verbosity = LOG_LEVEL_ERROR;28 29    if (!common_params_parse(argc, argv, params, LLAMA_EXAMPLE_DOWNLOAD, print_usage)) {30        return 1;31    }32 33    const bool has_source = !params.model.hf_repo.empty() || !params.model.url.empty() ||34                            !params.model.path.empty()    || !params.model.docker_repo.empty();35    if (!has_source) {36        fprintf(stderr, "error: no model source specified (use --hf-repo, --model-url, --model or --docker-repo)\n");37        return 1;38    }39 40    try {41        common_models_handler handler = common_models_handler_init(params, LLAMA_EXAMPLE_DOWNLOAD);42        common_models_handler_apply(handler, params);43    } catch (const std::exception & e) {44        fprintf(stderr, "error: %s\n", e.what());45        return 1;46    }47 48    if (!params.models_preset.empty()) {49        // -hf pointed at a preset repo: print the preset path and stop50        printf("%s\n", params.models_preset.c_str());51        return 0;52    }53    if (params.model.path.empty()) {54        fprintf(stderr, "error: model download failed\n");55        return 1;56    }57    if (!std::filesystem::exists(params.model.path)) {58        fprintf(stderr, "error: model file does not exist: %s\n", params.model.path.c_str());59        return 1;60    }61 62    printf("%s\n", params.model.path.c_str());63    if (!params.mmproj.path.empty()) {64        printf("%s\n", params.mmproj.path.c_str());65    }66    if (!params.speculative.draft.mparams.path.empty()) {67        printf("%s\n", params.speculative.draft.mparams.path.c_str());68    }69 70    return 0;71}72