# CNN LSTM machine learning model on GPU?

**URL:** <https://root-forum.cern.ch/t/cnn-lstm-machine-learning-model-on-gpu/53753>\
**Category:** TMVA\
**Created:** [February 23, 2023, 6:57pm UTC](https://root-forum.cern.ch/t/cnn-lstm-machine-learning-model-on-gpu/53753 "2023-02-23T18:57:27Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![meyerma](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/meyerma/32/29724_2.png) [@meyerma](https://root-forum.cern.ch/u/meyerma)\
**Post date:** [February 23, 2023, 6:57pm UTC](https://root-forum.cern.ch/t/cnn-lstm-machine-learning-model-on-gpu/53753/1 "2023-02-23T18:57:27Z")

</div>

Hello,

I have found this talk (slide 14) from 5 years ago and I am particularly willing to use CNN-LSTM machine learning model on GPU. It seems this wasn’t implemented yet at that time. Were there some recent development about LSTM model for TMVA ?

 ![Screenshot 2023-02-24 at 03.56.44](https://root-forum.cern.ch/uploads/default/original/3X/e/f/ef9d2b2752aaaefda86fd149e7ab57775baa138b.png)

> **[TMVA\_QC2018.pdf](https://indico.cern.ch/event/648004/contributions/3068017/attachments/1695765/2729454/TMVA_QC2018.pdf)**

Thanks !

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [February 27, 2023, 9:30am UTC](https://root-forum.cern.ch/t/cnn-lstm-machine-learning-model-on-gpu/53753/2 "2023-02-27T09:30:06Z")

</div>

That’s a question for @moneta I suppose

---

<div class="post-metadata">

**Author:** ![meyerma](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/meyerma/32/29724_2.png) [@meyerma](https://root-forum.cern.ch/u/meyerma)\
**Post date:** [February 28, 2023, 1:39am UTC](https://root-forum.cern.ch/t/cnn-lstm-machine-learning-model-on-gpu/53753/3 "2023-02-28T01:39:45Z")

</div>

If needed I can surely develop some code if this is not too difficult task and if documentation is available

I have also found that it is possible to import model developed with python ml packages (Keras,etc…). How CPU/GPU featured are interfaced ?  
Is it restricted to PyRoot or can this be used also with C++ root ? (I am only using C++)

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [February 28, 2023, 7:50am UTC](https://root-forum.cern.ch/t/cnn-lstm-machine-learning-model-on-gpu/53753/4 "2023-02-28T07:50:06Z")

</div>

As I said, @moneta will most probably guide you

---

<div class="post-metadata">

**Author:** ![moneta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/moneta/32/19423_2.png) [@moneta](https://root-forum.cern.ch/u/moneta)\
**Post date:** [February 28, 2023, 3:38pm UTC](https://root-forum.cern.ch/t/cnn-lstm-machine-learning-model-on-gpu/53753/5 "2023-02-28T15:38:39Z")

</div>

Hi,

The CNN and recurrent including LSTM and GRU are all supported on GPU using the native Deep Learning package. You can see example on how to use them in the tutorial  
[https://root.cern.ch/doc/master/TMVA\_\_CNN\_\_Classification\_8C.html](https://root.cern.ch/doc/master/TMVA __CNN__ Classification_8C.html)

and

[https://root.cern.ch/doc/master/TMVA\_\_RNN\_\_Classification\_8C.html](https://root.cern.ch/doc/master/TMVA __RNN__ Classification_8C.html)

The GPU is automatically enabled if TMVA has been built with GPU support (`-Dtmva-gpu=On -Dcuda=On`).  
The tutorials show also how you can train the model using Keras or PyTorch using the TMVA interface.

Best,

Lorenzo

---

<div class="post-metadata">

**Author:** ![meyerma](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/meyerma/32/29724_2.png) [@meyerma](https://root-forum.cern.ch/u/meyerma)\
**Post date:** [May 28, 2023, 9:13am UTC](https://root-forum.cern.ch/t/cnn-lstm-machine-learning-model-on-gpu/53753/6 "2023-05-28T09:13:44Z")

</div>

Hi @moneta

Sorry for my late reply. Thank you for your help !  
Side question, I have been looking recently into convolutional transformers (transformers seems to be “natural” evolution of the LSTM models) in my research. Is this also implemented in TMVA ? Working on GPU ?

Cheers,  
M.

---

<div class="post-metadata">

**Author:** ![moneta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/moneta/32/19423_2.png) [@moneta](https://root-forum.cern.ch/u/moneta)\
**Post date:** [June 1, 2023, 9:15am UTC](https://root-forum.cern.ch/t/cnn-lstm-machine-learning-model-on-gpu/53753/7 "2023-06-01T09:15:27Z")

</div>

Hi

Unfortunately we have not so far implemented transformers in native TMVA. We might look at implementing only for inference with SOFIE, our fast system for evaluation of deep learning models.

Lorenzo

---

<div class="post-metadata">

**Author:** ![meyerma](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/meyerma/32/29724_2.png) [@meyerma](https://root-forum.cern.ch/u/meyerma)\
**Post date:** [June 2, 2023, 11:42am UTC](https://root-forum.cern.ch/t/cnn-lstm-machine-learning-model-on-gpu/53753/8 "2023-06-02T11:42:07Z")

</div>

Thank you, Lorenzo

---

<div class="post-metadata">

**Author:** ![meyerma](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/meyerma/32/29724_2.png) [@meyerma](https://root-forum.cern.ch/u/meyerma)\
**Post date:** [June 6, 2023, 4:32pm UTC](https://root-forum.cern.ch/t/cnn-lstm-machine-learning-model-on-gpu/53753/9 "2023-06-06T16:32:58Z")

</div>

Hi @moneta

I will definitely work with Transformers and a team of people physicist/IA specialists in the next months.  
Is there any possibility to implement this model natively both on cpu/gpu or SOFIE inference will be the new standard ?

Is there some documentation, rules or suggestions you could provide maybe to estimate the feasibility and see if we can do that ?
