# NetTrain TargetDevice GPU error

**URL:** <https://community.wolfram.com/t/nettrain-targetdevice-gpu-error/9032>\
**Category:** Questions\
**Tags:** data-science, high-performance-computing, machine-learning, neural-networks\
**Created:** [August 9, 2016, 9:51pm UTC](https://community.wolfram.com/t/nettrain-targetdevice-gpu-error/9032 "2016-08-09T21:51:12Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![gijsbertwiesenekker](https://avatars.discourse-cdn.com/v4/letter/g/90db22/32.png) [@gijsbertwiesenekker](https://community.wolfram.com/u/gijsbertwiesenekker)\
**Post date:** [August 9, 2016, 9:51pm UTC](https://community.wolfram.com/t/nettrain-targetdevice-gpu-error/9032/1 "2016-08-09T21:51:12Z")

</div>

When I add the option `TargetDevice->"GPU"` to NetTrain in Mathematica 11.0.0.0 I get the error ‘First argument to NetTrain should be a fully specified net’. Is this broken in 11.0.0.0?

---

<div class="post-metadata">

**Author:** ![sebastianb](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/sebastianb/32/36523_2.png) [@sebastianb](https://community.wolfram.com/u/sebastianb)\
**Post date:** [August 10, 2016, 8:49am UTC](https://community.wolfram.com/t/nettrain-targetdevice-gpu-error/9032/2 "2016-08-10T08:49:06Z")

</div>

Can you post your full example that you think should be working? Its impossible to debug this without more information.

---

<div class="post-metadata">

**Author:** ![gijsbertwiesenekker](https://avatars.discourse-cdn.com/v4/letter/g/90db22/32.png) [@gijsbertwiesenekker](https://community.wolfram.com/u/gijsbertwiesenekker)\
**Post date:** [August 10, 2016, 11:44am UTC](https://community.wolfram.com/t/nettrain-targetdevice-gpu-error/9032/3 "2016-08-10T11:44:05Z")

</div>

Hi,

I first tried the following example available on the Wolfram website:

> **[Accelerate Training Using a GPU: New in Wolfram Language 11](https://www.wolfram.com/language/11/neural-networks/accelerate-training-using-a-gpu.html?product=mathematica)**

That failed, so I then tried to modify the following example that is also available on the Wolfram website:

> **[Digit Classification: New in Wolfram Language 11](https://www.wolfram.com/language/11/neural-networks/digit-classification.html?product=mathematica)**

It works until you modify the NetTrain command and add TargetDevice-\>“GPU”. That results in the same error.

GW

---

<div class="post-metadata">

**Author:** ![sebastianb](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/sebastianb/32/36523_2.png) [@sebastianb](https://community.wolfram.com/u/sebastianb)\
**Post date:** [August 10, 2016, 12:06pm UTC](https://community.wolfram.com/t/nettrain-targetdevice-gpu-error/9032/4 "2016-08-10T12:06:03Z")

</div>

Again, can you post the code that is failing for your example?

Also, what is the failure message with your “I first tried the following example available on the Wolfram website” example?

---

<div class="post-metadata">

**Author:** ![gijsbertwiesenekker](https://avatars.discourse-cdn.com/v4/letter/g/90db22/32.png) [@gijsbertwiesenekker](https://community.wolfram.com/u/gijsbertwiesenekker)\
**Post date:** [August 10, 2016, 2:44pm UTC](https://community.wolfram.com/t/nettrain-targetdevice-gpu-error/9032/5 "2016-08-10T14:44:07Z")

</div>

I have attached the second example as a Notebook. It works as designed without TargetDevice-\>“GPU”, but fails if you specify that option.

GW

---

<div class="post-metadata">

**Author:** ![seanc](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/seanc/32/34005_2.png) [@seanc](https://community.wolfram.com/u/seanc)\
**Post date:** [August 10, 2016, 6:25pm UTC](https://community.wolfram.com/t/nettrain-targetdevice-gpu-error/9032/6 "2016-08-10T18:25:47Z")

</div>

The documentation is doing something slightly confusing. It is reassigning to the value “lenet”.

Try the following. Rename “lenet” to “trainedlenet” after it has been trained. You will want to re-run everything from the top after doing this:

```
lenet = NetChain[{ConvolutionLayer[20, 5], Ramp, PoolingLayer[2, 2], 
   ConvolutionLayer[50, 5], Ramp, PoolingLayer[2, 2], FlattenLayer[], 
   500, Ramp, 10, SoftmaxLayer[]}, 
  "Output" -> NetDecoder[{"Class", Range[0, 9]}], 
  "Input" -> NetEncoder[{"Image", {28, 28}, "Grayscale"}]];

trainedlenet = NetTrain[lenet, trainingData, ValidationSet -> testData, 
  MaxTrainingRounds -> 3, TargetDevice -> "GPU"]

```

This way you can be sure to not get them mixed up.

---

<div class="post-metadata">

**Author:** ![gijsbertwiesenekker](https://avatars.discourse-cdn.com/v4/letter/g/90db22/32.png) [@gijsbertwiesenekker](https://community.wolfram.com/u/gijsbertwiesenekker)\
**Post date:** [August 11, 2016, 8:05am UTC](https://community.wolfram.com/t/nettrain-targetdevice-gpu-error/9032/7 "2016-08-11T08:05:55Z")

</div>

I have tried that and at least the error message is now gone but it still does not seem to work. Without the TargetDevice option you get:

 ![Selection_197.png](https://global.discourse-cdn.com/wolfram/original/3X/3/7/3795d1a6035dd5d4b5063635fcb0c8b51f1f5541.png)

but with the TargetDevice option nothing seems to happen:

![Selection_198.png](https://global.discourse-cdn.com/wolfram/original/3X/0/e/0e8065fefa676220f1a481d4d41039f7ade3f83b.png)

Any ideas?

GW

---

<div class="post-metadata">

**Author:** ![seanc](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/seanc/32/34005_2.png) [@seanc](https://community.wolfram.com/u/seanc)\
**Post date:** [August 11, 2016, 2:37pm UTC](https://community.wolfram.com/t/nettrain-targetdevice-gpu-error/9032/8 "2016-08-11T14:37:15Z")

</div>

In your picture, some of the code is black and some of the code is blue.

The syntax highlighter highlights things in blue if they are undefined. This means that it thinks “lenet”, “trainingdata” and “testData” are all undefined for some reason.

I’ve attached my notebook. It shows a simple evaluation which leads to a failure (because I don’t have a compatible graphics card). But you can see it runs.

---

<div class="post-metadata">

**Author:** ![gijsbertwiesenekker](https://avatars.discourse-cdn.com/v4/letter/g/90db22/32.png) [@gijsbertwiesenekker](https://community.wolfram.com/u/gijsbertwiesenekker)\
**Post date:** [August 11, 2016, 3:02pm UTC](https://community.wolfram.com/t/nettrain-targetdevice-gpu-error/9032/9 "2016-08-11T15:02:17Z")

</div>

Hi,

Before I hit Shift+Enter to evaluate the NetTrain command my notebook looks like:

 ![Selection_225.png](https://global.discourse-cdn.com/wolfram/original/3X/7/e/7e499d697275f87f904484fbc55f8e9ccff9714a.png)

After I hit Shift+Enter to evaluate the NetTrain command my notebook looks like:

 ![Selection_226.png](https://global.discourse-cdn.com/wolfram/original/3X/9/9/99ec7684f831ba0ccda57d17f02d3a3bffe745d7.png)

So the evaluation of the NetTrain command invalidates these objects? Still I do not get the same output as without the TargetDevice-\>“GPU” option.

GW

---

<div class="post-metadata">

**Author:** ![seanc](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/seanc/32/34005_2.png) [@seanc](https://community.wolfram.com/u/seanc)\
**Post date:** [August 11, 2016, 5:02pm UTC](https://community.wolfram.com/t/nettrain-targetdevice-gpu-error/9032/10 "2016-08-11T17:02:39Z")

</div>

There does seem to be problem. It probably only happens with the your graphics card or driver. We haven’t been able yet to reproduce it.

What Operating System are you using? Additionally, do you know what your graphics card is?

We would like to reproduce the problem as closely as possible. If you can, please send an email to [support@wolfram.com](http://support@wolfram.com) about this issue. If you can, include a notebook where you have evaluated the command **SystemInformation[]**. This will tell us more about your computer and its graphics card, helping us to fix this issue.

---

<div class="post-metadata">

**Author:** ![shenghuiy](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/shenghuiy/32/36073_2.png) [@shenghuiy](https://community.wolfram.com/u/shenghuiy)\
**Post date:** [August 11, 2016, 8:57pm UTC](https://community.wolfram.com/t/nettrain-targetdevice-gpu-error/9032/11 "2016-08-11T20:57:39Z")

</div>

I tried Sean’s code on my OS X 10.11.6 El Captain with the following configuration. The odds is in my favor during the compilation of the training process on a local GPU:

* * *

#### Train with GPU

 ![ScreenShot2016-08-11at3.30.06PM.png](https://global.discourse-cdn.com/wolfram/original/3X/5/5/551c12519e45f382dd53c19e0f49a61d1ab3614c.png)

* * *

### Result

 ![ScreenShot2016-08-11at3.38.42PM.png](https://global.discourse-cdn.com/wolfram/original/3X/8/1/81f20ada4924fd06e5bf7f3c470fe03941ca7722.png)

* * *

### Configuration:

 ![ScreenShot2016-08-11at3.38.27PM.png](https://global.discourse-cdn.com/wolfram/original/2X/7/7a2f3bc62e31964d3f4383330733a81d7c7f35ca.png)

I haven’t try on the Win10 Workstation yet.

---

<div class="post-metadata">

**Author:** ![gijsbertwiesenekker](https://avatars.discourse-cdn.com/v4/letter/g/90db22/32.png) [@gijsbertwiesenekker](https://community.wolfram.com/u/gijsbertwiesenekker)\
**Post date:** [August 13, 2016, 11:03am UTC](https://community.wolfram.com/t/nettrain-targetdevice-gpu-error/9032/12 "2016-08-13T11:03:15Z")

</div>

I am running Mathematica on Ubuntu 16.04. Here is the same info for my system:

 ![Selection_227.png](https://global.discourse-cdn.com/wolfram/original/2X/0/03a11d1c30be0c2c4d3c757302e567065fa83ca2.png)

Perhaps it is related to the CUDA Compute Capabilities of my Geforce GTX 460.

Gijsbert

---

<div class="post-metadata">

**Author:** ![sebastianb](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/sebastianb/32/36523_2.png) [@sebastianb](https://community.wolfram.com/u/sebastianb)\
**Post date:** [August 13, 2016, 12:43pm UTC](https://community.wolfram.com/t/nettrain-targetdevice-gpu-error/9032/13 "2016-08-13T12:43:11Z")

</div>

Ah, this is the problem. We are making use of cuDNN, which requires compute capability \>=3.0 ([CUDA Deep Neural Network (cuDNN) | NVIDIA Developer](https://developer.nvidia.com/cudnn)).

It is a bug though that we are not catching this properly and displaying a useful message.

---

<div class="post-metadata">

**Author:** ![david3](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/david3/32/25830_2.png) [@david3](https://community.wolfram.com/u/david3)\
**Post date:** [August 14, 2016, 6:30pm UTC](https://community.wolfram.com/t/nettrain-targetdevice-gpu-error/9032/14 "2016-08-14T18:30:27Z")

</div>

Should this code work in Mathematica 11 on a Dell Alienware with Nvidia GPU 660?

```
data = {1 -> "One", 2 -> "Two", 3 -> "Three", 4 -> "Four"};
Classify[data, {Method -> "NeuralNetwork", 
  PerformanceGoal -> "Quality", TargetDevice -> "GPU"}]

```

---

<div class="post-metadata">

**Author:** ![david3](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/david3/32/25830_2.png) [@david3](https://community.wolfram.com/u/david3)\
**Post date:** [August 14, 2016, 6:35pm UTC](https://community.wolfram.com/t/nettrain-targetdevice-gpu-error/9032/15 "2016-08-14T18:35:26Z")

</div>

Here is my info:

```
In[9]:= CUDAInformation[]

Out[9]= {1 -> {"Name" -> "GeForce GTX 660", "Clock Rate" -> 888500, 
   "Compute Capabilities" -> 3., "GPU Overlap" -> 1, 
   "Maximum Block Dimensions" -> {1024, 1024, 64}, 
   "Maximum Grid Dimensions" -> {2147483647, 65535, 65535}, 
   "Maximum Threads Per Block" -> 1024, 
   "Maximum Shared Memory Per Block" -> 49152, 
   "Total Constant Memory" -> 65536, "Warp Size" -> 32, 
   "Maximum Pitch" -> 2147483647, 
   "Maximum Registers Per Block" -> 65536, "Texture Alignment" -> 512,
    "Multiprocessor Count" -> 6, "Core Count" -> 192, 
   "Execution Timeout" -> 1, "Integrated" -> False, 
   "Can Map Host Memory" -> True, "Compute Mode" -> "Default", 
   "Texture1D Width" -> 65536, "Texture2D Width" -> 65536, 
   "Texture2D Height" -> 65536, "Texture3D Width" -> 4096, 
   "Texture3D Height" -> 4096, "Texture3D Depth" -> 4096, 
   "Texture2D Array Width" -> 16384, 
   "Texture2D Array Height" -> 16384, 
   "Texture2D Array Slices" -> 2048, "Surface Alignment" -> 512, 
   "Concurrent Kernels" -> True, "ECC Enabled" -> False, 
   "TCC Enabled" -> False, "Total Memory" -> 1610612736}}

In[10]:= CUDAResourcesInformation[]

Out[10]= {{"Name" -> "CUDAResources", "Version" -> "10.5.0", 
  "BuildNumber" -> "", "Qualifier" -> "Win64", 
  "WolframVersion" -> "10.5+", "SystemID" -> {"Windows-x86-64"}, 
  "Description" -> "{ToolkitVersion -> 7.0, MinimumDriver -> 300.0}", 
  "Category" -> "", "Creator" -> "", "Publisher" -> "", 
  "Support" -> "", "Internal" -> False, 
  "Location" -> 
   "C:\\Users\\David\\AppData\\Roaming\\Mathematica\\Paclets\\\
Repository\\CUDAResources-Win64-10.5.0", "Context" -> {}, 
  "Enabled" -> True, "Loading" -> Manual, 
  "Hash" -> "79fa747a52a45bf2d78e2c3516c80061"}}

```

---

<div class="post-metadata">

**Author:** ![david3](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/david3/32/25830_2.png) [@david3](https://community.wolfram.com/u/david3)\
**Post date:** [August 14, 2016, 6:37pm UTC](https://community.wolfram.com/t/nettrain-targetdevice-gpu-error/9032/16 "2016-08-14T18:37:02Z")

</div>

Here is the error I am getting:

```
Classify::optx: Unknown option TargetDevice in Classify[{1->One,2->Two,3->Three,4->Four},{Method->NeuralNetwork,PerformanceGoal->Quality,TargetDevice->GPU}].

```

---

<div class="post-metadata">

**Author:** ![sebastianb](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/sebastianb/32/36523_2.png) [@sebastianb](https://community.wolfram.com/u/sebastianb)\
**Post date:** [August 14, 2016, 6:43pm UTC](https://community.wolfram.com/t/nettrain-targetdevice-gpu-error/9032/17 "2016-08-14T18:43:07Z")

</div>

No, Classify has no support for GPU (as you can see from docs).

---

<div class="post-metadata">

**Author:** ![david3](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/david3/32/25830_2.png) [@david3](https://community.wolfram.com/u/david3)\
**Post date:** [August 14, 2016, 6:47pm UTC](https://community.wolfram.com/t/nettrain-targetdevice-gpu-error/9032/18 "2016-08-14T18:47:10Z")

</div>

When I run the example.nb above, everything works fine. I am assuming my GTX 660 is compatible but TargetDevice is just not a parameter of Classify yet.

This should be added because everything I have built uses Classify or Predict and forcing users like myself to specify the parameters of super complicated NeuralNetworks in order to utilize GPUs is not going to be good for mass adoption.

BTW: It only took about 2 minutes to finish the full training in the example.nb which is amazing!

---

<div class="post-metadata">

**Author:** ![gijsbertwiesenekker](https://avatars.discourse-cdn.com/v4/letter/g/90db22/32.png) [@gijsbertwiesenekker](https://community.wolfram.com/u/gijsbertwiesenekker)\
**Post date:** [December 4, 2016, 12:00pm UTC](https://community.wolfram.com/t/nettrain-targetdevice-gpu-error/9032/19 "2016-12-04T12:00:23Z")

</div>

I have upgraded to a GTX 1050 with compute capability 6.1 and my error is gone. The training results are wrong however. Without TargetDevice-\>“GPU” the results are OK, but with TargetDevice-\>“GPU” I am seeing this while training:

 ![Selection_382.png](https://global.discourse-cdn.com/wolfram/original/3X/2/3/23c6de7bc67cda62255136a12843ae6b59f43a7c.png)

and the resulting recognition is also very poor. I am running Mathematica 11.0.1.0 on 64-bit Ubuntu 4.4.0-51-generic, the Nvidia driver version is 875.20 and the CUDA version is 8.0.

How can I troubleshoot this?

GW

---

<div class="post-metadata">

**Author:** ![gijsbertwiesenekker](https://avatars.discourse-cdn.com/v4/letter/g/90db22/32.png) [@gijsbertwiesenekker](https://community.wolfram.com/u/gijsbertwiesenekker)\
**Post date:** [December 5, 2016, 3:11pm UTC](https://community.wolfram.com/t/nettrain-targetdevice-gpu-error/9032/20 "2016-12-05T15:11:29Z")

</div>

This is a known issue, see:

[http://community.wolfram.com/groups/-/m/t/917616](http://community.wolfram.com/groups/-/m/t/917616)

GW

[Next page](https://community.wolfram.com/t/nettrain-targetdevice-gpu-error/9032.md?page=2)
