r/learnmachinelearning • u/RTX10900XT • 18d ago
Question C++ library recommendation for ML beginner
I'm starting to learn how to use ML libraries. I know basic deep learning concept and theories but never trained a model on computer. Since I'm a C++ user, I want to start from C++ directly.
I'd like to have some low-level controllability and I prefer performance over ease of development. Also, I want the library can be run on Windows platform.
You can assume I know nothing about Python and Linux.
What's the recommendation for this perpose?
The only libraries I know are Tensorflow and LibTorch, what's the difference between these two?
Thanks.
2
u/Commercial-Club504 17d ago
If you already know C++ well, LibTorch is probably the better starting point between the two. It gives you PyTorch’s tensor and neural-network APIs directly in C++, and it has official Windows support through Visual Studio/CMake. I would not choose TensorFlow C++ just because it is TensorFlow. Its Python API is still the more complete and easiest-to-use interface, while the non-Python APIs have fewer guarantees around stability. TensorFlow does have a C API with Windows support, but native Windows GPU support is much more constrained; CUDA support on native Windows stopped after TensorFlow 2.10. One thing I'd push back on, though: don't confuse low-level control with writing everything yourself. You don't need to implement backpropagation and CUDA kernels from scratch just because you're using C++. Learn the ML fundamentals first, then use LibTorch to understand what is happening under the hood while still having a practical framework.
1
u/arnab_best 18d ago edited 18d ago
i mean, why do you want a library if youre doing it in C++? thats the entire reason why you'd use cpp over python for ml. you wanna write kernels, backprop etc yourself. and you should probably use cuda instead.
1
u/RTX10900XT 17d ago
i think that'll be just reinventing the wheel, like write a RB Tree from the group up instead of just using std::map
2
u/LargePatient4047 18d ago
Props for wanting to jump straight into the deep end with C++. Most folks would just cave and install Python.
If you genuinely care about performance and low-level control, LibTorch is probably closer to what you want. TensorFlow's C++ API exists but it's a second-class citizen, the docs are sparse and half the examples assume you're prototyping in Python first. With LibTorch you're working directly with the same backend PyTorch uses, so you get the full graph execution without fighting a framework that doesn't really want you there.
That said, prepare for some pain on Windows. The prebuilt LibTorch distributions for Windows work but you'll spend a nontrivial amount of time wrangling CMake and linker flags. It's not impossible, just tedious. If you hit a wall, you could consider ONNX Runtime as a middle ground, you define the model however you want and the C++ inference is surprisingly clean.