First Attempt at using native llama.cpp finetune..

#90
by LinuxMagic - opened

I expected that I might be pushing training, with only a single 4090, however the memory allocation confuses me in the following..

'''
ggml_aligned_malloc: insufficient memory (attempted to allocate 17592186044415.94 MB)
'''

That seems to allocate WAY more memory than I would expect.. Full output below..

'''
ggml_cuda_init: GGML_CUDA_FORCE_MMQ: no
ggml_cuda_init: GGML_CUDA_FORCE_CUBLAS: no
ggml_cuda_init: found 1 CUDA devices:
Device 0: NVIDIA GeForce RTX 4090, compute capability 8.9, VMM: yes
main: force disabling memory mapping because it would result in-read-only pointers to the weights
main: force changing k cache type to f32 due to a lack of f16 support for OUT_PROD
main: force changing v cache type to f32 due to a lack of f16 support for OUT_PROD
build: 6735 (a3cb04744) with cc (Ubuntu 11.4.0-1ubuntu1~22.04.2) 11.4.0 for x86_64-linux-gnu
llama_model_load_from_file_impl: using device CUDA0 (NVIDIA GeForce RTX 4090) (0000:41:00.0) - 14544 MiB free
llama_model_loader: loaded meta data with 40 key-value pairs and 363 tensors from /models/Mistral-Nemo-Instruct-2407-GGUF/Mistral-Nemo-Instruct-2407-f16.gguf (version GGUF V3 (latest))
llama_model_loader: Dumping metadata keys/values. Note: KV overrides do not apply in this output.
llama_model_loader: - kv 0: general.architecture str = llama
llama_model_loader: - kv 1: general.type str = model
llama_model_loader: - kv 2: general.name str = Mistral Nemo Instruct 2407
llama_model_loader: - kv 3: general.version str = 2407
llama_model_loader: - kv 4: general.finetune str = Instruct
llama_model_loader: - kv 5: general.basename str = Mistral-Nemo
llama_model_loader: - kv 6: general.size_label str = 12B
llama_model_loader: - kv 7: general.license str = apache-2.0
llama_model_loader: - kv 8: general.base_model.count u32 = 1
llama_model_loader: - kv 9: general.base_model.0.name str = Mistral Nemo Base 2407
llama_model_loader: - kv 10: general.base_model.0.version str = 2407
llama_model_loader: - kv 11: general.base_model.0.organization str = Mistralai
llama_model_loader: - kv 12: general.base_model.0.repo_url str = https://huggingface.co/mistralai/Mist...
llama_model_loader: - kv 13: general.languages arr[str,9] = ["en", "fr", "de", "es", "it", "pt", ...
llama_model_loader: - kv 14: llama.block_count u32 = 40
llama_model_loader: - kv 15: llama.context_length u32 = 1024000
llama_model_loader: - kv 16: llama.embedding_length u32 = 5120
llama_model_loader: - kv 17: llama.feed_forward_length u32 = 14336
llama_model_loader: - kv 18: llama.attention.head_count u32 = 32
llama_model_loader: - kv 19: llama.attention.head_count_kv u32 = 8
llama_model_loader: - kv 20: llama.rope.freq_base f32 = 1000000.000000
llama_model_loader: - kv 21: llama.attention.layer_norm_rms_epsilon f32 = 0.000010
llama_model_loader: - kv 22: llama.attention.key_length u32 = 128
llama_model_loader: - kv 23: llama.attention.value_length u32 = 128
llama_model_loader: - kv 24: general.file_type u32 = 1
llama_model_loader: - kv 25: llama.vocab_size u32 = 131072
llama_model_loader: - kv 26: llama.rope.dimension_count u32 = 128
llama_model_loader: - kv 27: tokenizer.ggml.model str = gpt2
llama_model_loader: - kv 28: tokenizer.ggml.pre str = tekken
llama_model_loader: - kv 29: tokenizer.ggml.tokens arr[str,131072] = ["", "", "", "[INST]", "[...
llama_model_loader: - kv 30: tokenizer.ggml.token_type arr[i32,131072] = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, ...
llama_model_loader: - kv 31: tokenizer.ggml.merges arr[str,269443] = ["Ġ Ġ", "Ġ t", "e r", "i n", "Ġ �...
llama_model_loader: - kv 32: tokenizer.ggml.bos_token_id u32 = 1
llama_model_loader: - kv 33: tokenizer.ggml.eos_token_id u32 = 2
llama_model_loader: - kv 34: tokenizer.ggml.unknown_token_id u32 = 0
llama_model_loader: - kv 35: tokenizer.ggml.add_bos_token bool = true
llama_model_loader: - kv 36: tokenizer.ggml.add_eos_token bool = false
llama_model_loader: - kv 37: tokenizer.chat_template str = {%- if messages[0]["role"] == "system...
llama_model_loader: - kv 38: tokenizer.ggml.add_space_prefix bool = false
llama_model_loader: - kv 39: general.quantization_version u32 = 2
llama_model_loader: - type f32: 81 tensors
llama_model_loader: - type f16: 282 tensors
print_info: file format = GGUF V3 (latest)
print_info: file type = F16
print_info: file size = 22.81 GiB (16.00 BPW)
load: special_eos_id is not in special_eog_ids - the tokenizer config may be incorrect
load: printing all EOG tokens:
load: - 2 ('')
load: special tokens cache size = 1000
load: token to piece cache size = 0.8498 MB
print_info: arch = llama
print_info: vocab_only = 0
print_info: n_ctx_train = 1024000
print_info: n_embd = 5120
print_info: n_layer = 40
print_info: n_head = 32
print_info: n_head_kv = 8
print_info: n_rot = 128
print_info: n_swa = 0
print_info: is_swa_any = 0
print_info: n_embd_head_k = 128
print_info: n_embd_head_v = 128
print_info: n_gqa = 4
print_info: n_embd_k_gqa = 1024
print_info: n_embd_v_gqa = 1024
print_info: f_norm_eps = 0.0e+00
print_info: f_norm_rms_eps = 1.0e-05
print_info: f_clamp_kqv = 0.0e+00
print_info: f_max_alibi_bias = 0.0e+00
print_info: f_logit_scale = 0.0e+00
print_info: f_attn_scale = 0.0e+00
print_info: n_ff = 14336
print_info: n_expert = 0
print_info: n_expert_used = 0
print_info: causal attn = 1
print_info: pooling type = 0
print_info: rope type = 0
print_info: rope scaling = linear
print_info: freq_base_train = 1000000.0
print_info: freq_scale_train = 1
print_info: n_ctx_orig_yarn = 1024000
print_info: rope_finetuned = unknown
print_info: model type = 13B
print_info: model params = 12.25 B
print_info: general.name = Mistral Nemo Instruct 2407
print_info: vocab type = BPE
print_info: n_vocab = 131072
print_info: n_merges = 269443
print_info: BOS token = 1 ''
print_info: EOS token = 2 '
'
print_info: UNK token = 0 ''
print_info: LF token = 1010 'Ċ'
print_info: EOG token = 2 ''
print_info: max token length = 150
load_tensors: loading model tensors, this can take a while... (mmap = false)
load_tensors: offloading 8 repeating layers to GPU
load_tensors: offloaded 8/41 layers to GPU
load_tensors: CUDA_Host model buffer size = 19201.27 MiB
load_tensors: CUDA0 model buffer size = 4160.31 MiB
............................................................................................
llama_init_from_model: model default pooling_type is [0], but [-1] was specified
llama_context: constructing llama_context
llama_context: n_batch is less than GGML_KQ_MASK_PAD - increasing to 64
llama_context: n_seq_max = 1
llama_context: n_ctx = 4096
llama_context: n_ctx_per_seq = 4096
llama_context: n_batch = 64
llama_context: n_ubatch = 64
llama_context: causal_attn = 1
llama_context: flash_attn = auto
llama_context: kv_unified = false
llama_context: freq_base = 1000000.0
llama_context: freq_scale = 1
llama_context: n_ctx_per_seq (4096) < n_ctx_train (1024000) -- the full capacity of the model will not be utilized
llama_context: CPU output buffer size = 0.50 MiB
llama_kv_cache: CUDA0 KV buffer size = 256.00 MiB
llama_kv_cache: CPU KV buffer size = 1024.00 MiB
llama_kv_cache: size = 1280.00 MiB ( 4096 cells, 40 layers, 1/1 seqs), K (f32): 640.00 MiB, V (f32): 640.00 MiB
llama_context: Flash Attention was auto, set to enabled
llama_context: CUDA0 compute buffer size = 1318.00 MiB
llama_context: CUDA_Host compute buffer size = 17.57 MiB
llama_context: graph nodes = 1327
llama_context: graph splits = 356 (with bs=64), 3 (with bs=1)
common_init_from_params: added logit bias = -inf
common_init_from_params: setting dry_penalty_last_n to ctx_size = 4096
common_init_from_params: warming up the model with an empty run - please wait ... (--no-warmup to disable)

system_info: n_threads = 8 (n_threads_batch = 8) / 32 | CUDA : ARCHS = 500,610,700,750,800,860,890 | USE_GRAPHS = 1 | PEER_MAX_BATCH_SIZE = 128 | CPU : SSE3 = 1 | SSSE3 = 1 | AVX = 1 | AVX2 = 1 | F16C = 1 | FMA = 1 | BMI2 = 1 | LLAMAFILE = 1 | OPENMP = 1 | REPACK = 1 |
ggml_aligned_malloc: insufficient memory (attempted to allocate 17592186044415.94 MB)
ggml_backend_cpu_buffer_type_alloc_buffer: failed to allocate buffer of size 18446744073709486080
alloc_tensor_range: failed to allocate CPU buffer of size 18446744073709486080
/home/michael/git/llama.cpp/build/bin/libggml-base.so(+0x183cb)[0x7f8c8eb0e3cb]
/home/michael/git/llama.cpp/build/bin/libggml-base.so(ggml_print_backtrace+0x21f)[0x7f8c8eb0e82f]
/home/michael/git/llama.cpp/build/bin/libggml-base.so(+0x2b20f)[0x7f8c8eb2120f]
/lib/x86_64-linux-gnu/libstdc++.so.6(+0xae20c)[0x7f8c8e8c220c]
/lib/x86_64-linux-gnu/libstdc++.so.6(+0xae277)[0x7f8c8e8c2277]
/lib/x86_64-linux-gnu/libstdc++.so.6(+0xae4d8)[0x7f8c8e8c24d8]
/lib/x86_64-linux-gnu/libstdc++.so.6(+0xa27ac)[0x7f8c8e8b67ac]
/home/michael/git/llama.cpp/build/bin/libggml-base.so(_ZNSt6vectorIlSaIlEE17_M_default_appendEm+0x1ab)[0x7f8c8eb2ec9b]
/home/michael/git/llama.cpp/build/bin/libggml-base.so(ggml_opt_dataset_init+0x1ee)[0x7f8c8eb2c32e]
./git/llama.cpp/build/bin/llama-finetune(+0x14c64e)[0x55573bb2e64e]
./git/llama.cpp/build/bin/llama-finetune(+0x42b56)[0x55573ba24b56]
/lib/x86_64-linux-gnu/libc.so.6(+0x29d90)[0x7f8c8e50bd90]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x80)[0x7f8c8e50be40]
./git/llama.cpp/build/bin/llama-finetune(+0x44145)[0x55573ba26145]
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
./train_magicspam_lora.sh: line 17: 645986 Aborted (core dumped) ./git/llama.cpp/build/bin/llama-finetune --model /models/Mistral-Nemo-Instruct-2407-GGUF/Mistral-Nemo-Instruct-2407-f16.gguf --output ./lora_weights/mistral_lora.ft.gguf --batch-size 1 --learning-rate 1e-4 --threads 8 --n-gpu-layers 8
michael@ai-cube:~$ nvidia-smi
Sun Oct 12 19:00:19 2025
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 575.57.08 Driver Version: 575.57.08 CUDA Version: 12.9 |
|-----------------------------------------+------------------------+----------------------+
| GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|=========================================+========================+======================|
| 0 NVIDIA GeForce RTX 4090 On | 00000000:41:00.0 On | Off |
| 0% 53C P8 48W / 450W | 9146MiB / 24564MiB | 0% Default |
| | | N/A |
+-----------------------------------------+------------------------+----------------------+

+-----------------------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=========================================================================================|
| 0 N/A N/A 643103 C ./bin/llama-server 9128MiB |
+-----------------------------------------------------------------------------------------+
michael@ai-cube:~$ free
total used free shared buff/cache available
Mem: 527964704 3424548 35096128 40456 489444028 520037652
Swap: 11534324 6912 11527412
'''

Sign up or log in to comment