Any way to make Stan competitive with Tensorflow for maximum likelihood?

Ah ok, sorry I did misunderstand your question.

I created the data in python and have it in CPU/host memory as a numpy array. If there is a better way to transfer this data into cmdstan then I would love to try it!

As @seantalts points out, fixing that’s on our to-do list. It hasn’t been a priority in the past because bit optimizations are the only place where I/O winds up being a measurable part of run time.

I wrote out 125M double values in ASCII. It took 1.4 GB on disk and takes about 2s to read in on my Mac using an ifstream and <<.

#include <fstream>
#include <iostream>

int main() {
  long I = 125000000l;
  std::string path("/Users/carp/Desktop/foo.csv");

  std::ofstream f;
  f.open(path);
  for (long i = 0; i < I; ++i) {
    double a = i / 3.0;
    f << a;
  }
  f.close();

  std::ifstream g;
  g.open(path);
  double total = 0;
  for (long i = 0; i < I; ++i) {
    double a;
    g >> a;
    total += a;
  }
  g.close();

  std::cout << "total = " << total << std::endl;
}

I think @rok_cesnovar mentioned he was actually working on the JSON reader situation now :)

I think this is the kind of thing that silently bites us in benchmarks - if you just measure how long the process took to execute, you get a number including I/O, and if your incentive is to find settings that maximize your new software’s advantage against Stan you’ll end up choosing large JSON data sets with low iteration counts to exacerbate that advantage. I bet this has already happened a bunch…

2 Likes

I have a PR up https://github.com/stan-dev/stan/pull/2793
Also see the related issue.

Its marked WIP but I am mostly waiting for a green light that this is acceptable before I start cleaning up and optimizing. Tadej suggested to try simdjson, will try today just to see if its worth the hype.

EDIT: simdjson is not suitable, assumes you have a C++17 compiler, so if anyone has time to look a the questions posted in the PR, that would be much appreciated.

For a 200MB JSON we get from 35s to 2.5s with RapidJSON and for the 2GB we get from 350s to 25s on my system. For the latter file ujson in python takes 30s.

6 Likes