mirror of
https://github.com/Lizonghang/prima.cpp.git
synced 2025-09-06 07:19:04 +00:00
fix: enable rolling back set assignment when all devices are assigned to M4 but no feasible solutions
This commit is contained in:
parent
6439090920
commit
27756ee182
1 changed files with 39 additions and 10 deletions
|
@ -1094,8 +1094,8 @@ static bool assign_layers_to_device(
|
||||||
};
|
};
|
||||||
(void)print_matrix;
|
(void)print_matrix;
|
||||||
|
|
||||||
std::vector<double> final_solution;
|
std::vector<double> final_solution, rollback_solution;
|
||||||
int final_k = -1;
|
int final_k = -1, rollback_k = -1;
|
||||||
|
|
||||||
// iterative optimization to find a valid set assignment (M1, M2, M3, M4)
|
// iterative optimization to find a valid set assignment (M1, M2, M3, M4)
|
||||||
while (true) {
|
while (true) {
|
||||||
|
@ -1367,20 +1367,49 @@ static bool assign_layers_to_device(
|
||||||
|
|
||||||
// get the solution
|
// get the solution
|
||||||
const HighsModelStatus& model_status = highs.getModelStatus();
|
const HighsModelStatus& model_status = highs.getModelStatus();
|
||||||
if (model_status != HighsModelStatus::kOptimal) continue;
|
|
||||||
|
if (model_status != HighsModelStatus::kOptimal) {
|
||||||
|
bool is_all_in_M4 = true;
|
||||||
|
for (uint32_t m = 0; m < n_world; ++m) {
|
||||||
|
if (!in_set(m, M4)) {
|
||||||
|
is_all_in_M4 = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!is_all_in_M4) continue;
|
||||||
|
}
|
||||||
|
|
||||||
// record the best solution
|
// record the best solution
|
||||||
const HighsSolution& solution = highs.getSolution();
|
const HighsSolution& solution = highs.getSolution();
|
||||||
double objective_value = highs.getInfo().objective_function_value;
|
double objective_value = highs.getInfo().objective_function_value;
|
||||||
|
|
||||||
|
if (solution.value_valid) {
|
||||||
if (objective_value < best_objective) {
|
if (objective_value < best_objective) {
|
||||||
best_objective = objective_value;
|
best_objective = objective_value;
|
||||||
best_k = k;
|
best_k = k;
|
||||||
best_solution = solution.col_value;
|
best_solution = solution.col_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_INF("k = %2d, obj = %7.1f, solution: %s | best_k = %2d, best_obj = %7.1f, best_solution: %s\n",
|
LOG_INF("k = %2d, obj = %7.1f, solution: %s | best_k = %2d, best_obj = %7.1f, best_solution: %s\n",
|
||||||
k, objective_value, vec_to_str(solution.col_value).c_str(), best_k, best_objective, vec_to_str(best_solution).c_str());
|
k, objective_value, vec_to_str(solution.col_value).c_str(), best_k, best_objective, vec_to_str(best_solution).c_str());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (best_solution.empty()) {
|
||||||
|
LOG_INF("No feasible solution found for this set assignment, rolling back to previous sets.\n");
|
||||||
|
|
||||||
|
final_solution = rollback_solution;
|
||||||
|
final_k = rollback_k;
|
||||||
|
|
||||||
|
// update w[m] and n[m]
|
||||||
|
GGML_ASSERT(final_solution.size() == n_world * 2 && "Invalid solution\n");
|
||||||
|
std::copy(final_solution.begin(), final_solution.begin() + n_world, w.begin());
|
||||||
|
std::copy(final_solution.begin() + n_world, final_solution.end(), n.begin());
|
||||||
|
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
rollback_solution = best_solution;
|
||||||
|
rollback_k = best_k;
|
||||||
|
}
|
||||||
|
|
||||||
// check the solution
|
// check the solution
|
||||||
bool has_free_gpu_memory = false, has_gpu_overload = false, has_cpu_overload = false;
|
bool has_free_gpu_memory = false, has_gpu_overload = false, has_cpu_overload = false;
|
||||||
|
|
Loading…
Add table
Reference in a new issue