[tmva][sofie] New Keras Parser from SOFIE#20871
Conversation
|
Thanks for the PR! One two things to do before a more detailed review is to merge #15790 and fix the test failures in this PR. But I also have a general question, the same as in #19692 (comment): why not remove the old C++ parser at the same time, so we don't risk code duplication and user confusion? |
0c9d958 to
d592d31
Compare
e7a5b7c to
fc8f6a4
Compare
|
@lmoneta, it seems the new Python files are missing in the relevant diff --git a/bindings/pyroot/pythonizations/python/CMakeLists.txt b/bindings/pyroot/pythonizations/python/CMakeLists.txt
index 4c96c7556c7..e9bbed07628 100644
--- a/bindings/pyroot/pythonizations/python/CMakeLists.txt
+++ b/bindings/pyroot/pythonizations/python/CMakeLists.txt
@@ -58,7 +58,33 @@ if(tmva)
ROOT/_pythonization/_tmva/_rtensor.py
ROOT/_pythonization/_tmva/_tree_inference.py
ROOT/_pythonization/_tmva/_utils.py
- ROOT/_pythonization/_tmva/_gnn.py)
+ ROOT/_pythonization/_tmva/_gnn.py
+ ROOT/_pythonization/_tmva/_sofie/_parser/_keras/__init__.py
+ ROOT/_pythonization/_tmva/_sofie/_parser/_keras/generate_keras_functional.py
+ ROOT/_pythonization/_tmva/_sofie/_parser/_keras/generate_keras_sequential.py
+ ROOT/_pythonization/_tmva/_sofie/_parser/_keras/parser.py
+ ROOT/_pythonization/_tmva/_sofie/_parser/_keras/parser_test_function.py
+ ROOT/_pythonization/_tmva/_sofie/_parser/_keras/layers/__init__.py
+ ROOT/_pythonization/_tmva/_sofie/_parser/_keras/layers/batchnorm.py
+ ROOT/_pythonization/_tmva/_sofie/_parser/_keras/layers/binary.py
+ ROOT/_pythonization/_tmva/_sofie/_parser/_keras/layers/concat.py
+ ROOT/_pythonization/_tmva/_sofie/_parser/_keras/layers/conv.py
+ ROOT/_pythonization/_tmva/_sofie/_parser/_keras/layers/dense.py
+ ROOT/_pythonization/_tmva/_sofie/_parser/_keras/layers/elu.py
+ ROOT/_pythonization/_tmva/_sofie/_parser/_keras/layers/flatten.py
+ ROOT/_pythonization/_tmva/_sofie/_parser/_keras/layers/identity.py
+ ROOT/_pythonization/_tmva/_sofie/_parser/_keras/layers/layernorm.py
+ ROOT/_pythonization/_tmva/_sofie/_parser/_keras/layers/leaky_relu.py
+ ROOT/_pythonization/_tmva/_sofie/_parser/_keras/layers/permute.py
+ ROOT/_pythonization/_tmva/_sofie/_parser/_keras/layers/pooling.py
+ ROOT/_pythonization/_tmva/_sofie/_parser/_keras/layers/reshape.py
+ ROOT/_pythonization/_tmva/_sofie/_parser/_keras/layers/relu.py
+ ROOT/_pythonization/_tmva/_sofie/_parser/_keras/layers/rnn.py
+ ROOT/_pythonization/_tmva/_sofie/_parser/_keras/layers/selu.py
+ ROOT/_pythonization/_tmva/_sofie/_parser/_keras/layers/sigmoid.py
+ ROOT/_pythonization/_tmva/_sofie/_parser/_keras/layers/softmax.py
+ ROOT/_pythonization/_tmva/_sofie/_parser/_keras/layers/swish.py
+ ROOT/_pythonization/_tmva/_sofie/_parser/_keras/layers/tanh.py)
if(dataframe)
list(APPEND PYROOT_EXTRA_PYTHON_SOURCES
ROOT/_pythonization/_tmva/_batchgenerator.py) |
dd9635a to
ed4c2bd
Compare
|
Hi @lmoneta, about these ruff check bindings/pyroot/pythonizations/python/ROOT/_pythonization/_tmva/_sofie/_parser/_keras --fixRuff can just be installed with pip: I think it would be worth it to add a commit that does does these automatic fixes! Then we don't have to update the code again later just for that. |
079dc53 to
ca33772
Compare
ca33772 to
cfb7d53
Compare
|
There is also a Node: 'model_9/average_pooling2d/AvgPool'
Default AvgPoolingOp only supports NHWC on device type CPU
[[{{node model_9/average_pooling2d/AvgPool}}]] [Op:__inference_train_function_2459]I guess it's there because it's the only Intel mac platform we test. Maybe it's not necessarily worth for SOFIE to support it? I think setting |
2a0382e to
9aa6e2a
Compare
guitargeek
left a comment
There was a problem hiding this comment.
Thank you very much for carrying this over the finish line! I'm glad to see that the C++ implementation which called back to Python was translated to a native Python version that also supports Keras 3.
New Keras parser - added support for LayerNorm, BatchNorm ND, ELU layers and added tests for them. Imported Keras within the required functions. Created new CMakeLists.txt file for the keras parser. Made changes in the pythonization CMake file to build the keras parser files removed get_keras_version function call from tmva __init__ file. Replaced import keras_version with get_keras_version and called it in necessary files Removed SOFIE Keras Parser CMakeLists.txt file from the Pythonization directory. Used import numpy statements within the parser functions to avoid slowing down the import of ROOT. Added print statements to display the TensorFlow Keras version used in CI Correctly inject RModelParser_Keras class into Python interfaces
… Keras3 Sequential In Keras3 Sequential output of a layer can have a different name than input of the next layer. Since in sequnrial model each layer has a single input/output use as output names the layer name (which is unique) and set as input name for the next layer [tmva][sofie] Adapt SOFIE tutorial for new Keras parser and remove old C++ parser - use new python keras parser for parsing a model into SOFIE. Since new parser is only Python base, move some tutorials from C++ to Python Remove also tutorial dependency on TMVA_Higgs_Classification by creating and training a model in tutorial TMVA_SOFIE_Keras_HiggsModel.py Adapt also RSofieReader for using new Python Keras parser [tmva][sofie] Disable Conv2D tests of keras parser and add keras dependency to test Fix also an issue in a SOFIE tutorial [tmva][sofie] Fix issue in Keras parser in Redhape operator With this fix now the Keras parser can parse the convolutional model generated by TMVA_CNN_Classification [tmva][sofie] Fix test Keras parser and a bug in Squeeze Fix bug in Squeeze operator when the axes to squeeze are provided. In that case a wrong usage of vector.erase was done. Fix the Keras parser tests when convolutions with channel_first are not supported (e.g. on CPU impelmentations of tensorflows) [tmva][sofie] Fix some remining conflicts left from master rebasing
The bug fixes the closing of the loops on the outer axis. The tests worked because the number of outer axes and normalization axes was the same in the test scripts.
…axpy Avoid using saxpy and use directly the wrapper function in Sofie_common to call blas and automatically also include the bias addition fix doing bias for Conv operator, beta must be equal to 1 now we don't use saxpy
The Python files were moved in root-project@3281aa9 in a different location and it was not done during the rebase. This is now fixed Fix also an issue in parsing input shape from the Keras model and add support also for the different types of input shapes Increase also test tolerance from 10-3 to 10-2 Add also test RModelKerasParser test Fix an issue with RSofieReader forcing a loading of libROOTTMVASofie when compiling the SOFIE code on the flight with RReader [tmva][sofie] Apply review comments from Jonas Move python files used only for testing from the bindings/python code directory to the binding/python test directory
Apply to tutorials and bindings files used by the new keras parser
9aa6e2a to
cc7d91d
Compare
This PR superseeds #19692 fixing the conflicts and add some bug fixes