JoaquinAmatRodrigo / skforecast

Time series forecasting with machine learning models
https://skforecast.org
BSD 3-Clause "New" or "Revised" License
992 stars 113 forks source link

Forecaster with Deep Learning - GPU #726

Open AVPokrovsky opened 1 week ago

AVPokrovsky commented 1 week ago

Hi, I run on google colab. It seems GPU does not work despite it is active in notebook settings. What can be wrong?

FernandoCarazoMelo commented 1 week ago

Hi @AVPokrovsky ,

Thanks for your comment.

The ForecasterRNN fits a Keras/TensorFlow model under the hood. Therefore, there are no reasons why Colab is not using the GPU apart from those specific to Keras/TensorFlow. I recommend you:

  1. Check the GPU availability:

    print("Num GPUs Available: ", len(tf.config.list_physical_devices('GPU')))
  2. Make sure that you run the code with the GPU:

    with tf.device('/GPU:0'):
       # ...

Let me know if this solves your issue and if you need any further assistance!

AVPokrovsky commented 1 week ago

Hi, like this?

with tf.device('/GPU:0'): forecaster.fit(series=data_m)

FernandoCarazoMelo commented 1 week ago

I would recommend checking out the official TF & Colab GPU documentation:

AVPokrovsky commented 1 week ago

Hi, I put in code tf.debugging.set_log_device_placement(True) to show GPU usage. Run the same program on colab and locally on my computer with CPU only. I see in the log that as expected GPU0 is used on colab and CPU0 locally. But it is strange that CPU run the program quicker than GPU (412.60607266426086 seconds vs 449.97930932044983 seconds). In the past I run on colab another program that used tensowflow and keras directly without skforecast. And effect from GPU was very big (ten times ore more). Listings are 2024.docx attached.

AVPokrovsky commented 1 week ago

the test from colab shows for me:

https://colab.research.google.com/notebooks/gpu.ipynb

Time (s) to convolve 32x7x7x3 filter over random 100x100x100x3 images (batch x height x width x channel). Sum of ten runs. CPU (s): 6.06291970800001 GPU (s): 0.12086969300000305 GPU speedup over CPU: 50x

FernandoCarazoMelo commented 1 week ago

Thanks for the benchmark. I'll take a look at it.

FernandoCarazoMelo commented 1 week ago

Could you send the experiment you did with skforecast?

AVPokrovsky commented 1 week ago

LSTM.txt It will takes time to explain how to run my code. But I see the same effect on your code example. I just add time measure in the code (attached). First I run it on colab with GPU - Execution time: 132.4332287311554 seconds. After that I switched off GPU in notebook settings and run again - Execution time: 119.97605085372925 seconds. CPU works faster.