From 30d81cce153bf0143398a7a813c4eac5bbca0aa1 Mon Sep 17 00:00:00 2001 From: Aleksa Gordic Date: Sun, 2 Jun 2024 21:28:42 +0200 Subject: [PATCH] Fix mem leak --- train_gpt2.cu | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/train_gpt2.cu b/train_gpt2.cu index bf6acf1..2ee029f 100644 --- a/train_gpt2.cu +++ b/train_gpt2.cu @@ -2554,7 +2554,7 @@ void gpt2_backward(GPT2 *model, int* inputs) { model->grads_memory = malloc_and_point_parameters(&model->grads, model->param_elements, model->param_sizeof); // we're going to be clever for the activations backward pass. we don't need to exactly // mirror the forward pass activations and we will save memory. - size_t bw_act_sizes[NUM_ACTIVATION_TENSORS]; + size_t bw_act_sizes[NUM_BACKWARD_TENSORS]; fill_in_grad_act_sizes(bw_act_sizes, model->batch_size, model->seq_len, model->config); // count up and allocate the space model->num_grad_acts = 0; @@ -2985,6 +2985,7 @@ void load_state(int* step, GPT2* model, DataLoader* loader, const char* filename cudaCheck(cudaMemcpy(model->m_memory, cpu_buffer, shard_num_parameters * sizeof(float), cudaMemcpyHostToDevice)); freadCheck(cpu_buffer, sizeof(float), shard_num_parameters, state_file); cudaCheck(cudaMemcpy(model->v_memory, cpu_buffer, shard_num_parameters * sizeof(float), cudaMemcpyHostToDevice)); + free(cpu_buffer); } // ----------------------------------------------------------------------------