Skip to content
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

Merged
merged 6 commits into from Mar 8, 2019

Conversation

lmoneta
Copy link
Member

@lmoneta lmoneta commented Aug 31, 2018

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

@phsft-bot
Copy link
Collaborator

Starting build on slc6/gcc48, slc6-i686/gcc49, centos7/clang39, centos7/gcc62, centos7/gcc7, fedora28/native, ubuntu16/native, mac1013/native, windows10/vc15 with flags -Dccache=ON
How to customize builds

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' ");
Copy link
Contributor

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!

Copy link
Member Author

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

@phsft-bot
Copy link
Collaborator

Starting build on slc6/gcc48, slc6-i686/gcc49, centos7/clang39, centos7/gcc62, centos7/gcc7, fedora28/native, ubuntu16/native, mac1013/native, windows10/vc15 with flags -Dccache=ON
How to customize builds

@phsft-bot
Copy link
Collaborator

Starting build on slc6/gcc48, slc6-i686/gcc49, centos7/clang39, centos7/gcc62, centos7/gcc7, fedora28/native, ubuntu16/native, mac1013/native, windows10/vc15 with flags -Dccache=ON
How to customize builds

@phsft-bot
Copy link
Collaborator

Build failed on ubuntu16/native.
See console output.

@phsft-bot
Copy link
Collaborator

Build failed on centos7/clang39.
See console output.

Warnings:

  • /cvmfs/sft.cern.ch/lcg/views/LCG_rootext20180517/x86_64-centos7-clang39-opt/lib/cmake/VecCore/../../../include/Vc/scalar/../common/../sse/intrinsics.h:616:16: warning: variable 'f' may be uninitialized when used here [-Wconditional-uninitialized]
  • /cvmfs/sft.cern.ch/lcg/views/LCG_rootext20180517/x86_64-centos7-clang39-opt/lib/cmake/VecCore/../../../include/Vc/scalar/../common/memorybase.h:463:83: warning: unused parameter 'flags' [-Wunused-parameter]
  • /cvmfs/sft.cern.ch/lcg/views/LCG_rootext20180517/x86_64-centos7-clang39-opt/lib/cmake/VecCore/../../../include/Vc/scalar/../common/memorybase.h:478:89: warning: unused parameter 'flags' [-Wunused-parameter]
  • /cvmfs/sft.cern.ch/lcg/views/LCG_rootext20180517/x86_64-centos7-clang39-opt/lib/cmake/VecCore/../../../include/Vc/common/simdize.h:913:1: warning: 'tuple_size' defined as a class template here but previously declared as a struct template [-Wmismatched-tags]
  • /cvmfs/sft.cern.ch/lcg/views/LCG_rootext20180517/x86_64-centos7-clang39-opt/lib/cmake/VecCore/../../../include/Vc/common/simdize.h:920:1: warning: 'tuple_element' defined as a class template here but previously declared as a struct template [-Wmismatched-tags]

@phsft-bot
Copy link
Collaborator

Build failed on centos7/gcc62.
See console output.

@phsft-bot
Copy link
Collaborator

Build failed on centos7/gcc7.
See console output.

