Hasktorch is a library for tensors and neural networks in Haskell. It is an independent open source community project which leverages the core C libraries shared by Torch and PyTorch. This library leverages cabal new-build and backpack.
Note: This project is in early development and should only be used by contributing developers. Expect substantial changes to the library API as it evolves. Contributions and PRs are welcome (see details below).
Directory | Description |
---|---|
examples/ |
Examples of basic usage and experimental prototypes (recommended starting point) |
zoo/ |
Beginnings of a model zoo |
hasktorch/ |
Reexports of the high-level interface to basic tensor creation and math operations and manages allocation/deallocation via foreign pointers |
indef/ |
Orphan instances of the above typeclasses for the relevant backpack signatures |
signatures/ |
Backpack signatures which line up with the generated C-FFI |
types/ |
Memory-managed tensors and core data types that satisfy global and type-specific backpack types |
ffi/ |
Submodule for low-level C ffi |
Due to the Torch Aten C++ library dependency and use of new cabal functionality with backpack, the setup process can be a bit more involved than a typical haskell library. Don't hesitate to reach out to the development team for questions or issues with getting setup (see "Contributing" below).
Currently hasktorch only supports OSX and Linux builds -- if you would like to add *BSD or Windows support, please let us know!
To get started building and testing the library:
- Run
make init
which uses the Makefile to build PyTorch's ATen library dependency.
- Install cabal-install > 2.2 for
new-build
and backpack support if it is not already installed. We would like to support stack in the future, but that is pending the completion of backpack support in stack. Note stack can still be used as an installer for a new version of cabal-install usingstack install cabal-install --resolver lts-12.21
.
- Build Hasktorch and run an example:
cabal new-build all
cabal new-run static-tensor-usage
To build without GPU support/CUDA, use:
cabal new-build all --flags=-cuda
cabal new-run static-tensor-usage --flags=-cuda
To launch a repl with a project (static-tensor-usage
example here), use:
cabal new-repl static-tensor-usage
For examples of basic end-user API usage, see statically typed tensor usage and simple linear regression using backprop.
Additional examples can be found in examples/
as well as the test modules.
We welcome new contributors. For a rough list of outstanding items on deck (there are many places to contribute), refer to:
https://github.com/hasktorch/hasktorch/projects/1
Contact Austin Huang or Sam Stites for access to the hasktorch slack channel. You can send an email to [email protected], ping us on gitter in the DataHaskell Lobby, or on twitter as @austinvhuang and @SamStites.
Thanks to all hasktorch developers who have contributed to this community effort so far. This project is also indebted to prior work on typed functional programming for deep learning by Justin Le , Edward Yang , Huw Campbell , Kaixi Ruan , and Khanh Nguyen , as well as to the Torch and PyTorch dev teams.