Skip to content
Snippets Groups Projects
running_theano.md 2.46 KiB
Newer Older
Adam Caprez's avatar
Adam Caprez committed
+++
title = "Running Theano"
description = "How to run the Theano on HCC resources."
+++
Theano is available on HCC resources via the modules system. Both CPU and GPU
versions are available on Crane.  Additionally, installs for both Python
2.7 and 3.6 are provided.

### Initial Setup

Theano attempts to write to a `~/.theano` directory in some
circumstances, which can cause errors as the `/home` filesystem is
read-only on HCC machines.  As a workaround, create the directory on
`/work` and make a symlink from `/home`:

Adam Caprez's avatar
Adam Caprez committed
{{% panel theme="info" header="Create & symlink .theano directory" %}}
{{< highlight bash >}}
mkdir -p $WORK/.theano
ln -s $WORK/.theano $HOME/.theano
Adam Caprez's avatar
Adam Caprez committed
{{< /highlight >}}
{{% /panel %}}

This only needs to be done once on each HCC machine.

### Running the CPU version

To use the CPU version, simply load the module and run your Python code.
 You can choose between the Python 2.7, 3.5 or 3.6 environments:

Adam Caprez's avatar
Adam Caprez committed
{{% panel theme="info" header="Python 2.7 version" %}}
{{< highlight bash >}}
module load theano/py27/1.0
python my_python2_script.py
Adam Caprez's avatar
Adam Caprez committed
{{< /highlight >}}
{{% /panel %}}
Adam Caprez's avatar
Adam Caprez committed
{{% panel theme="info" header="Python 3.5 version" %}}
{{< highlight bash >}}
module load theano/py35/1.0
python my_python3_script.py
Adam Caprez's avatar
Adam Caprez committed
{{< /highlight >}}
{{% /panel %}}
Adam Caprez's avatar
Adam Caprez committed
{{% panel theme="info" header="Python 3.6 version" %}}
{{< highlight bash >}}
module load theano/py36/1.0
python my_python3_script.py
Adam Caprez's avatar
Adam Caprez committed
{{< /highlight >}}
{{% /panel %}}
Adam Caprez's avatar
Adam Caprez committed
### Running the GPU version

To use the GPU version, first create a `~/.theanorc` file with the
following contents (or append to an existing file as needed):

Adam Caprez's avatar
Adam Caprez committed
{{% panel theme="info" header="~/.theanorc" %}}
{{< highlight batch >}}
Adam Caprez's avatar
Adam Caprez committed
{{< /highlight >}}
{{% /panel %}}

Next, load the theano module:

Adam Caprez's avatar
Adam Caprez committed
{{% panel theme="info" header="Load the theano module" %}}
{{< highlight bash >}}
module load theano/py27/0.9
Adam Caprez's avatar
Adam Caprez committed
{{< /highlight >}}
{{% /panel %}}

To test the GPU support, start an interactive job on a GPU node and
import the theano module within the Python interpreter.  You should see
output similar to the following:

Adam Caprez's avatar
Adam Caprez committed
{{% panel theme="info" header="GPU support test" %}}
{{< highlight python >}}
Python 2.7.15 | packaged by conda-forge | (default, May  8 2018, 14:46:53)
[GCC 4.8.2 20140120 (Red Hat 4.8.2-15)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import theano
Using cuDNN version 7005 on context None
Mapped name None to device cuda: Tesla K20m (0000:03:00.0)
Adam Caprez's avatar
Adam Caprez committed
{{< /highlight >}}
{{% /panel %}}