Skip to content

Commit d79ade2

Browse files
committed
Adjust for small vector size
1 parent f184450 commit d79ade2

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/llama-quant.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -885,9 +885,8 @@ static std::unordered_map<std::string, ggml_type> target_bpw_type(
885885
if (n < 50) { return std::accumulate(v.begin(), v.end(), 0.0); }
886886

887887
int64_t k = (int64_t) std::floor(0.02 * (double)n); // trim 2% on each side
888-
k = std::clamp<int64_t>(k, 0, n / 32); // but no more than ~3%
889-
std::nth_element(v.begin(), v.begin() + k, v.end());
890-
std::nth_element(v.begin() + k, v.begin() + (n - k), v.end());
888+
k = std::clamp<int64_t>(k, 0, std::min(n / 32, n / 2 - 1)); // but no more than ~3% or n/2 if small
889+
std::sort(v.begin(), v.end());
891890
return std::accumulate(v.begin() + k, v.begin() + (n - k), 0.0);
892891
};
893892

0 commit comments

Comments
 (0)