Skip to content

Commit f6ff1b5

Browse files
authored
Merge pull request #29 from acompany-develop/feature/otsuka/add_progress_log
Add simple progress log
2 parents 796d7e6 + bf0b839 commit f6ff1b5

File tree

5 files changed

+92
-4
lines changed

5 files changed

+92
-4
lines changed

src/ComputationContainer/Client/ComputationToDbGate/ValueTable.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "ValueTable.hpp"
22

3+
#include <chrono>
34
#include <unordered_map>
45
#include <unordered_set>
56

@@ -76,7 +77,11 @@ std::vector<std::pair<int, int>> intersectionSortedValueIndex(
7677
// v1, v2がソートされている必要あり
7778
std::vector<std::pair<int, int>> it_list;
7879
it_list.reserve(sorted_v1.size());
80+
7981
size_t i1 = 0, i2 = 0;
82+
std::uint32_t iterated = 0;
83+
spdlog::info("[progress] hjoin: core (0/1)");
84+
auto time_from = std::chrono::system_clock::now();
8085
while (i1 < sorted_v1.size() && i2 < sorted_v2.size())
8186
{
8287
if (sorted_v1[i1] == sorted_v2[i2])
@@ -93,7 +98,25 @@ std::vector<std::pair<int, int>> intersectionSortedValueIndex(
9398
{
9499
++i2;
95100
}
101+
if (++iterated % 10 == 0)
102+
{
103+
auto time_to = std::chrono::system_clock::now();
104+
auto dur = std::chrono::duration_cast<std::chrono::milliseconds>(time_to - time_from);
105+
106+
if (dur.count() >= 5000)
107+
{
108+
double max_progress =
109+
std::max(i1 * 100.0 / sorted_v1.size(), i2 * 100.0 / sorted_v2.size());
110+
spdlog::info("[progress] hjoin: core (0/1): {:>5.2f} %", max_progress);
111+
112+
time_from = time_to;
113+
}
114+
}
96115
}
116+
spdlog::info("[progress] hjoin: core (0/1): {:>5.2f} %", 100.0);
117+
118+
spdlog::info("[progress] hjoin: core (1/1)");
119+
97120
return it_list;
98121
}
99122

src/ComputationContainer/Job/Jobs/LinearRegressionJob.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class LinearRegressionJob : public JobBase<LinearRegressionJob>
6262
const std::vector<std::list<int>> &arg
6363
)
6464
{
65+
spdlog::info("[progress] Linear Regression: learning: pre-processing (0/4)");
6566
// 入力parse
6667
auto [x, y] = parse_table(table, arg);
6768
if (x.empty())
@@ -74,10 +75,18 @@ class LinearRegressionJob : public JobBase<LinearRegressionJob>
7475
auto mat_y = qmpc::Share::ShareMatrix(y);
7576

7677
// w = (X^T * X)^{-1} * X^T * y
78+
spdlog::info("[progress] Linear Regression: learning: mat mul (1/4)");
7779
auto mat_x_trans = mat_x.transpose();
7880
auto mat_mul = (mat_x_trans * mat_x);
81+
82+
spdlog::info("[progress] Linear Regression: learning: mat inverse (2/4)");
7983
auto mat_mul_inv = mat_mul.inverse();
84+
85+
spdlog::info("[progress] Linear Regression: learning: mat mul (3/4)");
8086
auto w = mat_mul_inv * mat_x_trans * mat_y;
87+
88+
spdlog::info("[progress] Linear Regression: learning: post-procesing (4/4)");
89+
8190
return w.transpose().get_row()[0];
8291
}
8392
};

src/ComputationContainer/Model/Models/LinearRegression.hpp

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#pragma once
22

