Counting 3,319 Big Data & Machine Learning Frameworks, Toolsets, and Examples...
Suggestion? Feedback? Tweet @stkim1

Last Commit
Nov. 16, 2018
Sep. 9, 2017


Stable Status Development 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
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
zoo/ Beginnings of a model zoo

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.

Now you can build hasktorch:

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

For more development tips, see and review the [vendor/][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/][raw] and [core/][core] package directories. 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:

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

Latest Releases
 Nov. 2 2018