New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add possibility to specify number of threads in PyKeras and set specific Tensorflow session config options #2566
Conversation
Starting build on |
tmva/pymva/src/MethodPyKeras.cxx
Outdated
if (num_threads > 0) { | ||
PyRunString("import tensorflow as tf"); | ||
PyRunString("from keras.backend import tensorflow_backend as K"); | ||
PyRunString("print 'setting tensorflow to run as single thread' "); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This breaks for Theano or CNTK as backend!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, I will add an if statement that this will work only in case of Tensorflow
Starting build on |
07537e3
to
1b59336
Compare
Starting build on |
Build failed on ubuntu16/native. |
Build failed on centos7/clang39. Warnings:
|
Build failed on centos7/gcc62. |
Build failed on centos7/gcc7. Warnings:
And 314 more |
Build failed on slc6/gcc48. |
Build failed on slc6-i686/gcc49. |
Build failed on fedora28/native. Errors:
Warnings:
And 68 more |
Starting build on |
Build failed on fedora28/native. Errors:
Warnings:
And 68 more |
Build failed on windows10/vc15. Errors:
|
9c8f3c0
to
96504dc
Compare
Starting build on |
Added also possibility to set gpu_options. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! Just a few minor discussion points on style.
tmva/pymva/src/MethodPyKeras.cxx
Outdated
// - set up number of threads for CPU if NumThreads option was specified | ||
|
||
// check first if using tensorflow backend | ||
PyRunString("keras_backend_is_tf = keras.backend.backend() == \"tensorflow\""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be refactored into a separate function TMVA::PyKeras::kBackends GetKerasBackend();
to raise the level of abstraction a little bit.
(Possibly just as a named lambda function.)
PyRunString("import tensorflow as tf"); | ||
PyRunString("from keras.backend import tensorflow_backend as K"); | ||
// in case specify number of threads | ||
int num_threads = fNumThreads; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this and just use fNumThreads
directly?
tmva/pymva/src/MethodPyKeras.cxx
Outdated
else | ||
PyRunString("session_conf = tf.ConfigProto()"); | ||
|
||
PyRunString("session_conf.gpu_options.allow_growth = True"); // for GPU's (needed for new RTX cards) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will just mention this for reference:
As you mentioned during our discussion today this could be extracted to an option.
tmva/pymva/src/MethodPyKeras.cxx
Outdated
// Setup model, either the initial model from `fFilenameModel` or | ||
// the trained model from `fFilenameTrainedModel` | ||
if (fContinueTraining) Log() << kINFO << "Continue training with trained model" << Endl; | ||
SetupKerasModel(fContinueTraining); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be here?
…e to the right place
…l config option for GPU that is needed for new RTX cards
Define a new options GpuOPtions to allow to confire the Gpu when using Tensorflow. FOr example, to minimize GPu emory usage, needed for running Keras and then TMVA on GPU, you can specify: "GpuOptions=allow_growth=True"
96504dc
to
218f8c3
Compare
Starting build on |
Add a new option in PyKeras to select the number of running threads when running keras with tensorflow.
If nothing is specified, tensor flow normally runs by default on all available cores