diff --git a/src/llama-context.cpp b/src/llama-context.cpp index ccfd52175747..53668fa316aa 100644 --- a/src/llama-context.cpp +++ b/src/llama-context.cpp @@ -1743,7 +1743,9 @@ int llama_context::decode(const llama_batch & batch_inp) { { // warm the page cache for this batch's per-layer-embedding rows while the first chunk is on the GPU; // posix_fadvise only, so a wrong prediction costs readahead and nothing else extern void qwen4exp_ple_prefetch(const llama_model & model, const llama_token * tokens, int32_t n_tokens); - if (batch_inp.token && batch_inp.n_tokens >= 4096) { qwen4exp_ple_prefetch(model, batch_inp.token, batch_inp.n_tokens); } + if (model.arch == LLM_ARCH_QWEN4EXP && batch_inp.token && batch_inp.n_tokens >= 4096) { + qwen4exp_ple_prefetch(model, batch_inp.token, batch_inp.n_tokens); + } } const uint32_t n_outputs_all = balloc->get_n_outputs(); diff --git a/src/models/qwen4exp.cpp b/src/models/qwen4exp.cpp index 899258ab493e..b1a127d1b546 100644 --- a/src/models/qwen4exp.cpp +++ b/src/models/qwen4exp.cpp @@ -1749,6 +1749,12 @@ void qwen4exp_ple_prefetch(const llama_model & model_base, const llama_token * t if (!tokens || n_tokens < 4096) { return; } + // llama_context::decode calls this for every architecture, so the downcast below is only valid + // once the arch is known: on any other model it reads ple_disk out of an unrelated object and + // dereferences whatever that happens to hold. + if (model_base.arch != LLM_ARCH_QWEN4EXP) { + return; + } const auto & pmodel = static_cast(model_base); if (!pmodel.ple_disk || !pmodel.ple_disk->page_cached()) { return;