Warnings:

  • ../root/core/newdelete/src/NewDelete.cxx:217:11: warning: ‘operator new’ must not return NULL unless it is declared ‘throw()’ (or -fcheck-new is in effect)
  • ../root/core/newdelete/src/NewDelete.cxx:344:11: warning: ‘operator new’ must not return NULL unless it is declared ‘throw()’ (or -fcheck-new is in effect)
  • ../root/core/newdelete/src/NewDelete.cxx:263:6: warning: the program should also define ‘void operator delete(void*, std::size_t)’ [-Wsized-deallocation]
  • ../root/core/newdelete/src/NewDelete.cxx:367:6: warning: the program should also define ‘void operator delete [](void*, std::size_t)’ [-Wsized-deallocation]
  • /cvmfs/sft.cern.ch/lcg/views/LCG_rootext20180517/x86_64-centos7-gcc7-opt/include/python2.7/unicodeobject.h:534:24: warning: ISO C++1z does not allow ‘register’ storage class specifier [-Wregister]
  • /cvmfs/sft.cern.ch/lcg/views/LCG_rootext20180517/x86_64-centos7-gcc7-opt/include/python2.7/unicodeobject.h:553:24: warning: ISO C++1z does not allow ‘register’ storage class specifier [-Wregister]
  • /cvmfs/sft.cern.ch/lcg/views/LCG_rootext20180517/x86_64-centos7-gcc7-opt/include/python2.7/unicodeobject.h:575:29: warning: ISO C++1z does not allow ‘register’ storage class specifier [-Wregister]
  • /cvmfs/sft.cern.ch/lcg/views/LCG_rootext20180517/x86_64-centos7-gcc7-opt/include/python2.7/unicodeobject.h:593:23: warning: ISO C++1z does not allow ‘register’ storage class specifier [-Wregister]
  • /cvmfs/sft.cern.ch/lcg/views/LCG_rootext20180517/x86_64-centos7-gcc7-opt/include/python2.7/stringobject.h:173:24: warning: ISO C++1z does not allow ‘register’ storage class specifier [-Wregister]
  • /cvmfs/sft.cern.ch/lcg/views/LCG_rootext20180517/x86_64-centos7-gcc7-opt/include/python2.7/stringobject.h:174:21: warning: ISO C++1z does not allow ‘register’ storage class specifier [-Wregister]

And 314 more

@phsft-bot
Copy link
Collaborator

Build failed on slc6/gcc48.
See console output.

@phsft-bot
Copy link
Collaborator

Build failed on slc6-i686/gcc49.
See console output.

@phsft-bot
Copy link
Collaborator

Build failed on fedora28/native.
See console output.

Errors:

  • /mnt/build/workspace/root-pullrequests-build/root/tmva/pymva/src/MethodPyKeras.cxx:148:34: error: ‘PyString_AsString’ was not declared in this scope

Warnings:

  • /mnt/build/workspace/root-pullrequests-build/root/interpreter/llvm/src/include/llvm/ADT/SmallVector.h:309:11: warning: ‘void* memcpy(void*, const void*, size_t)’ writing to an object of type ‘struct std::pair<void*, long unsigned int>’ with no trivial copy-assignment; use copy-assignment or copy-initialization instead [-Wclass-memaccess]
  • /mnt/build/workspace/root-pullrequests-build/root/interpreter/llvm/src/include/llvm/ADT/SmallVector.h:296:13: warning: ‘void* memcpy(void*, const void*, size_t)’ writing to an object of type ‘struct std::pair<clang::CXXRecordDecl*, clang::SourceLocation>’ with no trivial copy-assignment; use copy-assignment or copy-initialization instead [-Wclass-memaccess]
  • /mnt/build/workspace/root-pullrequests-build/root/interpreter/llvm/src/include/llvm/ADT/SmallVector.h:296:13: warning: ‘void* memcpy(void*, const void*, size_t)’ writing to an object of type ‘struct std::pair<const clang::CXXMethodDecl*, const clang::CXXMethodDecl*>’ with no trivial copy-assignment; use copy-assignment or copy-initialization instead [-Wclass-memaccess]
  • /mnt/build/workspace/root-pullrequests-build/root/interpreter/llvm/src/include/llvm/ADT/SmallVector.h:296:13: warning: ‘void* memcpy(void*, const void*, size_t)’ writing to an object of type ‘struct std::pair<clang::CXXMethodDecl*, const clang::FunctionProtoType*>’ with no trivial copy-assignment; use copy-assignment or copy-initialization instead [-Wclass-memaccess]
  • /mnt/build/workspace/root-pullrequests-build/root/interpreter/llvm/src/include/llvm/ADT/SmallVector.h:309:11: warning: ‘void* memcpy(void*, const void*, size_t)’ writing to an object of type ‘struct std::pair<void*, long unsigned int>’ with no trivial copy-assignment; use copy-assignment or copy-initialization instead [-Wclass-memaccess]
  • /mnt/build/workspace/root-pullrequests-build/root/interpreter/llvm/src/include/llvm/ADT/SmallVector.h:309:11: warning: ‘void* memcpy(void*, const void*, size_t)’ writing to an object of type ‘struct std::pair<void*, long unsigned int>’ with no trivial copy-assignment; use copy-assignment or copy-initialization instead [-Wclass-memaccess]
  • /mnt/build/workspace/root-pullrequests-build/root/interpreter/llvm/src/include/llvm/ADT/SmallVector.h:309:11: warning: ‘void* memcpy(void*, const void*, size_t)’ writing to an object of type ‘struct std::pair<void*, long unsigned int>’ with no trivial copy-assignment; use copy-assignment or copy-initialization instead [-Wclass-memaccess]
  • /mnt/build/workspace/root-pullrequests-build/root/interpreter/llvm/src/include/llvm/ADT/SmallVector.h:309:11: warning: ‘void* memcpy(void*, const void*, size_t)’ writing to an object of type ‘struct std::pair<void*, long unsigned int>’ with no trivial copy-assignment; use copy-assignment or copy-initialization instead [-Wclass-memaccess]
  • /mnt/build/workspace/root-pullrequests-build/root/interpreter/llvm/src/include/llvm/ADT/SmallVector.h:296:13: warning: ‘void* memcpy(void*, const void*, size_t)’ writing to an object of type ‘struct std::pair<clang::CXXRecordDecl*, clang::SourceLocation>’ with no trivial copy-assignment; use copy-assignment or copy-initialization instead [-Wclass-memaccess]
  • /mnt/build/workspace/root-pullrequests-build/root/interpreter/llvm/src/include/llvm/ADT/SmallVector.h:296:13: warning: ‘void* memcpy(void*, const void*, size_t)’ writing to an object of type ‘struct std::pair<const clang::CXXMethodDecl*, const clang::CXXMethodDecl*>’ with no trivial copy-assignment; use copy-assignment or copy-initialization instead [-Wclass-memaccess]

