-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Implement llama-pull tool #16132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ericcurtin
wants to merge
1
commit into
master
Choose a base branch
from
llama-pull
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+136
−0
Open
Implement llama-pull tool #16132
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
set(TARGET llama-pull) | ||
add_executable(${TARGET} pull.cpp) | ||
target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT}) | ||
target_compile_features(${TARGET} PRIVATE cxx_std_17) | ||
|
||
if(LLAMA_TOOLS_INSTALL) | ||
install(TARGETS ${TARGET} RUNTIME) | ||
endif() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# llama-pull - Model Download Tool | ||
|
||
A command-line tool for downloading AI models from HuggingFace and Docker Hub for use with llama.cpp. | ||
|
||
## Usage | ||
|
||
```bash | ||
# Download from HuggingFace | ||
llama-pull -hf <user>/<model>[:<quant>] | ||
|
||
# Download from Docker Hub | ||
llama-pull -dr [<repo>/]<model>[:<quant>] | ||
``` | ||
|
||
## Options | ||
|
||
- `-hf, --hf-repo REPO` - Download model from HuggingFace repository | ||
- `-dr, --docker-repo REPO` - Download model from Docker Hub | ||
- `--hf-token TOKEN` - HuggingFace token for private repositories | ||
- `-h, --help` - Show help message | ||
|
||
## Examples | ||
|
||
```bash | ||
# Download a HuggingFace model | ||
llama-pull -hf microsoft/DialoGPT-medium | ||
|
||
# Download a Docker model (ai/ repo is default) | ||
llama-pull -dr gemma3 | ||
|
||
# Download with specific quantization | ||
llama-pull -hf bartowski/Llama-3.2-1B-Instruct-GGUF:Q4_K_M | ||
``` | ||
|
||
## Model Storage | ||
|
||
Downloaded models are stored in the standard llama.cpp cache directory: | ||
- Linux/macOS: `~/.cache/llama.cpp/` | ||
- The models can then be used with other llama.cpp tools | ||
|
||
## Requirements | ||
|
||
- Built with `LLAMA_USE_CURL=ON` (default) for download functionality |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#include "arg.h" | ||
#include "common.h" | ||
#include "log.h" | ||
|
||
#include <cstdio> | ||
#include <string> | ||
|
||
static void print_usage(int, char ** argv) { | ||
LOG("Usage: %s [options]\n", argv[0]); | ||
LOG("\n"); | ||
LOG("Download models from HuggingFace or Docker Hub\n"); | ||
LOG("\n"); | ||
LOG("Options:\n"); | ||
LOG(" -h, --help show this help message and exit\n"); | ||
LOG(" -hf, -hfr, --hf-repo REPO download model from HuggingFace repository\n"); | ||
LOG(" format: <user>/<model>[:<quant>]\n"); | ||
LOG(" example: microsoft/DialoGPT-medium\n"); | ||
LOG(" -dr, --docker-repo REPO download model from Docker Hub\n"); | ||
LOG(" format: [<repo>/]<model>[:<quant>]\n"); | ||
LOG(" example: gemma3\n"); | ||
LOG(" -o, --output PATH output path for downloaded model\n"); | ||
LOG(" (default: cache directory)\n"); | ||
LOG(" --hf-token TOKEN HuggingFace token for private repositories\n"); | ||
LOG("\n"); | ||
LOG("Examples:\n"); | ||
LOG(" %s -hf microsoft/DialoGPT-medium\n", argv[0]); | ||
LOG(" %s -dr gemma3\n", argv[0]); | ||
LOG(" %s -hf microsoft/DialoGPT-medium -o ./my-model.gguf\n", argv[0]); | ||
LOG("\n"); | ||
} | ||
|
||
int main(int argc, char ** argv) { | ||
common_params params; | ||
|
||
// Set up argument parsing context | ||
auto ctx = common_params_parser_init(params, LLAMA_EXAMPLE_COMMON, print_usage); | ||
|
||
// Parse command line arguments | ||
if (!common_params_parse(argc, argv, params, LLAMA_EXAMPLE_COMMON)) { | ||
print_usage(argc, argv); | ||
return 1; | ||
} | ||
|
||
// Check if help was requested or no download option provided | ||
if (params.model.hf_repo.empty() && params.model.docker_repo.empty()) { | ||
LOG_ERR("error: must specify either -hf <repo> or -dr <repo>\n"); | ||
print_usage(argc, argv); | ||
return 1; | ||
} | ||
|
||
// Both cannot be specified at the same time | ||
if (!params.model.hf_repo.empty() && !params.model.docker_repo.empty()) { | ||
LOG_ERR("error: cannot specify both -hf and -dr options\n"); | ||
print_usage(argc, argv); | ||
return 1; | ||
} | ||
Comment on lines
+52
to
+56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be checked inside |
||
|
||
// Initialize llama backend for download functionality | ||
llama_backend_init(); | ||
Comment on lines
+58
to
+59
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why we need to initialize the inference backend to download the model? |
||
|
||
LOG_INF("llama-pull: downloading model...\n"); | ||
|
||
try { | ||
// Use the existing model handling logic which downloads the model | ||
common_init_result llama_init = common_init_from_params(params); | ||
|
||
if (llama_init.model != nullptr) { | ||
LOG_INF("Model downloaded and loaded successfully to: %s\n", params.model.path.c_str()); | ||
|
||
// We only want to download, not keep the model loaded | ||
// The download happens during common_init_from_params | ||
} else { | ||
LOG_ERR("Failed to download or load model\n"); | ||
return 1; | ||
} | ||
} catch (const std::exception & e) { | ||
LOG_ERR("Error: %s\n", e.what()); | ||
return 1; | ||
} | ||
|
||
// Clean up | ||
llama_backend_free(); | ||
return 0; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure that the
-o
is currently handled this way?