Browse Source

Bug fix: ETA time

Summary:
Thank you very much for the great package. I did notice that when training the ETA is very innacurate. I propose a minor change to make this more accurate.

https://github.com/facebookresearch/fastText/issues/500
Closes https://github.com/facebookresearch/fastText/pull/501

Differential Revision: D7830309

Pulled By: EdouardGrave

fbshipit-source-id: 7f15200697725f667725284a6b54387f06c921a7
Dom Hudson 7 years ago
parent
commit
eefbf9580b
2 changed files with 11 additions and 8 deletions
  1. 10 7
      src/fasttext.cc
  2. 1 1
      src/fasttext.h

+ 10 - 7
src/fasttext.cc

@@ -239,18 +239,21 @@ void FastText::loadModel(std::istream& in) {
 }
 
 void FastText::printInfo(real progress, real loss, std::ostream& log_stream) {
-  // clock_t might also only be 32bits wide on some systems
-  double t = double(clock() - start_) / double(CLOCKS_PER_SEC);
+  std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now();
+  double t = std::chrono::duration_cast<std::chrono::duration<double>> (end - start_).count();
   double lr = args_->lr * (1.0 - progress);
   double wst = 0;
-  int64_t eta = 720 * 3600; // Default to one month
+
+  int64_t eta = 2592000; // Default to one month in seconds (720 * 3600)
+
   if (progress > 0 && t >= 0) {
-    eta = int(t / progress * (1 - progress) / args_->thread);
-    wst = double(tokenCount_) / t;
+    progress = progress * 100;
+    eta = t * (100 - progress) / progress;
+    wst = double(tokenCount_) / t / args_->thread;
   }
   int32_t etah = eta / 3600;
   int32_t etam = (eta % 3600) / 60;
-  progress = progress * 100;
+
   log_stream << std::fixed;
   log_stream << "Progress: ";
   log_stream << std::setprecision(1) << std::setw(5) << progress << "%";
@@ -682,7 +685,7 @@ void FastText::train(const Args args) {
 }
 
 void FastText::startThreads() {
-  start_ = clock();
+  start_ = std::chrono::steady_clock::now();
   tokenCount_ = 0;
   loss_ = -1;
   std::vector<std::thread> threads;

+ 1 - 1
src/fasttext.h

@@ -46,7 +46,7 @@ class FastText {
   std::atomic<int64_t> tokenCount_;
   std::atomic<real> loss_;
 
-  clock_t start_;
+  std::chrono::steady_clock::time_point start_;
   void signModel(std::ostream&);
   bool checkModel(std::istream&);