본문 바로가기

Coding/Python

[Tensorflow/Python] LSTM 레이어 사용 시 cuDNN 커널 사용 불가 오류

Tensorflow의 layers.LSTM 클래스는 API 상에서 최적의 속도로 학습이 가능하도록 구현되어있는데, 이 구현이 특정 조건에 국한되어 있다. 이를 변조시키면 레이어 생성 시 다음과 같은 경고 메시지를 출력한다.

 

"WARNING:tensorflow:Layer lstm will not use cuDNN kernels since it doesn't meet the criteria. It will use a generic GPU kernel as fallback when running on GPU."

 

무시하고 실행하게 되면 최적화가 적용되었을 때에 비해 매우 느린 속도로 학습이 진행된다. 특별한 상황이 아니라면 조건을 만족시키도록 하자.

 

최적화 방식으로 구동되는 LSTM 레이어의 조건은 아래와 같다.

 

출처: (https://www.tensorflow.org/api_docs/python/tf/keras/layers/LSTM)

 

The requirements to use the cuDNN implementation are:

activation == tanh
recurrent_activation == sigmoid
recurrent_dropout == 0
unroll is False
use_bias is True
Inputs, if use masking, are strictly right-padded.
Eager execution is enabled in the outermost context.

이 때 활성화 함수(activation func.)가 두 개 존재하는데,

맨 위 activation 항목은 셀 상태에 반영할 후보 텐서와 출력 후보 텐서를 결정하는 node 연산의 활성화 함수이고, 

recurrent_activation 항목은 셀 상태에 반영할 비율을 결정하는 gate 연산의 활성화 함수이다.

 

recurrent_activation은 비율(%)을 결정하는 연산에 사용되므로 시그모이드에서 바꿀 필요가 없을 것이다.

 

LSTM 구성 요소인 메모리 셀 내부 구조
메모리 셀 내부 연산 수식 (미출처: 본 블로그)

LSTM 유닛 내부 구조를 설명하는 위 이미지를 참고하면 이해가 수월하겠다.