Tensors and neural networks in Haskell
Haskell C Other
Switch branches/tags
Nothing to show
Clone or download

README.md

hasktorch

Build Status

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 that 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).

Project Organization

In order of high-to-low level. The reverse order can also be seen in the cabal.project file.

Directory Description
examples/ Examples of basic usage and experimental prototypes from a simple hasktorch-core dependency
core/ Reexports of all typeclasses (see classes/) and instances (see indef/)
dimensions/ Reexports and helpers of the dimensions library
classes/ Typeclasses and helpers which consist of a user-friendly Haskell API
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
raw/ Comprehensive raw bindings to C operations (TH, THNN, THC, THCUNN)
codegen/ Code generation to produce low-level raw Haskell bindings
output/ Staging directory for codegen/ output, contents should not be under source control
vendor/ 3rd party dependencies as git submodules (links to ATen and, possibly, other libraries)

Build Instructions

Currently hasktorch only supports OSX and Linux builds because these are what the development team works on -- if you would like to add *BSD or Windows support, please let us know!

Building Hasktorch requires retrieving and building a fork of pytorch's ATen library dependency. Currently (04/12/2018), we fork ATen to reintroduce some C-native broadcasting functionality which was moved to ATen's C++ core. This step has been condensed in our Makefile as make init.

Following this, you will need cabal-install > 2.0 for new-build and backpack support. If you would like to new-run the examples on the command line (instead of dropping into a new-repl) you will need to build off of the cabal's head (here's the current commit). If this seems intimidating, wait for backpack support in stack.

Ensure that libATen.so is on your library path. This can be done by sourcing the setenv file or configuring cabal from ~/.cabal/config. Now you can build hasktorch:

cabal new-build all
cabal new-run static-tensor-usage

For more development tips, see DEVELOPERS.md and review the vendor/ readme for details on external dependencies.

Getting started

For an example of basic end-user API usage, see the statically typed tensor usage example and the example of simple gradient descent.

For details on implementation and usage of raw C bindings and the core library, refer to their respective README documentation in raw/ and core/ package directories. Additional examples can be found in examples/ as well as the test modules.

Contributing

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 find our contact information by digging through cabal files or you can ping us on gitter in the DataHaskell Lobby.

Thanks

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.