r/cpp • u/just_some_bodie • Apr 16 '21
Flashlight - A C++ standalone library for machine learning. Open-sourced by Facebook.
https://github.com/flashlight/flashlight33
23
u/Flibidy_Dibidy Apr 17 '21
So how does this library compare to libtorch? Why would one choose one over the other?
8
u/rotzak Apr 17 '21
Definitely had to do a double-take when I saw there was a C++ standalone library for machine learning called "fleshlight." Thanks Reddit.
7
u/Axelwickm Apr 17 '21
As someone who's currently stuck using LibTorch, which isn't exactly robust, and where errors mostly only get caught during runtime, I am really happy to see tools like this starting to come out. I'm a bit surprised it doesn't seem to have any TorchScript or other integration with PyTorch, considering they're both from Facebook.
5
u/reduced_space Apr 17 '21
Unfortunately the alternative to the runtime errors are libraries like Eigen.
For the most part, libtorch is well written and well tested code. Most of its code base comes from torch7, which is written in C and has a Lua wrapper (interestingly the predecessor to that was written in c++).
Design-wise, ATen, the library libtorch is built around (which in turn is based on the torch7 C code) follows the Python wrapper. It makes sense why they did that, but doesn’t always make for a good C++ experience. Also their documentation still is not great.
This looks interesting, and though digging into the conv2d code, interfacing with the arrayfire library looks a little hairy (they have to construct a dict to pass parameters?). Design-wise it doesn’t look radically different from torch.
1
30
u/just_some_bodie Apr 16 '21
If you like this, I do a weekly roundup of open source projects that includes an interview with one of the devs you can subscribe to.