Skip to content

Commit bc34dd4

Browse files
ggerganovxaedes
andauthored
train : fix KQ_pos allocation (ggml-org#3392)
* train : fix KQ_pos allocation * make sure KQ_pos is not reallocated in finetune --------- Co-authored-by: xaedes <[email protected]>
1 parent 2777a84 commit bc34dd4

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

examples/finetune/finetune.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,8 @@ static struct ggml_tensor * llama_build_lora_finetune_graphs(
626626

627627
// KQ_pos - contains the positions
628628
struct ggml_tensor * KQ_pos = ggml_new_tensor_1d(ctx, GGML_TYPE_I32, N);
629-
{
629+
ggml_allocr_alloc(alloc, KQ_pos);
630+
if (!ggml_allocr_is_measure(alloc)) {
630631
int * data = (int *) KQ_pos->data;
631632
for (int i = 0; i < N; ++i) {
632633
data[i] = n_past + i;
@@ -786,6 +787,8 @@ static struct ggml_tensor * llama_build_lora_finetune_graphs(
786787
ggml_build_forward_expand(gb, ggml_scale_inplace(ctx, t36->grad, one));
787788
GGML_ASSERT(t36->grad->data == NULL && t36->grad->view_src == NULL);
788789
ggml_allocr_alloc(alloc, t36->grad);
790+
// KQ_pos
791+
ggml_build_forward_expand(gb, ggml_scale_inplace(ctx, KQ_pos, one));
789792

790793
// make sure base model tensors data cannot be used in viewable operations
791794
ggml_build_forward_expand(gb, ggml_scale_inplace(ctx, model->tok_embeddings, one));

examples/train-text-from-scratch/train-text-from-scratch.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,8 @@ static struct ggml_tensor * llama_build_train_graphs(
334334

335335
// KQ_pos - contains the positions
336336
struct ggml_tensor * KQ_pos = ggml_new_tensor_1d(ctx, GGML_TYPE_I32, N);
337-
{
337+
ggml_allocr_alloc(alloc, KQ_pos);
338+
if (!ggml_allocr_is_measure(alloc)) {
338339
int * data = (int *) KQ_pos->data;
339340
for (int i = 0; i < N; ++i) {
340341
data[i] = n_past + i;

0 commit comments

Comments
 (0)