Link Search Menu Expand Document

Torch-HD lives here

Torch-HD is a library that provides optimized implementations of various Hyperdimensional Computing functions using both GPUs and CPUs. The package also provides HD based ML functions for classification tasks.

Get started now View it on GitHub

Getting started

Torch-HD builds on top of PyTorch and follows its semantics closely. You would use most components of this library as layers just like how you do in PyTorch except for the functional implementation.


Torch-HD does not support multi-gpu training or testing yet. This is due to a limitation of pytorch which prevents us from averaging the weights during training. If anyone knows workarounds or a way to implement this please create a pull request or contact me.


Installation is straightforward. Simply use pip to install the pacakge.

pip3 install torch-hd

Requires python 3.6+ and PyTorch 1.8.2 or later.

Quick start: Encode and decode a vector using ID-Level encoding

from torch_hd import hdlayers as hd

codec = hd.IDLevelCodec(dim_in = 5, D = 10000, qbins = 8, max_val = 8, min_val = 0)
testdata = torch.tensor([0, 4, 1, 3, 0]).type(torch.float)
out = codec(testdata)



tensor([[0., 4., 1., 3., 0.]])
tensor([[0., 4., 1., 3., 0.]])

Functionalities available

Currently Torch-HD supports 3 different encoding methodologies:

  • Random Projection Encoding
  • ID-Level Encoding
  • Selective Kanerva Coding
  • Pact quantization

Apart from encoding functionalities, the library also provides a HD classifier which can be used for training and inference on classification tasks. The package also includes utility functions for training, testing and creating dataloaders.

Coming soon

  • [] Implement fractional-binding
  • Utility functions for training and validation
  • Different VSA architectures
    • [] Multiply-Add-Permute (MAP) - real, binary and integer vector spaces
    • [] Holographic Reduced Representations (HRR)
    • [] HRR in Frequency domain (FHRR)
  • Functional implementations of
    • [] binding
    • [] unbinding
    • [] bundling


Contributions to help improve the implementation are welcome. Please create a pull request on the repo or report issues. Feel free to email me at