]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commitdiff
hparams : add check for layer index in is_recurrent (#16511)
authorDaniel Bevenius <redacted>
Sun, 12 Oct 2025 05:19:06 +0000 (07:19 +0200)
committerGitHub <redacted>
Sun, 12 Oct 2025 05:19:06 +0000 (07:19 +0200)
* 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

index c04ac58f1af4ba3746c97ddefcfd723c390ad027..db65d69eabdcbd3dcc106428b90dd72afb5b04d3 100644 (file)
@@ -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("%s: il (%u) out of bounds (n_layer: %u)\n", __func__, il, n_layer);
 }
 
 uint32_t llama_hparams::n_pos_per_embd() const {