jeremiedb / mxnet_winbin

MXNET R Package binaries for Windows
Apache License 2.0
2 stars 3 forks source link

Version 3.5 Oddness #2

Open some-guy1 opened 6 years ago

some-guy1 commented 6 years ago

mx.nd.internal.dispatch.Ops is acting differently for R version 3.5.

Mxnet R code that worked great with R 3.4.4 no longer works with 3.5 with random mx.nd.internal.dispatch.Ops errors.

Even the simple https://mxnet.incubator.apache.org/tutorials/r/fiveMinutesNeuralNetwork.html

results in the following error:

error in mx.nd.internal.dispatch.Ops(.Generic, e1, e2) : [12:07:35] c:\jenkins\workspace\mxnet\mxnet\src\operator\tensor../elemwise_op_common.h:123: Check failed: assign(&dattr, (*vec)[i]) Incompatible attr in node at 1-th input: expected [20], got [20,1]

Something appears to be slightly different mx.nd.internal.dispatch.Ops

Difficult to debug in my complex CNN architecture.

R session info:

sessionInfo() R version 3.5.0 (2018-04-23) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] mlbench_2.1-1 mxnet_1.2.0

some-guy1 commented 6 years ago

Ok FYI, I rolled back my version of R to 3.4.4, then I downloaded and reinstalled the Mxnet that was compiled with R 3.4.4 for windows. Everything works as expected with 3.4.4 including the super simple tutorial.

So, something definitely changed with R 3.5, but unfortunately I dont think I am knowledgeable enough to know what it is. :-/

jeremiedb commented 6 years ago

More details would be needed. I run R 3.5.0 using the compiled Winodws libraries (mxnet 1.2.0) and the FiveMinutes tutorial runs without issue. The demo.metric.mae however won't work as the metrics are calculated on ndarrays rather than R arrays.

some-guy1 commented 6 years ago

Hmm ok. When I get some free time I will try and hunt down why 3.5 is not working. Lots of changes with 3.5, so I guess I shouldnt be surprised.

Thanks for the quick response! I will report back soon.

some-guy1 commented 6 years ago

Ok you gave me a very big hint with the metrics and the change from R arrays to ndarrays.

Yes, the FiveMinutes tutorial works except for the custom metric.

My personal code was NOT using a custom metric, BUT it is using a custom loss function. The new metrics (not custom) are not playing nicely with the custom loss. I kept getting errors about array sizes. I was able to get my code to work with R 3.5 by using my custom loss I had before, but I had to create a dummy metric shown below.

This doesnt seem like it was intended? Should I move this issue to the official mxnet issue area or am I still messing something up?

mx.metric.rmse.mine <- mx.metric.custom("rmse.mine", function(label, pred)
{  
  res = pred
  return(as.array(res))
})
some-guy1 commented 6 years ago

Oh also, using this modification appears to require about 6GB more RAM. :-(

jeremiedb commented 6 years ago

Custom metric need to return a single value.

In your case, you might want to do:

mx.metric.rmse.mine <- mx.metric.custom("rmse.mine", function(label, pred)
{  
  res = pred
  return(mean(as.array(res)))
})

or

mx.metric.rmse.mine <- mx.metric.custom("rmse.mine", function(label, pred)
{  
  res = mx.nd.mean(pred)
  return(as.array(res))
})
some-guy1 commented 6 years ago

I am just saying the new default R 3.5 metric seemed to not run when using a MXNet custom loss. I was able to fix the issue by also creating a custom metric.

In otherwords, I had a custom loss, but used default metrics. MXNet would not run. I then used a custom metric and the code successfully ran. Maybe this doesnt happen for you? This observation did not happen with older versions of R.