Skip to content

Commit 58b1d46

Browse files
author
Lazy Programmer
committed
add gpu rnn units
1 parent 4a52b07 commit 58b1d46

File tree

7 files changed

+33
-0
lines changed

7 files changed

+33
-0
lines changed

nlp_class3/attention.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
import numpy as np
1717
import matplotlib.pyplot as plt
1818

19+
if len(K.tensorflow_backend._get_available_gpus()) > 0:
20+
from keras.layers import CuDNNLSTM as LSTM
21+
from keras.layers import CuDNNGRU as GRU
22+
1923

2024
# make sure we do softmax over the time axis
2125
# expected shape is N x T x D

nlp_class3/bilstm_mnist.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
import pandas as pd
1414
import matplotlib.pyplot as plt
1515

16+
if len(K.tensorflow_backend._get_available_gpus()) > 0:
17+
from keras.layers import CuDNNLSTM as LSTM
18+
from keras.layers import CuDNNGRU as GRU
19+
1620

1721
def get_mnist(limit=None):
1822
if not os.path.exists('../large_files'):

nlp_class3/bilstm_test.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
import numpy as np
1010
import matplotlib.pyplot as plt
1111

12+
import keras.backend as K
13+
if len(K.tensorflow_backend._get_available_gpus()) > 0:
14+
from keras.layers import CuDNNLSTM as LSTM
15+
from keras.layers import CuDNNGRU as GRU
16+
1217

1318
T = 8
1419
D = 2

nlp_class3/lstm_toxic.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
from keras.optimizers import Adam
2020
from sklearn.metrics import roc_auc_score
2121

22+
import keras.backend as K
23+
if len(K.tensorflow_backend._get_available_gpus()) > 0:
24+
from keras.layers import CuDNNLSTM as LSTM
25+
from keras.layers import CuDNNGRU as GRU
26+
2227

2328
# Download the data:
2429
# https://www.kaggle.com/c/jigsaw-toxic-comment-classification-challenge

nlp_class3/poetry.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
from keras.preprocessing.sequence import pad_sequences
1818
from keras.optimizers import Adam, SGD
1919

20+
import keras.backend as K
21+
if len(K.tensorflow_backend._get_available_gpus()) > 0:
22+
from keras.layers import CuDNNLSTM as LSTM
23+
from keras.layers import CuDNNGRU as GRU
24+
2025

2126
# some configuration
2227
MAX_SEQUENCE_LENGTH = 100

nlp_class3/simple_rnn_test.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
import numpy as np
1010
import matplotlib.pyplot as plt
1111

12+
import keras.backend as K
13+
if len(K.tensorflow_backend._get_available_gpus()) > 0:
14+
from keras.layers import CuDNNLSTM as LSTM
15+
from keras.layers import CuDNNGRU as GRU
16+
1217

1318
T = 8
1419
D = 2

nlp_class3/wseq2seq.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
import numpy as np
1616
import matplotlib.pyplot as plt
1717

18+
import keras.backend as K
19+
if len(K.tensorflow_backend._get_available_gpus()) > 0:
20+
from keras.layers import CuDNNLSTM as LSTM
21+
from keras.layers import CuDNNGRU as GRU
22+
1823

1924
# some config
2025
BATCH_SIZE = 64 # Batch size for training.

0 commit comments

Comments
 (0)