Even though the backend of PyTorch is mostly implemented by C++, its frontend API has always been focused on Python. It's partly because Python has already been very popular among data scientists and it has tons of open source packages that help us focus on solving the problems, rather than re-creating the wheel. Also, it's extremely easy to read and write. However, Python is not known for computation and memory resource efficiency. Big companies often develop their own tools in C++ for better performance. But smaller companies or individual developers find it difficult to divert their main focus to developing their own C++ tools. Luckily, PyTorch has now shipped the C++ API. Now, anyone can build efficient projects with it.

Here's an example of how to use the C++ API provided by PyTorch. Let's load the traced model we exported previously:

Get hands-on with 1400+ tech skills courses.