Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable GPU #54

Open
heeh opened this issue Nov 5, 2020 · 1 comment
Open

Enable GPU #54

heeh opened this issue Nov 5, 2020 · 1 comment

Comments

@heeh
Copy link

heeh commented Nov 5, 2020

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

@nvanva
Copy link

nvanva commented Feb 11, 2021

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 :((

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants