概要
前回もご紹介したTensorflow-Directmlに関するエラーについて。
この間久しぶりにTensorflow-Directmlを使ったところ、DXGI_ERROR_DEVICE_REMOVED
というエラーが出て学習前にコケてしまう事態に見舞われた。
Tensorflow-Directml の日本語記事はあまりないので、とりあえずメモ。
まとめ
確認した環境は、RX6900XT, python3.7にtensorflow-directmlの各バージョン。
- 1.15.5.dev210429, 1.15.5.dev210422, 1.15.4.dev201216, 1.15.3.dev200911 といろいろバージョンを試してみたが同じエラーが出てしまった。
対処法は、DMLデバイスを使う前に予め環境変数
TF_DIRECTML_MAX_ALLOC_SIZE
で割り当てるメモリの量を決めておくというもの。
python中で設定するなら、
import os os.environ["TF_DIRECTML_MAX_ALLOC_SIZE"] = "8589934592" # ここの値はデバイスによって適切に書き換える。この例では8GB。
てな感じで環境変数をセットしてからtensorflow-directmlを使うとうまく動くことがわかりました。
多分メモリ確保の量を決定するプロセスでドライバのタイムアウトが起きてしまうために起こるのだと思う(完全なる憶測)。
なので、多分tensorflowのconfig.protoで使用メモリ量を予め決めておいてもこの問題は起きないのではないかと思う(完全なる憶測)。
参考URL
よくRadeonでFF14をやってる人が遭遇する忌々しきDX11の致命的なエラー
の対処法としてお馴染みの、 レジストリのTdrDelay
を調整するやり方もGitHubで提案されていましたが、残念ながらこれでは解決せず。
tensorflow-directml/Troubleshooting-Timeouts.md at directml · microsoft/tensorflow-directml · GitHub
結果的にこちらのページに書いてあるように、環境変数でメモリ量を決めてやると動くことがわかりました。
DXGI_ERROR_DEVICE_REMOVED Error · Issue #95 · microsoft/DirectML · GitHub
エラー出力
_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 2021-06-09 23:21:04.003571: I tensorflow/core/common_runtime/dml/dml_device_cache.cc:185] DirectML: creating device on adapter 0 (AMD Radeon RX 6900 XT) 2021-06-09 23:21:04.181556: I tensorflow/stream_executor/platform/default/dso_loader.cc:99] Successfully opened dynamic library Kernel32.dll 2021-06-09 23:21:08.022165: E tensorflow/core/common_runtime/dml/dml_heap_allocator.cc:53] The DirectML device has encountered an unrecoverable error (DXGI_ERROR_DEVICE_REMOVED). This is most often caused by a timeout occurring on the GPU. Please visit https://aka.ms/tfdmltimeout for more information and troubleshooting steps. 2021-06-09 23:21:08.022265: F tensorflow/core/common_runtime/dml/dml_heap_allocator.cc:53] HRESULT failed with 0x887a0005: hr