in astra-sim-alibabacloud/astra-sim/system/AstraParamParse.hh [101:157]
void parseYaml(NetWorkParam& params, const std::string& filename) {
std::ifstream file(BUSBW_PATH + filename);
if (!file) {
std::cerr << "Unable to open file: " << filename << std::endl;
exit(-1);
}
std::string line;
std::string currentSection;
std::getline(file, line);
while (std::getline(file, line)) {
// Remove whitespace
line.erase(0, line.find_first_not_of(' '));
line.erase(line.find_last_not_of(' ') + 1);
if (line.empty() || line[0] == '#') continue;
if (line.back() == ':') {
currentSection = line.substr(0, line.size() - 1);
} else {
std::istringstream ss(line);
std::string key, valueStr;
if (std::getline(ss, key, ':') && ss >> valueStr) {
key.erase(key.find_last_not_of(' ') + 1);
// Remove part after comma
auto commaPos = key.find(',');
if (commaPos != std::string::npos) {
key = key.substr(0, commaPos);
}
if (valueStr != "null") {
float value = std::stof(valueStr);
if (currentSection == "TP") {
if (key == "allreduce") params.tp_ar = value;
else if (key == "allgather") params.tp_ag = value;
else if (key == "reducescatter") params.tp_rs = value;
else if (key == "alltoall") params.tp_ata = value;
} else if (currentSection == "DP") {
if (key == "allreduce") params.dp_ar = value;
else if (key == "allgather") params.dp_ag = value;
else if (key == "reducescatter") params.dp_rs = value;
else if (key == "alltoall") params.dp_ata = value;
} else if (currentSection == "EP") {
if (key == "allreduce") params.ep_ar = value;
else if (key == "allgather") params.ep_ag = value;
else if (key == "reducescatter") params.ep_rs = value;
else if (key == "alltoall") params.ep_ata = value;
} else if (currentSection == "PP") {
if (key == "busbw") params.pp = value;
}
}
}
}
}
}