Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: YAML Config Tests

on:
push:
branches: [ "master", "devin/*" ]
pull_request:
branches: [ "master" ]

jobs:
test-yaml-config:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Dependencies
id: depends
run: |
sudo apt-get update
sudo apt-get install -y build-essential cmake git-lfs
git lfs install

- name: Download tiny model (stories15M)
run: |
mkdir -p models
# Download only the specific model file we need (19MB) to avoid disk space issues
wget -q "https://huggingface.co/ggml-org/models/resolve/main/tinyllamas/stories15M-q4_0.gguf" -O models/stories15M-q4_0.gguf
ls -lh models/stories15M-q4_0.gguf

- name: Build
id: cmake_build
run: |
cmake -B build -DLLAMA_BUILD_TESTS=ON -DLLAMA_BUILD_TOOLS=ON -DLLAMA_FATAL_WARNINGS=ON -DLLAMA_CURL=OFF
cmake --build build --config Release -j $(nproc)

- name: Test YAML config functionality
run: |
cd build
ctest -R "test-config-yaml|test-config-yaml-cli-.*|test-config-yaml-parity" --output-on-failure --timeout 300
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,38 @@ llama-cli -hf ggml-org/gemma-3-1b-it-GGUF
llama-server -hf ggml-org/gemma-3-1b-it-GGUF
```

### YAML Configuration

You can use YAML configuration files to set parameters instead of command-line flags:

```bash
llama-cli --config configs/minimal.yaml
```

Example `minimal.yaml`:
```yaml
model:
path: models/tinyllama-1.1b-chat-v1.0.Q4_K_M.gguf
n_ctx: 256
sampling:
seed: 42
temp: 0.0
prompt: "Hello from YAML"
n_predict: 16
simple_io: true
```

You can override YAML values with command-line flags:
```bash
llama-cli --config configs/minimal.yaml -n 32 --temp 0.8
```

**Precedence rules:** Command-line flags > YAML config > defaults

**Path resolution:** Relative paths in YAML files are resolved relative to the YAML file's directory.

**Error handling:** Unknown YAML keys will cause an error with a list of valid keys.

## Description

The main goal of `llama.cpp` is to enable LLM inference with minimal setup and state-of-the-art performance on a wide
Expand Down
26 changes: 26 additions & 0 deletions common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,32 @@ if (LLAMA_LLGUIDANCE)
set(LLAMA_COMMON_EXTRA_LIBS ${LLAMA_COMMON_EXTRA_LIBS} llguidance ${LLGUIDANCE_PLATFORM_LIBS})
endif ()

if (LLAMA_BUILD_TOOLS)
# yaml-cpp for YAML config (CLI-only)
find_package(yaml-cpp QUIET)
if (NOT yaml-cpp_FOUND)
include(FetchContent)
FetchContent_Declare(yaml-cpp
GIT_REPOSITORY https://github.com/jbeder/yaml-cpp.git
GIT_TAG 0.8.0)
set(YAML_CPP_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(YAML_CPP_BUILD_TOOLS OFF CACHE BOOL "" FORCE)
set(YAML_CPP_BUILD_CONTRIB OFF CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(yaml-cpp)
# Suppress all warnings for yaml-cpp to avoid -Werror failures
if(TARGET yaml-cpp)
target_compile_options(yaml-cpp PRIVATE -w)
endif()
endif()

target_sources(${TARGET} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/config.cpp
${CMAKE_CURRENT_SOURCE_DIR}/config.h
)
target_link_libraries(${TARGET} PRIVATE yaml-cpp)
target_compile_definitions(${TARGET} PUBLIC LLAMA_ENABLE_CONFIG_YAML)
endif()

target_include_directories(${TARGET} PUBLIC . ../vendor)
target_compile_features (${TARGET} PUBLIC cxx_std_17)
target_link_libraries (${TARGET} PRIVATE ${LLAMA_COMMON_EXTRA_LIBS} PUBLIC llama Threads::Threads)
Expand Down
33 changes: 33 additions & 0 deletions common/arg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

#include "chat.h"
#include "common.h"
#ifdef LLAMA_ENABLE_CONFIG_YAML
#include "config.h"
#endif
#include "gguf.h" // for reading GGUF splits
#include "json-schema-to-grammar.h"
#include "log.h"
Expand Down Expand Up @@ -1223,6 +1226,26 @@ bool common_params_parse(int argc, char ** argv, common_params & params, llama_e
const common_params params_org = ctx_arg.params; // the example can modify the default params

try {
#ifdef LLAMA_ENABLE_CONFIG_YAML
for (int i = 1; i < argc; ++i) {
if (std::string(argv[i]) == "--config") {
if (i + 1 >= argc) {
throw std::invalid_argument("error: --config requires a file path");
}
std::string cfg_path = argv[++i];
if (!common_load_yaml_config(cfg_path, ctx_arg.params)) {
throw std::invalid_argument("error: failed to load YAML config: " + cfg_path);
}
break;
}
}
#else
for (int i = 1; i < argc; ++i) {
if (std::string(argv[i]) == "--config") {
throw std::invalid_argument("error: this build does not include YAML config support (LLAMA_BUILD_TOOLS=OFF)");
}
}
#endif
if (!common_params_parse_ex(argc, argv, ctx_arg)) {
ctx_arg.params = params_org;
return false;
Expand Down Expand Up @@ -1317,6 +1340,16 @@ common_params_context common_params_parser_init(common_params & params, llama_ex
params.completion = true;
}
));

#ifdef LLAMA_ENABLE_CONFIG_YAML
add_opt(common_arg(
{"--config"},
"<path/to/config.yaml>",
"Load parameters from a YAML config file; flags passed on the command line override values from the YAML file.",
[](common_params &, const std::string &) {
}
));
#endif
add_opt(common_arg(
{"--verbose-prompt"},
string_format("print a verbose prompt before generation (default: %s)", params.verbose_prompt ? "true" : "false"),
Expand Down
Loading
Loading