From 374bfd43634e2ab2b42957243fa0a8295dd8de99 Mon Sep 17 00:00:00 2001 From: ddh0 Date: Thu, 11 Dec 2025 14:22:58 -0600 Subject: [PATCH] explicitly clamp `min_target` and `max_target` to `[0.0, 1.0]` --- src/llama-sampling.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/llama-sampling.cpp b/src/llama-sampling.cpp index fb488acffe..eacad79448 100644 --- a/src/llama-sampling.cpp +++ b/src/llama-sampling.cpp @@ -2334,8 +2334,9 @@ static const char * llama_sampler_power_law_name(const struct llama_sampler * /* static void llama_sampler_power_law_apply(struct llama_sampler * smpl, llama_token_data_array * cur_p) { auto * ctx = (llama_sampler_power_law *) smpl->ctx; - const float min_target = ctx->target - ctx->target_range; - const float max_target = ctx->target + ctx->target_range; + // clamp the target range to [0.0, 1.0] + const float min_target = std::max(ctx->target - ctx->target_range, 0.0f); + const float max_target = std::min(ctx->target + ctx->target_range, 1.0f); // compute probabilities to get the "original" values llama_sampler_softmax_impl(cur_p, false);