hparams : add check for layer index in is_recurrent (#16511)

* 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.
This commit is contained in:
Daniel Bevenius
2025-10-12 07:19:06 +02:00
committed by GitHub
parent 20cc625edc
commit a2fba89a42

View File

@@ -140,9 +140,13 @@ uint32_t llama_hparams::n_embd_s() const {
} }
bool llama_hparams::is_recurrent(uint32_t il) const { bool llama_hparams::is_recurrent(uint32_t il) const {
if (il < n_layer) {
return recurrent_layer_arr[il]; 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 { uint32_t llama_hparams::n_pos_per_embd() const {
return rope_type == LLAMA_ROPE_TYPE_MROPE ? 4 : 1; return rope_type == LLAMA_ROPE_TYPE_MROPE ? 4 : 1;
} }