Skip to content

Commit 09b2f3e

Browse files
authored
Merge pull request #38 from jpgaribotti/temp-latest
Revert finetuning
2 parents f07781e + 9b5fe8c commit 09b2f3e

25 files changed

+26
-1558
lines changed

examples/training/CMakeLists.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,3 @@ add_executable(${TARGET} finetune.cpp)
33
install(TARGETS ${TARGET} RUNTIME)
44
target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT})
55
target_compile_features(${TARGET} PRIVATE cxx_std_11)
6-
7-
set(TARGET llama-finetune-lora)
8-
add_executable(${TARGET} finetune-lora.cpp)
9-
install(TARGETS ${TARGET} RUNTIME)
10-
target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT})
11-
target_compile_features(${TARGET} PRIVATE cxx_std_11)

examples/training/README.md

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# llama.cpp/examples/training
22

3-
## finetune
43
This directory contains examples related to language model training using llama.cpp/GGML.
54
So far finetuning is technically functional (for FP32 models and limited hardware setups) but the code is very much WIP.
65
Finetuning of Stories 260K and LLaMA 3.2 1b seems to work with 24 GB of memory.
@@ -16,67 +15,3 @@ export model_name=llama_3.2-1b && export quantization=f32
1615
```
1716

1817
The perplexity value of the finetuned model should be lower after training on the test set for 2 epochs.
19-
20-
21-
## finetune-lora
22-
23-
LoRA (Low-Rank Adaptation) fine-tuning for efficient model training. This approach trains only a small set of additional parameters while keeping
24-
the base model frozen, making it memory-efficient.
25-
26-
### Basic Usage
27-
28-
```sh
29-
# Create new LoRA adapter with default settings (rank=8, alpha=16, attention modules)
30-
./build/bin/llama-finetune-lora -m model.gguf -f dataset.txt -ngl 999 -c 512 -b 512 -ub 512
31-
32-
# Custom LoRA parameters(creates new lora adapter and trains it from scratch)
33-
./build/bin/llama-finetune-lora -m model.gguf -f dataset.txt -ngl 999 -c 512 -b 512 -ub 512 \
34-
--lora-rank 16 --lora-alpha 32 --lora-modules "attn_q,attn_k,attn_v,attn_o"
35-
36-
# Fine-tune existing LoRA adapter
37-
./build/bin/llama-finetune-lora -m base_model.gguf -f dataset.txt --lora existing_adapter.gguf \
38-
--output-adapter improved_adapter.gguf -ngl 999 -c 512 -b 512 -ub 512
39-
```
40-
41-
42-
### Parameters
43-
44-
#### LoRA Configuration
45-
- `--lora-rank N` - LoRA rank (default: 8)
46-
- Lower rank = smaller adapter, less capacity
47-
- Higher rank = larger adapter, more capacity
48-
- `--lora-alpha N` - LoRA alpha scaling factor (default: 16.0)
49-
- Controls adaptation strength
50-
- Common rule: alpha = 2 × rank
51-
- `--lora-modules MODULES` - Target modules as comma-separated list
52-
- Available: `attn_q`, `attn_k`, `attn_v`, `attn_o`, `ffn_gate`, `ffn_up`, `ffn_down`, `embed`, `output`, `all`
53-
- Default: `attn_q,attn_k,attn_v,attn_o` (attention modules)
54-
- `--output-adapter PATH` - Output adapter filename (default: auto-generated)
55-
56-
#### Standard Parameters
57-
- `-m MODEL` - Base model file (.gguf)
58-
- `-f FILE` - Training dataset
59-
- `-ngl N` - GPU layers (use 999 for full GPU training)
60-
- `-c N` - Context length (512 recommended for mobile)
61-
62-
63-
### Using Trained Adapters
64-
65-
After training, you'll get a small adapter file. Use it with the original base model:
66-
67-
```sh
68-
./build/bin/llama-cli -m base_model.gguf --lora trained_adapter.gguf -ngl 999
69-
```
70-
71-
### Troubleshooting
72-
73-
- **Out of memory**: Reduce context length (`-c 256`), lower rank, or use fewer target modules
74-
- **Poor quality**: Increase rank, add more target modules, or train longer
75-
- **Large adapter**: Reduce rank or limit target modules
76-
77-
### Help
78-
79-
Run with `--help` or `-h` to see all available parameters:
80-
```sh
81-
./build/bin/llama-finetune-lora --help
82-
```

examples/training/finetune-lora.cpp

Lines changed: 0 additions & 263 deletions
This file was deleted.

examples/training/finetune.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ int main(int argc, char ** argv) {
5454
LOG_INF("%s\n", common_params_get_system_info(params).c_str());
5555
}
5656

57-
std::vector<llama_token> tokens = common_tokenize(ctx.get(), params.prompt, true);
58-
ggml_opt_dataset_t dataset = common_opt_dataset_init(ctx.get(), tokens, llama_n_ctx(ctx.get())/2);
57+
std::vector<llama_token> tokens = common_tokenize(ctx.get(), params.prompt, true);
58+
ggml_opt_dataset_t dataset = common_opt_dataset_init(ctx.get(), tokens, llama_n_ctx(ctx.get()) / 2);
5959

6060
struct lr_opt & lr = params.lr;
6161
LOG_INF("-optimizer %s -lr0 %.2g -wd %.2g -lr-min %.2g -min-epochs %.2g -epochs %d -period %.2g -val %.2g\n",
@@ -64,8 +64,7 @@ int main(int argc, char ** argv) {
6464

6565
struct llama_opt_params lopt_params{
6666
/*n_ctx_train =*/0,
67-
// /*param_filter =*/llama_opt_param_filter_all,
68-
llama_opt_param_filter_lora,
67+
/*param_filter =*/llama_opt_param_filter_all,
6968
/*param_filter_ud =*/nullptr,
7069
/*get_opt_pars =*/common_opt_lr_pars,
7170
/*get_opt_pars_ud =*/&params.lr,

ggml/include/ggml.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,6 @@ extern "C" {
479479
GGML_OP_REPEAT_BACK,
480480
GGML_OP_CONCAT,
481481
GGML_OP_SILU_BACK,
482-
GGML_OP_GEGLU_BACK,
483482
GGML_OP_NORM, // normalize
484483
GGML_OP_RMS_NORM,
485484
GGML_OP_RMS_NORM_BACK,
@@ -1131,12 +1130,6 @@ extern "C" {
11311130
struct ggml_tensor * a,
11321131
struct ggml_tensor * b);
11331132

1134-
GGML_API struct ggml_tensor * ggml_geglu_back(
1135-
struct ggml_context * ctx,
1136-
struct ggml_tensor * grad,
1137-
struct ggml_tensor * x,
1138-
struct ggml_tensor * g);
1139-
11401133
// hardswish(x) = x * relu6(x + 3) / 6
11411134
GGML_API struct ggml_tensor * ggml_hardswish(
11421135
struct ggml_context * ctx,

0 commit comments

Comments
 (0)