Skip to content

Commit 642bd57

Browse files
committed
Opt class for positional argument handling
Added support for positional arguments `model` and `prompt`. Added model path resolution, just `file://` for now. Added functionality to download via strings like: llama-run llama3 llama-run ollama://granite-code llama-run ollama://granite-code:8b llama-run hf://QuantFactory/SmolLM-135M-GGUF/SmolLM-135M.Q2_K.gguf llama-run huggingface://bartowski/SmolLM-1.7B-Instruct-v0.2-GGUF/SmolLM-1.7B-Instruct-v0.2-IQ3_M.gguf llama-run https://example.com/some-file1.gguf llama-run some-file2.gguf llama-run file://some-file3.gguf Signed-off-by: Eric Curtin <[email protected]>
1 parent 5555c0c commit 642bd57

File tree

6 files changed

+464
-161
lines changed

6 files changed

+464
-161
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,20 @@ To learn more about model quantization, [read this documentation](examples/quant
433433

434434
</details>
435435

436+
## [`llama-run`](examples/run)
437+
438+
#### A comprehensive example for running `llama.cpp` models. Useful for inferencing. Used with RamaLama [^3].
439+
440+
- <details>
441+
<summary>Run a model with a specific prompt (by default it's pulled from Ollama registry)</summary>
442+
443+
```bash
444+
llama-run granite-code
445+
```
446+
447+
</details>
448+
449+
[^3]: [https://github.com/containers/ramalama](RamaLama)
436450
437451
## [`llama-simple`](examples/simple)
438452

common/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ set(LLAMA_COMMON_EXTRA_LIBS build_info)
8181
# Use curl to download model url
8282
if (LLAMA_CURL)
8383
find_package(CURL REQUIRED)
84-
add_definitions(-DLLAMA_USE_CURL)
84+
target_compile_definitions(${TARGET} PUBLIC LLAMA_USE_CURL)
8585
include_directories(${CURL_INCLUDE_DIRS})
8686
find_library(CURL_LIBRARY curl REQUIRED)
8787
set(LLAMA_COMMON_EXTRA_LIBS ${LLAMA_COMMON_EXTRA_LIBS} ${CURL_LIBRARY})

common/common.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,12 +1108,6 @@ struct ggml_threadpool_params ggml_threadpool_params_from_cpu_params(const cpu_p
11081108
#define CURL_MAX_RETRY 3
11091109
#define CURL_RETRY_DELAY_SECONDS 2
11101110

1111-
1112-
static bool starts_with(const std::string & str, const std::string & prefix) {
1113-
// While we wait for C++20's std::string::starts_with...
1114-
return str.rfind(prefix, 0) == 0;
1115-
}
1116-
11171111
static bool curl_perform_with_retry(const std::string& url, CURL* curl, int max_attempts, int retry_delay_seconds) {
11181112
int remaining_attempts = max_attempts;
11191113

common/common.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ using llama_tokens = std::vector<llama_token>;
3737

3838
// build info
3939
extern int LLAMA_BUILD_NUMBER;
40-
extern char const * LLAMA_COMMIT;
41-
extern char const * LLAMA_COMPILER;
42-
extern char const * LLAMA_BUILD_TARGET;
40+
extern const char * LLAMA_COMMIT;
41+
extern const char * LLAMA_COMPILER;
42+
extern const char * LLAMA_BUILD_TARGET;
4343

4444
struct common_control_vector_load_info;
4545

@@ -437,6 +437,11 @@ std::vector<std::string> string_split<std::string>(const std::string & input, ch
437437
return parts;
438438
}
439439

440+
static bool string_starts_with(const std::string & str,
441+
const std::string & prefix) { // While we wait for C++20's std::string::starts_with...
442+
return str.rfind(prefix, 0) == 0;
443+
}
444+
440445
bool string_parse_kv_override(const char * data, std::vector<llama_model_kv_override> & overrides);
441446
void string_process_escapes(std::string & input);
442447

examples/run/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
set(TARGET llama-run)
22
add_executable(${TARGET} run.cpp)
33
install(TARGETS ${TARGET} RUNTIME)
4-
target_link_libraries(${TARGET} PRIVATE llama ${CMAKE_THREAD_LIBS_INIT})
4+
target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT})
5+
target_include_directories(${TARGET} PUBLIC ../../common)
56
target_compile_features(${TARGET} PRIVATE cxx_std_17)

0 commit comments

Comments
 (0)