hyperdimensional-computing / torchhd

Torchhd is a Python library for Hyperdimensional Computing and Vector Symbolic Architectures
https://torchhd.readthedocs.io
MIT License
233 stars 24 forks source link

improve ngrams performance #33

Closed aglinxinyuan closed 2 years ago

mikeheddes commented 2 years ago

Thanks for your pull request! I appreciate the effort you put into trying all the different versions. If it’s not too much work do you mind sharing code snippets for all the different versions you tried and their execution time? You can just post them as a comment in this PR. I’m curious to see the data. I will try out your pr tomorrow and merge it if it works.

mikeheddes commented 2 years ago

I tested it locally and it is indeed faster, from 200 usec down to 150 usec. However, PyTorch discourages the usage of in-place operations because it can interfere with autograd. By replacing the in-place multiply operations with bind() the execution is still faster at 175 usec.

I will go ahead and merge this and then I will update the implementation to use bind() instead of the in-place multiply.

mikeheddes commented 2 years ago

I tested it locally and it is indeed faster, from 200 usec down to 150 usec. However, PyTorch discourages the usage of in-place operations because it can interfere with autograd. By replacing the in-place multiply operations with bind() the execution is still faster at 175 usec.

I will go ahead and merge this and then I will update the implementation to use bind() instead of the in-place multiply.