And 68 more

@phsft-bot
Copy link
Collaborator

Starting build on slc6/gcc48, slc6-i686/gcc49, centos7/clang39, centos7/gcc62, centos7/gcc7, fedora28/native, ubuntu16/native, mac1013/native, windows10/vc15 with flags -Dccache=ON
How to customize builds

@phsft-bot
Copy link
Collaborator

Build failed on fedora28/native.
See console output.

Errors:

  • /mnt/build/workspace/root-pullrequests-build/root/tmva/pymva/src/MethodPyKeras.cxx:93:34: error: ‘PyString_AsString’ was not declared in this scope

Warnings:

  • /mnt/build/workspace/root-pullrequests-build/root/interpreter/llvm/src/include/llvm/ADT/SmallVector.h:309:11: warning: ‘void* memcpy(void*, const void*, size_t)’ writing to an object of type ‘struct std::pair<void*, long unsigned int>’ with no trivial copy-assignment; use copy-assignment or copy-initialization instead [-Wclass-memaccess]
  • /mnt/build/workspace/root-pullrequests-build/root/interpreter/llvm/src/include/llvm/ADT/SmallVector.h:296:13: warning: ‘void* memcpy(void*, const void*, size_t)’ writing to an object of type ‘struct std::pair<clang::CXXRecordDecl*, clang::SourceLocation>’ with no trivial copy-assignment; use copy-assignment or copy-initialization instead [-Wclass-memaccess]
  • /mnt/build/workspace/root-pullrequests-build/root/interpreter/llvm/src/include/llvm/ADT/SmallVector.h:296:13: warning: ‘void* memcpy(void*, const void*, size_t)’ writing to an object of type ‘struct std::pair<const clang::CXXMethodDecl*, const clang::CXXMethodDecl*>’ with no trivial copy-assignment; use copy-assignment or copy-initialization instead [-Wclass-memaccess]
  • /mnt/build/workspace/root-pullrequests-build/root/interpreter/llvm/src/include/llvm/ADT/SmallVector.h:296:13: warning: ‘void* memcpy(void*, const void*, size_t)’ writing to an object of type ‘struct std::pair<clang::CXXMethodDecl*, const clang::FunctionProtoType*>’ with no trivial copy-assignment; use copy-assignment or copy-initialization instead [-Wclass-memaccess]
  • /mnt/build/workspace/root-pullrequests-build/root/interpreter/llvm/src/include/llvm/ADT/SmallVector.h:309:11: warning: ‘void* memcpy(void*, const void*, size_t)’ writing to an object of type ‘struct std::pair<void*, long unsigned int>’ with no trivial copy-assignment; use copy-assignment or copy-initialization instead [-Wclass-memaccess]
  • /mnt/build/workspace/root-pullrequests-build/root/interpreter/llvm/src/include/llvm/ADT/SmallVector.h:309:11: warning: ‘void* memcpy(void*, const void*, size_t)’ writing to an object of type ‘struct std::pair<void*, long unsigned int>’ with no trivial copy-assignment; use copy-assignment or copy-initialization instead [-Wclass-memaccess]
  • /mnt/build/workspace/root-pullrequests-build/root/interpreter/llvm/src/include/llvm/ADT/SmallVector.h:309:11: warning: ‘void* memcpy(void*, const void*, size_t)’ writing to an object of type ‘struct std::pair<void*, long unsigned int>’ with no trivial copy-assignment; use copy-assignment or copy-initialization instead [-Wclass-memaccess]
  • /mnt/build/workspace/root-pullrequests-build/root/interpreter/llvm/src/include/llvm/ADT/SmallVector.h:309:11: warning: ‘void* memcpy(void*, const void*, size_t)’ writing to an object of type ‘struct std::pair<void*, long unsigned int>’ with no trivial copy-assignment; use copy-assignment or copy-initialization instead [-Wclass-memaccess]
  • /mnt/build/workspace/root-pullrequests-build/root/interpreter/llvm/src/include/llvm/ADT/SmallVector.h:296:13: warning: ‘void* memcpy(void*, const void*, size_t)’ writing to an object of type ‘struct std::pair<clang::CXXRecordDecl*, clang::SourceLocation>’ with no trivial copy-assignment; use copy-assignment or copy-initialization instead [-Wclass-memaccess]
  • /mnt/build/workspace/root-pullrequests-build/root/interpreter/llvm/src/include/llvm/ADT/SmallVector.h:296:13: warning: ‘void* memcpy(void*, const void*, size_t)’ writing to an object of type ‘struct std::pair<const clang::CXXMethodDecl*, const clang::CXXMethodDecl*>’ with no trivial copy-assignment; use copy-assignment or copy-initialization instead [-Wclass-memaccess]

