|
| 1 | +#include "arg.h" |
| 2 | +#include "common.h" |
| 3 | +#include "log.h" |
| 4 | + |
| 5 | +#include <cstdio> |
| 6 | +#include <string> |
| 7 | + |
| 8 | +static void print_usage(int, char ** argv) { |
| 9 | + LOG("Usage: %s [options]\n", argv[0]); |
| 10 | + LOG("\n"); |
| 11 | + LOG("Download models from HuggingFace or Docker Hub\n"); |
| 12 | + LOG("\n"); |
| 13 | + LOG("Options:\n"); |
| 14 | + LOG(" -h, --help show this help message and exit\n"); |
| 15 | + LOG(" -hf, -hfr, --hf-repo REPO download model from HuggingFace repo\n"); |
| 16 | + LOG(" format: <user>/<model>[:<quant>]\n"); |
| 17 | + LOG(" example: microsoft/DialoGPT-medium\n"); |
| 18 | + LOG(" -dr, --docker-repo REPO download model from Docker Hub\n"); |
| 19 | + LOG(" format: [<repo>/]<model>[:<quant>]\n"); |
| 20 | + LOG(" example: gemma3\n"); |
| 21 | + LOG(" --hf-token TOKEN HuggingFace token for private repos\n"); |
| 22 | + LOG("\n"); |
| 23 | + LOG("Examples:\n"); |
| 24 | + LOG(" %s -hf microsoft/DialoGPT-medium\n", argv[0]); |
| 25 | + LOG(" %s -dr gemma3\n", argv[0]); |
| 26 | + LOG(" %s -hf microsoft/DialoGPT-medium\n", argv[0]); |
| 27 | + LOG("\n"); |
| 28 | +} |
| 29 | + |
| 30 | +int main(int argc, char ** argv) { |
| 31 | + common_params params; |
| 32 | + |
| 33 | + // Set up argument parsing context |
| 34 | + auto ctx = common_params_parser_init(params, LLAMA_EXAMPLE_COMMON, print_usage); |
| 35 | + |
| 36 | + // Parse command line arguments |
| 37 | + if (!common_params_parse(argc, argv, params, LLAMA_EXAMPLE_COMMON, print_usage)) { |
| 38 | + print_usage(argc, argv); |
| 39 | + return 1; |
| 40 | + } |
| 41 | + |
| 42 | + // Check if help was requested or no download option provided |
| 43 | + if (params.model.hf_repo.empty() && params.model.docker_repo.empty()) { |
| 44 | + LOG_ERR("error: must specify either -hf <repo> or -dr <repo>\n"); |
| 45 | + print_usage(argc, argv); |
| 46 | + return 1; |
| 47 | + } |
| 48 | + |
| 49 | + LOG_INF("llama-pull: downloading model...\n"); |
| 50 | + try { |
| 51 | + // Use the existing model handling logic which downloads the model |
| 52 | + common_init_result llama_init = common_init_from_params(params); |
| 53 | + if (llama_init.model != nullptr) { |
| 54 | + LOG_INF("Model downloaded and loaded successfully to: %s\n", params.model.path.c_str()); |
| 55 | + |
| 56 | + // We only want to download, not keep the model loaded |
| 57 | + // The download happens during common_init_from_params |
| 58 | + } else { |
| 59 | + LOG_ERR("Failed to download or load model\n"); |
| 60 | + return 1; |
| 61 | + } |
| 62 | + } catch (const std::exception & e) { |
| 63 | + LOG_ERR("Error: %s\n", e.what()); |
| 64 | + return 1; |
| 65 | + } |
| 66 | + |
| 67 | + return 0; |
| 68 | +} |
0 commit comments