hyperdimensional-computing / torchhd

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

Consider allowing the user to choose dot_similarity dtype #158

Closed Zeldax64 closed 9 months ago

Zeldax64 commented 9 months ago

I've been using this library for a while to deploy HDC models with torchscript and one of my requirements is to carefully choose the underlying torch operations used. I noticed that dot_similarity is always executed using torch.get_default_dtype(), which is always float. I managed to solve my issue in a fork by allowing the user to choose the dtype used in dot_similarity of MAP vectors. This change impacts the processor instructions executed when running the models and also their accuracy.

I've been thinking about merging such changes back to the library but they require API changes. For instance, the cosine_similarity would also be changed since it relies on dot_similarity.

mikeheddes commented 9 months ago

Thank you for submitting this feature request. This seems like a useful feature so I am working on adding it (hopefully later today). The reason it currently uses the default dtype is to prevent counter overflows when the dtype of the VSATensor is torch.int8 for example.