CUSIM

February 20, 2021 ยท View on GitHub

License Build Status contributions welcome Documentation Status

Superfast CUDA implementation of Word2Vec and Latent Dirichlet Allocation (LDA)

Introduction

This project is to speed up various ML models (e.g. topic modeling, word embedding, etc) by CUDA. It would be nice to think of it as gensim's GPU version project. As a starting step, I implemented the most widely used word embedding model, the word2vec model, and the most representative topic model, the LDA (Latent Dirichlet Allocation) model.

Requirements

  • Python3.6+
  • gcc / g++ (>= 5.1 for c++14)
  • cuda >= 7.0
  • Tested on Ubuntu 18.04 / GCC 7.5 / CUDA 11.1 / Python 3.6

How to install

  • install from pypi
pip install cusim
  • install from source
# clone repo and submodules
git clone git@github.com:js1010/cusim.git && cd cusim && git submodule update --init

# install requirements
pip install -r requirements.txt

# generate proto
python -m grpc_tools.protoc --python_out cusim/ --proto_path cusim/proto/ config.proto

# install
python setup.py install

How to use

  • examples/example_w2v.py, examples/example_lda.py and examples/README.md will be very helpful to understand the usage.
  • paremeter description can be seen in cusim/proto/config.proto

Performance

  • AWS g4dn 2xlarge instance is used to the experiment. (One NVIDIA T4 GPU with 8 vcpus, Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz)
  • results can be reproduced by simply running examples/example_w2v.py and examples/example_lda.py
  • To evaluate w2v model, I used evaluate_word_pairs function (ref link) in gensim, note that better performance on WS-353 test set does not necessarily mean that the model will workbetter in application as desribed on the link. However, it is good to be measured quantitively and fast training time will be at least very objective measure of the performaance.
    • I trained W2V model on quora-duplicate-questions dataset from gensim downloader api on GPU with cusim and compare the performance (both speed and model quality) with gensim.
  • To evaluate LDA model, I found there is no good way to measure the quality of traing results quantitatively. But we can check the model by looking at the top words of each topic. Also, we can compare the training time quantitatively.
  • W2V (skip gram, hierarchical softmax)
attr1 workers (gensim)2 workers (gensim)4 workers (gensim)8 workers (gensim)NVIDIA T4 (cusim)
training time (sec)892.596544.212310.727226.47216.162
pearson0.4878320.4876960.4828210.4871360.492101
spearman0.5008460.5062140.5010480.5067180.479468
  • W2V (skip gram, negative sampling)
attr1 workers (gensim)2 workers (gensim)4 workers (gensim)8 workers (gensim)NVIDIA T4 (cusim)
training time (sec)586.545340.489220.804146.2333.9173
pearson0.3544480.3539520.3523980.3529250.360436
spearman0.3691460.3693650.3705650.3658220.355204
  • W2V (CBOW, hierarchical softmax)
attr1 workers (gensim)2 workers (gensim)4 workers (gensim)8 workers (gensim)NVIDIA T4 (cusim)
training time (sec)250.135155.121103.5773.80736.20787
pearson0.3096510.3218030.3248540.3142550.480298
spearman0.2940470.3087230.3182930.3005910.480971
  • W2V (CBOW, negative sampling)
attr1 workers (gensim)2 workers (gensim)4 workers (gensim)8 workers (gensim)NVIDIA T4 (cusim)
training time (sec)176.923100.36969.782949.92749.90391
pearson0.187720.1931520.2045090.1879240.368202
spearman0.2439750.245870.2605310.2374410.358042
  • LDA (nytimes dataset from https://archive.ics.uci.edu/ml/datasets/bag+of+words)
    • I found that setting workers variable in gensim LdaMulticore does not work properly (it uses all cores in instance anyway), so I just compared the speed between cusim with single GPU and gensim with 8 vcpus.
    • One can compare the quality of modeling by looking at examples/cusim.topics.txt and examples/gensim.topics.txt.
attrgensim (8 vpus)cusim (NVIDIA T4)
training time (sec)447.37676.6972

Future tasks

  • support half precision
  • support multi device (multi device implementation on LDA model will not be that hard, while multi device training on w2v may require some considerations)
  • implement other models such as FastText, BERT, etc
  • contribution is always welcome