From 894dc178aa9be380ed6772284de05ebb1a68dc77 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Sat, 11 Oct 2025 06:53:58 +0200 Subject: [PATCH 1/2] hparams : add check for layer index in is_recurrent This commit adds a check in the is_recurrent method to ensure that the provided layer index is within the valid range. The motivation for this change is to prevent potential out-of-bounds and also be consistent with other methods in the class that perform similar checks, like is_swa. --- src/llama-hparams.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/llama-hparams.cpp b/src/llama-hparams.cpp index c04ac58f1af4b..51172b8cd1e53 100644 --- a/src/llama-hparams.cpp +++ b/src/llama-hparams.cpp @@ -140,7 +140,11 @@ uint32_t llama_hparams::n_embd_s() const { } bool llama_hparams::is_recurrent(uint32_t il) const { - return recurrent_layer_arr[il]; + if (il < n_layer) { + return recurrent_layer_arr[il]; + } + + GGML_ABORT("\n%s: il (%u) out of bounds (n_layer: %d)\n", __func__, il, (int)n_layer); } uint32_t llama_hparams::n_pos_per_embd() const { From ac5d83b6c0c4b44d71791934a2f903c19398e291 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Sat, 11 Oct 2025 10:58:49 +0200 Subject: [PATCH 2/2] remove extra newline and int cast --- src/llama-hparams.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/llama-hparams.cpp b/src/llama-hparams.cpp index 51172b8cd1e53..db65d69eabdcb 100644 --- a/src/llama-hparams.cpp +++ b/src/llama-hparams.cpp @@ -144,7 +144,7 @@ bool llama_hparams::is_recurrent(uint32_t il) const { return recurrent_layer_arr[il]; } - GGML_ABORT("\n%s: il (%u) out of bounds (n_layer: %d)\n", __func__, il, (int)n_layer); + GGML_ABORT("%s: il (%u) out of bounds (n_layer: %u)\n", __func__, il, n_layer); } uint32_t llama_hparams::n_pos_per_embd() const {