3+
#include <boost/range/adaptor/indexed.hpp>
4+
#include <chrono>
5+
36
#include "Client/ComputationToDbGate/Client.hpp"
47
#include "ConfigParse/ConfigParse.hpp"
58
#include "Model/ModelBase.hpp"
@@ -54,17 +57,42 @@ class LinearRegression : public ModelBase
5457
const std::string &model_param_job_uuid
5558
) const override
5659
{
60+
spdlog::info("[progress] Linear Regression: predict: pre-processing (0/2)");
61+
5762
auto db_client = qmpc::ComputationToDbGate::Client::getInstance();
5863
auto a_str = db_client->readModelparam(model_param_job_uuid);
5964
auto a = std::vector<Share>(a_str.begin(), a_str.end());
6065
auto x = parse_table(table, arg);
6166

6267
std::vector<Share> result;
6368
result.reserve(a.size());
64-
for (const auto &xi : x)
69+
70+
spdlog::info("[progress] Linear Regression: predict: compute (1/2)");
71+
auto time_from = std::chrono::system_clock::now();
72+
for (const auto &xi : boost::adaptors::index(x))
6573
{
66-
result.emplace_back(predict_f(a, xi));
74+
if (xi.index() % 1000 == 0)
75+
{
76+
auto time_to = std::chrono::system_clock::now();
77+
auto dur =
78+
std::chrono::duration_cast<std::chrono::milliseconds>(time_to - time_from);
79+
80+
if (dur.count() >= 5000)
81+
{
82+
spdlog::info(
83+
"[progress] Linear Regression: predict: compute (1/2): {:>5.2f} %",
84+
xi.index() * 100.0 / x.size()
85+
);
86+
time_from = time_to;
87+
}
88+
}
89+
90+
result.emplace_back(predict_f(a, xi.value()));
6791
}
92+
spdlog::info("[progress] Linear Regression: predict: compute (1/2): {:>5.2f} %", 100.0);
93+
94+
spdlog::info("[progress] Linear Regression: predict: post-processing (2/2)");
95+
6896
return result;
6997
}
7098
};

src/ComputationContainer/Model/Models/LogisticRegression.hpp

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#pragma once
22

3+
#include <boost/range/adaptor/indexed.hpp>
4+
#include <chrono>
5+
36
#include "Client/ComputationToDbGate/Client.hpp"
47
#include "ConfigParse/ConfigParse.hpp"
58
#include "Math/Math.hpp"
@@ -62,17 +65,41 @@ class LogisticRegression : public ModelBase
6265
* 3. [1] / ([1] + [E]) を計算する
6366
*/
6467

68+
spdlog::info("[progress] Logistic Regression: predict: pre-processing (0/2)");
6569
auto db_client = qmpc::ComputationToDbGate::Client::getInstance();
6670
auto a_str = db_client->readModelparam(model_param_job_uuid);
6771
auto a = std::vector<Share>(a_str.begin(), a_str.end());
6872
auto x = parse_table(table, arg);
6973

7074
std::vector<Share> result;
7175
result.reserve(a.size());
72-
for (const auto &xi : x)
76+
77+
spdlog::info("[progress] Logistic Regression: predict: compute (1/2)");
78+
auto time_from = std::chrono::system_clock::now();
79+
for (const auto &xi : boost::adaptors::index(x))
7380
{
74-
result.emplace_back(predict_f(a, xi));
81+
if (xi.index() % 1000 == 0)
82+
{
83+
auto time_to = std::chrono::system_clock::now();
84+
auto dur =
85+
std::chrono::duration_cast<std::chrono::milliseconds>(time_to - time_from);
86+
87+
if (dur.count() >= 5000)
88+
{
89+
spdlog::info(
90+
"[progress] Logistic Regression: predict: compute (1/2): {:>5.2f} %",
91+
xi.index() * 100.0 / x.size()
92+
);
93+
time_from = time_to;
94+
}
95+
}
96+
97+
result.emplace_back(predict_f(a, xi.value()));
7598
}
99+
spdlog::info("[progress] Logistic Regression: predict: compute (1/): {:>5.2f} %", 100.0);
100+
101+
spdlog::info("[progress] Logistic Regression: predict: post-processing (2/2)");
102+
76103
return result;
77104
}
78105
};

src/ComputationContainer/Optimizer/SGD.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class SGD : public qmpc::Optimizer::OptInterface
2929
int iterationNum, const interface &f, const std::vector<Share> &theta
3030
) const override
3131
{
32+
spdlog::info("[progress] SGD optimize: remain: {}", iterationNum);
3233
if (iterationNum == 0)
3334
{
3435
return theta;

0 commit comments

Comments
 (0)