Skip to content

Commit 814f6b6

Browse files
committed
Minor general refactoring
1 parent 0d5f183 commit 814f6b6

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

src/llama-quant.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,8 @@ static std::unordered_map<std::string, ggml_type> target_bpw_type(
860860
const int64_t n = (int64_t)v.size();
861861
if (n == 0) { return 0.0; }
862862
if (n < 50) { return std::accumulate(v.begin(), v.end(), 0.0); }
863-
int64_t k = (int64_t) std::floor(0.02 * (double) n); // trim 2% on each side
863+
864+
int64_t k = (int64_t) std::floor(0.02 * (double)n); // trim 2% on each side
864865
k = std::clamp<int64_t>(k, 0, n / 32); // but no more than ~3%
865866
std::nth_element(v.begin(), v.begin() + k, v.end());
866867
std::nth_element(v.begin() + k, v.begin() + (n - k), v.end());
@@ -1190,7 +1191,7 @@ static std::unordered_map<std::string, ggml_type> target_bpw_type(
11901191
// Pareto by bytes -> error
11911192
std::vector<candidate_types> pareto;
11921193
pareto.reserve(candidates.size());
1193-
double best_err = std::numeric_limits<double>::infinity();
1194+
double best_err = infinity;
11941195
size_t last_b = std::numeric_limits<size_t>::max();
11951196
for (const auto & c : candidates) {
11961197
if (c.bytes != last_b) {
@@ -1273,12 +1274,10 @@ static std::unordered_map<std::string, ggml_type> target_bpw_type(
12731274

12741275
if (budget_bytes <= min_bytes) {
12751276
for (auto & ti : all) { ti.choice = 0; }
1276-
12771277
return emit_overrides();
12781278
}
12791279
if (budget_bytes >= max_bytes) {
12801280
for (auto & ti : all) { ti.choice = (int) ti.candidate.size() - 1; }
1281-
12821281
return emit_overrides();
12831282
}
12841283

@@ -1327,14 +1326,10 @@ static std::unordered_map<std::string, ggml_type> target_bpw_type(
13271326
int expand = 0;
13281327
while (true) {
13291328
lagrange_penalty(mu_hi, choice_hi, bytes_hi, err_hi);
1330-
if (bytes_hi <= budget_bytes) {
1331-
break;
1332-
}
1329+
if (bytes_hi <= budget_bytes) { break; }
13331330

13341331
mu_hi *= 2.0;
1335-
if (++expand > 60) {
1336-
break;
1337-
}
1332+
if (++expand > 60) { break; } // safety cap
13381333
}
13391334
}
13401335

0 commit comments

Comments
 (0)