And 68 more

@phsft-bot
Copy link
Collaborator

Build failed on windows10/vc15.
See console output.

Errors:

  • error: failed to execute prompt script (exit code 1)

@phsft-bot
Copy link
Collaborator

Starting build on ROOT-performance-centos7-multicore/default, ROOT-fedora27/noimt, ROOT-fedora29/python3, ROOT-ubuntu16/rtcxxmod, mac1014/cxx17, windows10/default
How to customize builds

@lmoneta lmoneta changed the title Add possibility to specify number of threads in PyKeras Add possibility to specify number of threads in PyKeras and set specific Tensorflow session config options Feb 5, 2019
@lmoneta
Copy link
Member Author

lmoneta commented Feb 5, 2019

Added also possibility to set gpu_options.
Added options session.gpu_options.allow_growth= True neded for running cuDNN on new RTX cards
See https://www.tensorflow.org/guide/using_gpu#allowing_gpu_memory_growth
and solution described here for RTX cards:
tensorflow/tensorflow#24496

Copy link
Contributor

@ashlaban ashlaban left a 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.

// - 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\"");
Copy link
Contributor

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;
Copy link
Contributor

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?

else
PyRunString("session_conf = tf.ConfigProto()");

PyRunString("session_conf.gpu_options.allow_growth = True"); // for GPU's (needed for new RTX cards)
Copy link
Contributor

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.

// 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);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be here?

Lorenzo Moneta and others added 6 commits March 7, 2019 18:20
…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"
@phsft-bot
Copy link
Collaborator

Starting build on ROOT-performance-centos7-multicore/default, ROOT-fedora27/noimt, ROOT-fedora29/python3, ROOT-ubuntu16/rtcxxmod, mac1014/cxx17, windows10/default
How to customize builds

@lmoneta lmoneta merged commit 6897056 into root-project:master Mar 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants