UbuntuがGPUを見失った時の作業履歴

Tensorflowのスクリプトを実行しようとしたところ、以下のようなエラーが出る。

InvalidArgumentError (see above for traceback): Cannot assign a device for operation 'Gs/Run/Gs/4x1/Conv/Reshape': Operation was explicitly assigned to /device:GPU:0 but available devices are [ /job:localhost/replica:0/task:0/device:CPU:0 ]. Make sure the device specification refers to a valid device.

         [[Node: Gs/Run/Gs/4x1/Conv/Reshape = Reshape[T=DT_FLOAT, Tshape=DT_INT32, _device="/device:GPU:0"](Gs/4x1/Conv/bias/read, Gs/Run/Gs/4x1/Conv/Reshape/shape)]]

GPUがちゃんと認識されているかどうかを、以下のコマンドで確認。

$ nvidia-smi
NVIDIA-SMI has failed because it couldn't communicate with the NVIDIA driver. Make sure that the latest NVIDIA driver is installed and running.

再起動しても同様の現象だったので、少し調査する。

qiita.com

ありがたくも、同様の症状の解決策を公開している方に遭遇。 参考に、以下のコマンドで使用可能なバージョンを確認した。

$ uname -r
4.15.0-42-generic

$ grep menuentry /boot/grub/grub.cfg

4.15系がデフォルトであった。4.13に戻してみる。

$ sudo vim /etc/default/grub
GRUB_DEFAULT="Advanced options for Ubuntu>Ubuntu, with Linux 4.13.0-45-generic"

と変更。

$ sudo update-grub
$ sudo reboot

変更を反映して再起動した。

$ uname -r
4.13.0-45-generic
$ nvidia-smi
Mon Dec 17 16:26:06 2018       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 387.34                 Driver Version: 387.34                    |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  GeForce GTX 108...  Off  | 00000000:65:00.0 Off |                  N/A |
| 44%   31C    P5    44W / 250W |      0MiB / 11170MiB |      1%      Default |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|  No running processes found                                                 |
+-----------------------------------------------------------------------------+

引用元では、4.13で不具合がおきていたが、私の環境では4.13に戻すことで解決しました。 少しずつカーネルのバージョンを戻していくというアプローチが良さそうです。