open-sesame icon indicating copy to clipboard operation
open-sesame copied to clipboard

Enable GPU

Open heeh opened this issue 3 years ago • 1 comments

The program uses CPU when training. How could I enable GPU?

heeh avatar Nov 05 '20 14:11 heeh

Recently I have managed to make it work on GPU. Though it was not easy... Basically, you shall install DyNet with GPU support. Then run your script with --dynet-gpu option which tells DyNet to run calculations on GPU (as described in https://dynet.readthedocs.io/en/latest/python.html#installing-a-cutting-edge-and-or-gpu-version).

Now, step-by-step instructions:

  1. Install DyNet with GPU support. This was the most difficult part. To achieve this, I had to install old CUDA 10.0, old gcc 7.3 and run: CUDNN_ROOT=/path/to/cudnn BACKEND=cuda pip install git+https://github.com/clab/dynet#egg=dynet

  2. Add --dynet-gpu flag to the command line arguments of OptionParser, otherwise OptionParser will report unsupported argument and exit. For instance, I've added to sesame/targetid.py the following line: optpr.add_option("--config", type="str", metavar="FILE") +optpr.add_option("--dynet-gpu")

  3. Finally, I had an error telling me that log_softmax operation does not have GPU implementation in DyNet. So had to move it to the CPU:

  •    score_i = dy.to_device(score_i, 'CPU')
       logloss = log_softmax(score_i, [0, 1])
    

After these steps training started utilizing GPU. But... seems it became even slower than on CPU. Probably, need some code optimization to improve performance on GPU :((

nvanva avatar Feb 11 '21 15:02 nvanva