From 098654c27760f837bddf6b114d0d3e53788e7043 Mon Sep 17 00:00:00 2001 From: xaedes Date: Mon, 14 Aug 2023 20:56:56 +0200 Subject: [PATCH] only use ggml_allocr_alloc when tensor has NULL data and is no view --- .../train-text-from-scratch/train-text-from-scratch.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/examples/train-text-from-scratch/train-text-from-scratch.cpp b/examples/train-text-from-scratch/train-text-from-scratch.cpp index 94a2a766d..a30291a1c 100644 --- a/examples/train-text-from-scratch/train-text-from-scratch.cpp +++ b/examples/train-text-from-scratch/train-text-from-scratch.cpp @@ -986,11 +986,15 @@ struct ggml_tensor * llama_build_train_graphs( // gradient tensors (will be set to zero by ggml_graph_reset) for (int i = 0; i < gf->n_nodes; ++i) { if (!gf->grads[i]) continue; - ggml_allocr_alloc(alloc, gf->grads[i]); + if (gf->grads[i]->data == NULL && !ggml_is_view(gf->grads[i])) { + ggml_allocr_alloc(alloc, gf->grads[i]); + } ggml_build_forward_expand(gb, ggml_scale_inplace(ctx, gf->grads[i], one)); } for (int i = 0; i < checkpoints.size(); ++i) { - ggml_allocr_alloc(alloc, checkpoints[i]); + if (checkpoints[i]->data == NULL && !ggml_is_view(checkpoints[i])) { + ggml_allocr_alloc(alloc, checkpoints[i]); + } } int n_leafs_after = gb->n_leafs;