Commit 0df40737c for llama.cpp
commit 0df40737cdbfc607aab2f21a5b75eec6d36be656
Author: Xuan-Son Nguyen <son@huggingface.co>
Date: Wed Dec 2 13:04:31 2026 +0100
test: fix mistral-large4 rope test randomly fails (#33519)
diff --git a/tests/test-llama-archs.cpp b/tests/test-llama-archs.cpp
index 34064f648..479b5d284 100644
--- a/tests/test-llama-archs.cpp
+++ b/tests/test-llama-archs.cpp
@@ -52,6 +52,7 @@ static double nmse(const std::vector<float> & a, const std::vector<float> & b) {
struct tensor_data_params {
size_t seed;
float stdev;
+ bool pos_invariant; // remove the dependency on the absolute position where weights allow it
};
// fills the values of one tensor, the name carries whatever the property needs
@@ -131,8 +132,18 @@ static void fill_exp_probs_b(std::vector<float> & dst, const char *, const tenso
}
}
+// SSMax scales Q by s * log(pos + 1) + b, a zero slope keeps it constant
+static void fill_ssmax_s(std::vector<float> & dst, const char * name, const tensor_data_params & params) {
+ if (params.pos_invariant) {
+ std::fill(dst.begin(), dst.end(), 0.0f);
+ } else {
+ fill_normal(dst, name, params);
+ }
+}
+
// a tensor whose values hold a property of their own, matched on a substring of its name, first match wins
static const struct { const char * match; tensor_filler fill; } TENSOR_FILLERS[] = {
+ { "ssmax.weight", fill_ssmax_s },
{ "ssm_a", fill_ssm_a },
{ "_resid_", fill_resid_gate },
{ "exp_probs_b", fill_exp_probs_b },
@@ -959,7 +970,7 @@ static llama_model_ptr get_model(
struct gguf_context * gguf_ctx, FILE * file, const size_t seed, const float stdev,
const std::vector<ggml_backend_dev_t> & devs,
const llama_split_mode split_mode = LLAMA_SPLIT_MODE_LAYER,
- const llama_model_tensor_buft_override * tensor_buft_overrides = nullptr) {
+ const llama_model_tensor_buft_override * tensor_buft_overrides = nullptr, bool pos_invariant = false) {
GGML_ASSERT((gguf_ctx == nullptr) != (file == nullptr));
llama_model_params model_params = llama_model_default_params();
model_params.progress_callback = silent_model_load_progress;
@@ -969,7 +980,7 @@ static llama_model_ptr get_model(
model_params.split_mode = split_mode;
model_params.tensor_buft_overrides = tensor_buft_overrides;
- tensor_data_params tensor_params = { seed, stdev };
+ tensor_data_params tensor_params = { seed, stdev, pos_invariant };
llama_model_ptr model(gguf_ctx != nullptr ?
llama_model_init_from_user(gguf_ctx, set_tensor_data, &tensor_params, model_params) :
llama_model_load_from_file_ptr(file, model_params));
@@ -1883,9 +1894,9 @@ static int test_kv_shift(const std::string & arch_filter, const size_t seed, con
const char * config_name = moe ? "MoE" : "Dense";
// the hidden states of the prefix depend on the absolute position:
- // mistral-large4 scales attention by position, hunyuan/maincoder apply q/k norm weights after RoPE
- const bool pos_dependent = arch == LLM_ARCH_MISTRAL_LARGE4 || arch == LLM_ARCH_HUNYUAN_MOE ||
- arch == LLM_ARCH_HUNYUAN_DENSE || arch == LLM_ARCH_MAINCODER;
+ // hunyuan/maincoder apply q/k norm weights after RoPE
+ // mistral-large4 SSMax is made constant via pos_invariant, so it uses the strict threshold
+ const bool pos_dependent = arch == LLM_ARCH_HUNYUAN_MOE || arch == LLM_ARCH_HUNYUAN_DENSE || arch == LLM_ARCH_MAINCODER;
const double thold = pos_dependent ? 1e-4 : 1e-6;
// at least 4 layers, so that "every 4th layer" patterns (NoPE, full attention) are covered
@@ -1901,7 +1912,7 @@ static int test_kv_shift(const std::string & arch_filter, const size_t seed, con
llama_model_ptr model;
try {
- model = get_model(gguf_ctx.get(), nullptr, seed, stdev, {});
+ model = get_model(gguf_ctx.get(), nullptr, seed, stdev, {}, LLAMA_SPLIT_MODE_LAYER, nullptr, true);
} catch (const std::exception & err) {
LOG(template_row.c_str(), llama_arch_name(arch), config_name, "", "", "", "", "\033[1;31mERROR\033[0m (model load)");
n_tests++;