Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ac87b5c

Browse files
slarenhodlen
authored andcommittedApr 1, 2024
finetune : keep allocs alive until all allocations are done (ggml-org#4486)
1 parent 1c1b696 commit ac87b5c

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed
 

‎examples/finetune/finetune.cpp

+7-8
Original file line numberDiff line numberDiff line change
@@ -1620,8 +1620,6 @@ int main(int argc, char ** argv) {
16201620
opt->params.adam.gclip = params.common.adam_gclip;
16211621
opt->params.adam.eps_f = params.common.adam_eps_f;
16221622

1623-
ggml_allocr * alloc = NULL;
1624-
16251623
printf("%s: init model\n", __func__);
16261624
bool existed = load_checkpoint_lora_file(params.common.fn_checkpoint_in, &model, &lora, train);
16271625

@@ -1725,10 +1723,9 @@ int main(int argc, char ** argv) {
17251723

17261724
// allocate input tensors
17271725
mem_input_data.resize(max_input_size);
1728-
alloc = ggml_allocr_new(mem_input_data.data(), mem_input_data.size(), tensor_alignment);
1729-
ggml_allocr_alloc(alloc, tokens_input);
1730-
ggml_allocr_alloc(alloc, target_probs);
1731-
ggml_allocr_free(alloc);
1726+
ggml_allocr_t alloc_inps = ggml_allocr_new(mem_input_data.data(), mem_input_data.size(), tensor_alignment);
1727+
ggml_allocr_alloc(alloc_inps, tokens_input);
1728+
ggml_allocr_alloc(alloc_inps, target_probs);
17321729

17331730
// context for compute tensors without their data
17341731
const size_t estimated_compute_size_wo_data = (
@@ -1755,7 +1752,7 @@ int main(int argc, char ** argv) {
17551752
// find best evaluation order
17561753
for (unsigned order = 0; order < (unsigned) GGML_CGRAPH_EVAL_ORDER_COUNT; ++order) {
17571754
ctx_compute = ggml_init(ctx_compute_params);
1758-
alloc = ggml_allocr_new_measure(tensor_alignment);
1755+
ggml_allocr_t alloc = ggml_allocr_new_measure(tensor_alignment);
17591756
gf = ggml_new_graph_custom(ctx_compute, LLAMA_TRAIN_MAX_NODES, true);
17601757
gf->order = (enum ggml_cgraph_eval_order) order;
17611758
gb = ggml_new_graph_custom(ctx_compute, LLAMA_TRAIN_MAX_NODES, true);
@@ -1788,7 +1785,7 @@ int main(int argc, char ** argv) {
17881785
// allocate compute tensors
17891786
mem_compute_data.resize(max_compute_size);
17901787
ctx_compute = ggml_init(ctx_compute_params);
1791-
alloc = ggml_allocr_new(mem_compute_data.data(), mem_compute_data.size(), tensor_alignment);
1788+
ggml_allocr_t alloc = ggml_allocr_new(mem_compute_data.data(), mem_compute_data.size(), tensor_alignment);
17921789
gf = ggml_new_graph_custom(ctx_compute, LLAMA_TRAIN_MAX_NODES, true);
17931790
gf->order = best_order;
17941791
gb = ggml_new_graph_custom(ctx_compute, LLAMA_TRAIN_MAX_NODES, true);
@@ -1804,6 +1801,8 @@ int main(int argc, char ** argv) {
18041801
params.common.use_checkpointing
18051802
);
18061803
ggml_allocr_free(alloc);
1804+
ggml_allocr_free(alloc_inps);
1805+
18071806

18081807
// tokenize data
18091808
std::vector<llama_token> train_tokens;

0 commit comments

Comments
 (0)
Please sign in to comment.