| 11 | |
| 12 | |
| 13 | int mode_model_sum(int argc, const char* argv[]) { |
| 14 | TVector<TString> modelPaths; |
| 15 | TVector<double> modelWeights; |
| 16 | TVector<TString> modelParamsPrefixes; |
| 17 | TString outputModelPath; |
| 18 | EModelType outputModelFormat = EModelType::CatboostBinary; |
| 19 | ECtrTableMergePolicy ctrMergePolicy = ECtrTableMergePolicy::IntersectingCountersAverage; |
| 20 | |
| 21 | auto parser = NLastGetopt::TOpts(); |
| 22 | parser.AddHelpOption(); |
| 23 | parser.AddLongOption('m', "model", "Model path with default weight 1.0") |
| 24 | .Handler1T<TString>([&modelPaths, &modelWeights](const TString& modelPath) { |
| 25 | modelPaths.emplace_back(modelPath); |
| 26 | modelWeights.emplace_back(1.0); |
| 27 | }); |
| 28 | parser.AddLongOption("model-with-weight", "Model path with custom weight") |
| 29 | .RequiredArgument("PATH=WEIGHT") |
| 30 | .Handler1T<TStringBuf>([&modelPaths, &modelWeights](auto path_weight) { |
| 31 | TStringBuf path, weight; |
| 32 | if (!path_weight.TryRSplit('=', path, weight)) { |
| 33 | throw NLastGetopt::TUsageException() << "bad option value `" << path_weight << "`, expected PATH=WEIGHT"; |
| 34 | } |
| 35 | modelPaths.emplace_back(path); |
| 36 | modelWeights.emplace_back(FromString<double>(weight)); |
| 37 | }); |
| 38 | parser.AddLongOption("model-with-weight-and-prefix", "Model path with custom weight and params prefix") |
| 39 | .RequiredArgument("PATH,WEIGHT,PREFIX") |
| 40 | .Handler1T<TStringBuf>([&modelPaths,&modelWeights,&modelParamsPrefixes](auto path_weight_prefix) { |
| 41 | TStringBuf path, weight, paramsPrefix; |
| 42 | Split(path_weight_prefix, ',', path, weight, paramsPrefix); |
| 43 | modelPaths.emplace_back(path); |
| 44 | modelWeights.emplace_back(FromString<double>(weight)); |
| 45 | modelParamsPrefixes.emplace_back(paramsPrefix); |
| 46 | }); |
| 47 | parser.AddLongOption('o', "output-path") |
| 48 | .Required() |
| 49 | .RequiredArgument("PATH") |
| 50 | .StoreResult(&outputModelPath); |
| 51 | parser.AddLongOption("output-model-format") |
| 52 | .OptionalArgument("output model format") |
| 53 | .Handler1T<TString>([&outputModelFormat](const TString& format) { |
| 54 | outputModelFormat = FromString<EModelType>(format); |
| 55 | }); |
| 56 | parser.AddLongOption("ctr-merge-policy", |
| 57 | TString::Join( |
| 58 | "One of ", |
| 59 | GetEnumAllNames<ECtrTableMergePolicy>())) |
| 60 | .Optional() |
| 61 | .StoreResult(&ctrMergePolicy); |
| 62 | parser.SetFreeArgsNum(0); |
| 63 | NLastGetopt::TOptsParseResult parserResult{&parser, argc, argv}; |
| 64 | TVector<THolder<TFullModel>> models; |
| 65 | TVector<const TFullModel*> modelPtrs; |
| 66 | for (const auto& path : modelPaths) { |
| 67 | models.emplace_back(MakeHolder<TFullModel>(ReadModel(path))); |
| 68 | modelPtrs.emplace_back(models.back().Get()); |
| 69 | } |
| 70 | TFullModel result = SumModels(modelPtrs, modelWeights, modelParamsPrefixes, ctrMergePolicy); |
nothing calls this directly
no test coverage detected