- Compiled for Python 3.6.x
- Custom functions written in C++ v14, using
torchv1.x C++ API - Functions bound to a Python module using
pybind11 - Uses
setuptoolsfor building, andpytestfor testing - Implements in C++ a custom LSTM-like layer (forward and backward passes), and plugs it in a regression
model, based on these tutorials:
- https://pytorch.org/tutorials/advanced/cpp_extension.html (PyTorch C++ kernel)
- https://machinelearningmastery.com/building-a-regression-model-in-pytorch/ (PyTorch regression model)
To compile, run
pip install -r requirements.txt
python setup.py buildThis will also install the module torch_kernel in the Python system path.
To run the unit tests, run
pytestTo import the module, import first torch
import torch
import torch_kernelTo train a sample regressor neural network (one LSTM-like layer followed by a linear layer) run:
python applications/custom_nn.pyThis script contains PyTorch classes wrapping up the custom layer. It also shows how to run stochastic gradient descent to update the network weights, and solve a sample Scikit-learn regression problem.